Defined Type: icinga2::object::notification

Defined in:
manifests/object/notification.pp

Summary

Manage Icinga 2 notification objects.

Overview

Parameters:

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

    Set to present enables the object, absent disables it.

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

    Set the Icinga 2 name of the notification object.

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

    The name of the host this notification belongs to.

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

    The short name of the service this notification belongs to. If omitted, this notification object is treated as host notification.

  • 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.

  • users (Optional[Variant[String[1], Array[String[1]]]]) (defaults to: undef)

    A list of user names who should be notified.

  • user_groups (Optional[Variant[String[1], Array[String[1]]]]) (defaults to: undef)

    A list of user group names who should be notified.

  • times (Optional[Hash[String[1], Any]]) (defaults to: undef)

    A dictionary containing begin and end attributes for the notification.

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

    The name of the notification command which should be executed when the notification is triggered.

  • interval (Optional[Variant[Icinga2::Interval,Pattern[/(host|service)\./]]]) (defaults to: undef)

    The notification interval (in seconds). This interval is used for active notifications.

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

    The name of a time period which determines when this notification should be triggered.

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

    The zone this object is a member of.

  • types (Optional[Variant[Array, String[1]]]) (defaults to: undef)

    A list of type filters when this notification should be triggered.

  • states (Optional[Variant[Array, String[1]]]) (defaults to: undef)

    A list of state filters when this notification should be triggered.

  • 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 notification_name as prefix in front of ‘apply for’. Only effects if apply is a string.

  • apply_target (Enum['Host', 'Service']) (defaults to: 'Host')

    An object type on which to target the apply rule. Valid values are ‘Host` and `Service`.

  • 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: 85)

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

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

    Assign notification using the assign rules.

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

    Exclude notification using the ignore rules.

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

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



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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
# File 'manifests/object/notification.pp', line 84

define icinga2::object::notification (
  Stdlib::Absolutepath                                                $target,
  Enum['absent', 'present']                                           $ensure            = present,
  String[1]                                                           $notification_name = $title,
  Optional[String[1]]                                                 $host_name         = undef,
  Optional[String[1]]                                                 $service_name      = undef,
  Optional[Icinga2::CustomAttributes]                                 $vars              = undef,
  Optional[Variant[String[1], Array[String[1]]]]                      $users             = undef,
  Optional[Variant[String[1], Array[String[1]]]]                      $user_groups       = undef,
  Optional[Hash[String[1], Any]]                                       $times             = undef,
  Optional[String[1]]                                                 $command           = undef,
  Optional[Variant[Icinga2::Interval,Pattern[/(host|service)\./]]]    $interval          = undef,
  Optional[String[1]]                                                 $period            = undef,
  Optional[String[1]]                                                 $zone              = undef,
  Optional[Variant[Array, String[1]]]                                 $types             = undef,
  Optional[Variant[Array, String[1]]]                                 $states            = undef,
  Variant[Boolean, String[1]]                                         $apply             = false,
  Variant[Boolean, String[1]]                                         $prefix            = false,
  Enum['Host', 'Service']                                             $apply_target      = 'Host',
  Array[String[1]]                                                    $assign            = [],
  Array[String[1]]                                                    $ignore            = [],
  Array[String[1]]                                                    $import            = [],
  Boolean                                                             $template          = false,
  Variant[String[1], Integer[0]]                                      $order             = 85,
  Variant[Array[String[1]], String[1]]                                $export            = [],
) {
  require icinga2::globals

  if $ignore != [] and $assign == [] {
    fail('When attribute ignore is used, assign must be set.')
  }

  # compose attributes
  $attrs = {
    'host_name'    => $host_name,
    'service_name' => $service_name,
    'users'        => $users,
    'user_groups'  => $user_groups,
    'times'        => $times,
    'command'      => $command,
    'interval'     => $interval,
    'period'       => $period,
    'zone'         => $zone,
    'types'        => $types,
    'states'       => $states,
    'vars'         => $vars,
  }

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

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