Defined Type: icinga2::object::service

Defined in:
manifests/object/service.pp

Summary

Manage Icinga 2 service objects.

Overview

Examples:

A service ‘ping` is applied to all hosts with a valid ipv4 address.

::icinga2::object::service { 'ping4':
  import        => ['generic-service'],
  apply         => true,
  check_command => 'ping',
  assign        => ['host.address'],
  target        => '/etc/icinga2/zones.d/global-templates/services.conf',
}

A ‘apply Service for (disk_name =>config in host.vars.disks)` rule is applied to all Linux hosts with an Icinga Agent. Note in this example it’s required that the endpoint (see ‘command_endpoint`) and the host object has the same name!

::icinga2::object::service { 'linux_disks':
  import           => ['generic-service'],
  apply            =>  'disk_name => config in host.vars.disks',
  check_command    => 'disk',
  command_endpoint => 'host.name',
  vars             => '+ config',
  assign           => ['host.vars.os == Linux'],
  ignore           => ['host.vars.noagent'],
  target           => '/etc/icinga2/zones.d/global-templates/services.conf',
}

Parameters:

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

    Set to present enables the object, absent disables it.

  • service_name (String[1]) (defaults to: $title)

    Set the Icinga 2 name of the service object.

  • display_name (Optional[String[1]]) (defaults to: undef)

    A short description of the service.

  • host_name (Optional[String[1]]) (defaults to: undef)

    The host this service belongs to. There must be a Host object with that name.

  • groups (Optional[Array[String[1]]]) (defaults to: undef)

    The service groups this service belongs to.

  • vars (Optional[Icinga2::CustomAttributes]) (defaults to: undef)

    A dictionary containing custom attributes that are specific to this service, a string to do operations on this dictionary or an array for multiple use of custom attributes.

  • check_command (Optional[String[1]]) (defaults to: undef)

    The name of the check command.

  • max_check_attempts (Optional[Integer[1]]) (defaults to: undef)

    The number of times a service is re-checked before changing into a hard state.

  • check_period (Optional[String[1]]) (defaults to: undef)

    The name of a time period which determines when this service should be checked.

  • check_timeout (Optional[Icinga2::Interval]) (defaults to: undef)

    Check command timeout in seconds. Overrides the CheckCommand’s timeout attribute.

  • check_interval (Optional[Icinga2::Interval]) (defaults to: undef)

    The check interval (in seconds). This interval is used for checks when the service is in a HARD state.

  • retry_interval (Optional[Icinga2::Interval]) (defaults to: undef)

    The retry interval (in seconds). This interval is used for checks when the service is in a SOFT state.

  • enable_notifications (Optional[Boolean]) (defaults to: undef)

    Whether notifications are enabled.

  • enable_active_checks (Optional[Boolean]) (defaults to: undef)

    Whether active checks are enabled.

  • enable_passive_checks (Optional[Boolean]) (defaults to: undef)

    Whether passive checks are enabled.

  • enable_event_handler (Optional[Boolean]) (defaults to: undef)

    Enables event handlers for this host.

  • enable_flapping (Optional[Boolean]) (defaults to: undef)

    Whether flap detection is enabled.

  • enable_perfdata (Optional[Boolean]) (defaults to: undef)

    Whether performance data processing is enabled.

  • event_command (Optional[String[1]]) (defaults to: undef)

    The name of an event command that should be executed every time the service’s state changes or the service is in a SOFT state.

  • flapping_threshold_low (Optional[Integer[1]]) (defaults to: undef)

    Flapping lower bound in percent for a host to be considered not flapping.

  • flapping_threshold_high (Optional[Integer[1]]) (defaults to: undef)

    Flapping upper bound in percent for a host to be considered flapping.

  • volatile (Optional[Boolean]) (defaults to: undef)

    The volatile setting enables always HARD state types if NOT-OK state changes occur.

  • zone (Optional[String[1]]) (defaults to: undef)

    The zone this object is a member of.

  • command_endpoint (Optional[String[1]]) (defaults to: undef)

    The endpoint where commands are executed on.

  • notes (Optional[String[1]]) (defaults to: undef)

    Notes for the service.

  • notes_url (Optional[String[1]]) (defaults to: undef)

    Url for notes for the service (for example, in notification commands).

  • action_url (Optional[String[1]]) (defaults to: undef)

    Url for actions for the service (for example, an external graphing tool).

  • icon_image (Optional[String[1]]) (defaults to: undef)

    Icon image for the service. Used by external interfaces only.

  • icon_image_alt (Optional[String[1]]) (defaults to: undef)

    Icon image description for the service. Used by external interface only.

  • template (Boolean) (defaults to: false)

    Set to true creates a template instead of an object.

  • apply (Variant[Boolean, String[1]]) (defaults to: false)

    Dispose an apply instead an object if set to ‘true’. Value is taken as statement, i.e. ‘vhost => config in host.vars.vhosts’.

  • prefix (Variant[Boolean, String[1]]) (defaults to: false)

    Set service_name as prefix in front of ‘apply for’. Only effects if apply is a string.

  • assign (Array[String[1]]) (defaults to: [])

    Assign service using the assign rules.

  • ignore (Array[String[1]]) (defaults to: [])

    Exclude service using the ignore rules.

  • import (Array[String[1]]) (defaults to: [])

    Sorted List of templates to include.

  • target (Stdlib::Absolutepath)

    Destination config file to store in this object. File will be declared the first time.

  • order (Variant[String[1], Integer[0]]) (defaults to: 60)

    String or integer to set the position in the target file, sorted alpha numeric.

  • export (Variant[Array[String[1]], String[1]]) (defaults to: [])

    Export object to destination, collected by class ‘icinga2::query_objects`.



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
# File 'manifests/object/service.pp', line 151

define icinga2::object::service (
  Stdlib::Absolutepath                       $target,
  Enum['absent', 'present']                  $ensure                  = present,
  String[1]                                  $service_name            = $title,
  Optional[String[1]]                        $display_name            = undef,
  Optional[String[1]]                        $host_name               = undef,
  Optional[Array[String[1]]]                 $groups                  = undef,
  Optional[Icinga2::CustomAttributes]        $vars                    = undef,
  Optional[String[1]]                        $check_command           = undef,
  Optional[Integer[1]]                       $max_check_attempts      = undef,
  Optional[String[1]]                        $check_period            = undef,
  Optional[Icinga2::Interval]                $check_timeout           = undef,
  Optional[Icinga2::Interval]                $check_interval          = undef,
  Optional[Icinga2::Interval]                $retry_interval          = undef,
  Optional[Boolean]                          $enable_notifications    = undef,
  Optional[Boolean]                          $enable_active_checks    = undef,
  Optional[Boolean]                          $enable_passive_checks   = undef,
  Optional[Boolean]                          $enable_event_handler    = undef,
  Optional[Boolean]                          $enable_flapping         = undef,
  Optional[Boolean]                          $enable_perfdata         = undef,
  Optional[String[1]]                        $event_command           = undef,
  Optional[Integer[1]]                       $flapping_threshold_low  = undef,
  Optional[Integer[1]]                       $flapping_threshold_high = undef,
  Optional[Boolean]                          $volatile                = undef,
  Optional[String[1]]                        $zone                    = undef,
  Optional[String[1]]                        $command_endpoint        = undef,
  Optional[String[1]]                        $notes                   = undef,
  Optional[String[1]]                        $notes_url               = undef,
  Optional[String[1]]                        $action_url              = undef,
  Optional[String[1]]                        $icon_image              = undef,
  Optional[String[1]]                        $icon_image_alt          = undef,
  Variant[Boolean, String[1]]                $apply                   = false,
  Variant[Boolean, String[1]]                $prefix                  = false,
  Array[String[1]]                           $assign                  = [],
  Array[String[1]]                           $ignore                  = [],
  Array[String[1]]                           $import                  = [],
  Boolean                                    $template                = false,
  Variant[String[1], Integer[0]]             $order                   = 60,
  Variant[Array[String[1]], String[1]]       $export                  = [],
) {
  require icinga2::globals

  # compose the attributes
  $attrs = {
    'display_name'            => $display_name,
    'host_name'               => $host_name,
    'check_command'           => $check_command,
    'check_timeout'           => $check_timeout,
    'check_interval'          => $check_interval,
    'check_period'            => $check_period,
    'retry_interval'          => $retry_interval,
    'max_check_attempts'      => $max_check_attempts,
    'groups'                  => $groups,
    'enable_notifications'    => $enable_notifications,
    'enable_active_checks'    => $enable_active_checks,
    'enable_passive_checks'   => $enable_passive_checks,
    'enable_event_handler'    => $enable_event_handler,
    'enable_flapping'         => $enable_flapping,
    'enable_perfdata'         => $enable_perfdata,
    'event_command'           => $event_command,
    'flapping_threshold_low'  => $flapping_threshold_low,
    'flapping_threshold_high' => $flapping_threshold_high,
    'volatile'                => $volatile,
    'zone'                    => $zone,
    'command_endpoint'        => $command_endpoint,
    'notes'                   => $notes,
    'notes_url'               => $notes_url,
    'action_url'              => $action_url,
    'icon_image'              => $icon_image,
    'icon_image_alt'          => $icon_image_alt,
    'vars'                    => $vars,
  }

  # create object
  $config = {
    'object_name' => $service_name,
    'object_type' => 'Service',
    'import'      => $import,
    'apply'       => $apply,
    'prefix'      => $prefix,
    'assign'      => $assign,
    'ignore'      => $ignore,
    'template'    => $template,
    'attrs'       => delete_undef_values($attrs),
    'attrs_list'  => keys($attrs),
  }

  unless empty($export) {
    @@icinga2::config::fragment { "icinga2::object::Service::${title}":
      tag     => prefix(any2array($export), 'icinga2::instance::'),
      content => epp('icinga2/object.conf.epp', $config),
      target  => $target,
      order   => $order,
    }
  } else {
    icinga2::object { "icinga2::object::Service::${title}":
      ensure => $ensure,
      target => $target,
      order  => $order,
      *      => $config,
    }
  }
}