Defined Type: sensu::check
- Defined in:
- manifests/check.pp
Summary
Creates Sensu checksOverview
This define manages Sensu checks
Hooks Since Sensu 1.1.0. Manages hooks for a check. See the documentation for the format of the Hash value.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'manifests/check.pp', line 104
define sensu::check (
Optional[String] $command = undef,
Enum['present','absent'] $ensure = 'present',
Optional[String] $type = undef,
Variant[Undef,String,Array] $handlers = undef,
Variant[Undef,String,Array] $contacts = undef,
Variant[Boolean,Enum['absent']] $standalone = true,
String $cron = 'absent',
Variant[Integer,Enum['absent']] $interval = 60,
Variant[Undef,Pattern[/^(\d+)$/],Integer,Enum['absent']] $occurrences = undef,
Variant[Undef,Enum['absent'],Integer] $refresh = undef,
Variant[Undef,String,Integer] $source = undef,
Variant[Undef,String,Array] $subscribers = undef,
Variant[Undef,Enum['absent'],Integer] $low_flap_threshold = undef,
Variant[Undef,Enum['absent'],Integer] $high_flap_threshold = undef,
Variant[Undef,Enum['absent'],Numeric] $timeout = undef,
Optional[String] $aggregate = undef,
Variant[Undef,String,Array] $aggregates = undef,
Variant[Undef,Enum['absent'],Boolean] $handle = undef,
Variant[Undef,Enum['absent'],Boolean] $publish = undef,
Variant[Undef,String,Array] $dependencies = undef,
Optional[Hash] $custom = undef,
Hash $content = {},
Variant[Undef,Enum['absent'],Integer] $ttl = undef,
Variant[Undef,Enum['absent'],Integer,Pattern[/^(\d+)+$/]] $ttl_status = undef,
Variant[Undef,Enum['absent'],Boolean] $auto_resolve = undef,
Variant[Undef,Enum['absent'],Hash] $subdue = undef,
Variant[Undef,Enum['absent'],Hash] $proxy_requests = undef,
Variant[Undef,Enum['absent'],Hash] $hooks = undef,
) {
include ::sensu
if $ensure == 'present' and !$command {
fail("sensu::check{${name}}: a command must be given when ensure is present")
}
if $subdue =~ Hash {
if !( has_key($subdue, 'days') and $subdue['days'] =~ Hash ){
fail("sensu::check{${name}}: subdue hash should have a proper format. (got: ${subdue}) See https://sensuapp.org/docs/latest/reference/checks.html#subdue-attributes")
}
}
if $proxy_requests {
if $proxy_requests =~ Hash {
if !( has_key($proxy_requests, 'client_attributes') ) {
fail("sensu::check{${name}}: proxy_requests hash should have a proper format. (got: ${proxy_requests}) See https://sensuapp.org/docs/latest/reference/checks.html#proxy-requests-attributes")
}
} elsif !($proxy_requests == 'absent') {
fail("sensu::check{${name}}: proxy_requests must be a hash or 'absent' (got: ${proxy_requests})")
}
}
$check_name = regsubst(regsubst($name, ' ', '_', 'G'), '[\(\)]', '', 'G')
# If cron is specified, interval should not be written to the configuration
if $cron and $cron != 'absent' {
$interval_real = 'absent'
} else {
$interval_real = $interval
}
case $handlers {
Pattern[/absent/]: { $handlers_array = undef }
String: { $handlers_array = [ $handlers ] }
default: { $handlers_array = $handlers }
}
case $subscribers {
Pattern[/absent/]: { $subscribers_array = undef }
String: { $subscribers_array = [ $subscribers ] }
default: { $subscribers_array = $subscribers }
}
case $aggregates {
Pattern[/absent/]: { $aggregates_array = undef }
String: { $aggregates_array = [ $aggregates ] }
default: { $aggregates_array = $aggregates }
}
case $contacts {
Pattern[/absent/]: { $contacts_array = undef }
String: { $contacts_array = [ $contacts ] }
default: { $contacts_array = $contacts }
}
case $dependencies {
Pattern[/absent/]: { $dependencies_array = undef }
String: { $dependencies_array = [ $dependencies ] }
default: { $dependencies_array = $dependencies }
}
# (#463) All plugins must come before all checks. Collections are not used to
# avoid realizing any resources.
Anchor['plugins_before_checks']
~> Sensu::Check[$name]
if is_hash($hooks) {
$hooks.each |$k,$v| {
$valid_k = $k ? {
Integer[1,255] => true,
Enum['ok', 'warning', 'critical', 'unknown', 'non-zero'] => true,
default => fail("Illegal value for ${k} hook. Valid values are: Integers from 1 to 255 and any of 'ok', 'warning', 'critical', 'unknown', 'non-zero'"),
}
}
}
# This Hash map will ultimately exist at `{"checks" => {"$check_name" =>
# $check_config}}`
$check_config_start = {
type => $type,
standalone => $standalone,
command => $command,
handlers => $handlers_array,
contacts => $contacts_array,
cron => $cron,
interval => $interval_real,
occurrences => $occurrences,
refresh => $refresh,
source => $source,
subscribers => $subscribers_array,
low_flap_threshold => $low_flap_threshold,
high_flap_threshold => $high_flap_threshold,
timeout => $timeout,
aggregate => $aggregate,
aggregates => $aggregates_array,
handle => $handle,
publish => $publish,
dependencies => $dependencies_array,
subdue => $subdue,
proxy_requests => $proxy_requests,
hooks => $hooks,
ttl => $ttl,
ttl_status => $ttl_status,
auto_resolve => $auto_resolve,
}
# Remove key/value pares where the value is `undef` or `"absent"`.
$check_config_pruned = $check_config_start.reduce({}) |$memo, $kv| {
$kv[1] ? {
undef => $memo,
'absent' => $memo,
default => $memo + Hash.new($kv),
}
}
# Merge the specified properties on top of the custom hash.
if $custom == undef {
$check_config = $check_config_pruned
} else {
$check_config = $custom + $check_config_pruned
}
# Merge together the "checks" scope with any arbitrary config specified via
# `content`.
$checks_scope_start = { $check_name => $check_config }
if $content['checks'] == undef {
$checks_scope = { 'checks' => $checks_scope_start }
} else {
$checks_scope = { 'checks' => $content['checks'] + $checks_scope_start }
}
# The final structure from the top level. Check configuration scope is merged
# on top of any arbitrary plugin and extension configuration in $content.
$content_real = $content + $checks_scope
sensu::write_json { "${::sensu::conf_dir}/checks/${check_name}.json":
ensure => $ensure,
content => $content_real,
owner => $::sensu::user,
group => $::sensu::group,
mode => $::sensu::config_file_mode,
notify_list => $::sensu::check_notify,
}
}
|