Defined Type: sensu::check

Defined in:
manifests/check.pp

Summary

Creates Sensu checks

Overview

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.

Parameters:

  • command (Optional[String]) (defaults to: undef)

    The check command to run

  • ensure (Enum['present','absent']) (defaults to: 'present')

    Whether the check should be present or not. Valid values: present, absent

  • type (Optional[String]) (defaults to: undef)

    Type of check. Set this to 'absent' to remove it completely.

  • handlers (Variant[Undef,String,Array]) (defaults to: undef)

    Array of Strings. Handlers to use for this check. Set this to 'absent' to remove it completely.

  • contacts (Variant[Undef,String,Array]) (defaults to: undef)

    Array of Strings. Contacts to use for the contact-routing Sensu Enterprise feature. This value corresponds with a sensu::contact resource having the same name.

  • standalone (Variant[Boolean,Enum['absent']]) (defaults to: true)

    When true, scheduled by the client. When false, listen for published check request. Set this to 'absent' to remove it completely.

  • cron (String) (defaults to: 'absent')

    When the check should be executed, using the Cron syntax. Supersedes the interval parameter. Example: "0 0 * * *".

  • interval (Variant[Integer,Enum['absent']]) (defaults to: 60)

    How frequently (in seconds) the check will be executed. Set this to 'absent' to remove it completely.

  • occurrences (Variant[Undef,Pattern[/^(\d+)$/],Integer,Enum['absent']]) (defaults to: undef)

    The number of event occurrences before the handler should take action. Set this to 'absent' to remove it completely.

  • refresh (Variant[Undef,Enum['absent'],Integer]) (defaults to: undef)

    The number of seconds sensu-plugin-aware handlers should wait before taking second action. Set this to 'absent' to remove it completely.

  • source (Variant[Undef,String,Integer]) (defaults to: undef)

    The check source, used to create a JIT Sensu client for an external resource (e.g. a network switch). Set this to 'absent' to remove it completely.

  • subscribers (Variant[Undef,String,Array]) (defaults to: undef)

    Array of Strings. Which subscriptions must execute this check. Set this to 'absent' to remove it completely.

  • low_flap_threshold (Variant[Undef,Enum['absent'],Integer]) (defaults to: undef)

    Flap detection - see Nagios Flap Detection. Set this to 'absent' to remove it completely.

  • high_flap_threshold (Variant[Undef,Enum['absent'],Integer]) (defaults to: undef)

    Flap detection - see Nagios Flap Detection. Set this to 'absent' to remove it completely.

  • timeout (Variant[Undef,Enum['absent'],Numeric]) (defaults to: undef)

    Check timeout in seconds, after it fails. Set this to 'absent' to remove it completely.

  • aggregate (Optional[String]) (defaults to: undef)

    Aggregates, preventing event floods. Set 'aggregate:' and 'handle:false', this prevents the server from sending to a handler, and makes the aggregated results available under /aggregates in the REST API. Set this to 'absent' to remove it completely.

  • aggregates (Variant[Undef,String,Array]) (defaults to: undef)

    Array of Strings. An array of aggregates to add to the check. This supercedes the above aggregate parameter. Set this to 'absent' to remove it completely.

  • handle (Variant[Undef,Enum['absent'],Boolean]) (defaults to: undef)

    When false, check will not be sent to handlers. Set this to 'absent' to remove it completely.

  • publish (Variant[Undef,Enum['absent'],Boolean]) (defaults to: undef)

    Unpublished checks. Prevents the check from being triggered on clients. This allows for the definition of commands that are not actually 'checks' per say, but actually arbitrary commands for remediation. Set this to 'absent' to remove it completely. Default: undef

  • dependencies (Variant[Undef,String,Array]) (defaults to: undef)

    List of checks this check depends on. Note: The validity of the other checks is not enforced by puppet Set this to 'absent' to remove it completely.

  • content (Hash) (defaults to: {})

    Mapping of arbitrary attributes from the top-level of the target configuration JSON map. This parameter is intended to configure plugins and extensions which look up values outside of the check configuration scope. Example: { "mailer" => { "mail_from" => "sensu@example.com", "mail_to" => "monitor@example.com" } }

  • custom (Optional[Hash]) (defaults to: undef)

    List of custom attributes to include in the check. You can use it to pass any attribute that is not listed here explicitly. Example: { 'remediation' => { 'low_remediation' => { 'occurrences' => [1,2], 'severities' => [1], 'command' => "/bin/command", 'publish' => false, } } }

  • ttl (Variant[Undef,Enum['absent'],Integer]) (defaults to: undef)

    The time to live (TTL) in seconds until check results are considered stale. Set this to 'absent' to remove it completely.

  • ttl_status (Variant[Undef,Enum['absent'],Integer,Pattern[/^(\d+)+$/]]) (defaults to: undef)

    The exit code that a check with the ttl attribute should return. Set this to 'absent' to remove it completely.

  • auto_resolve (Variant[Undef,Enum['absent'],Boolean]) (defaults to: undef)

    When a check in a WARNING or CRITICAL state returns to an OK state, the event generated by the WARNING or CRITICAL state will be automatically resolved. Set this to 'absent' to remove it completely.

  • subdue (Variant[Undef,Enum['absent'],Hash]) (defaults to: undef)

    Check subdue configuration. Set this to 'absent' to remove it completely.

  • proxy_requests (Variant[Undef,Enum['absent'],Hash]) (defaults to: undef)

    Manages Proxy Check Requests Since Sensu 0.28.0. Publishes a check request to every Sensu client which matches the defined client attributes. See the documentation for the format of the Hash value.

  • hooks (Variant[Undef,Enum['absent'],Hash]) (defaults to: undef)

    Manages



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,
  }
}