Defined Type: monitoring::service

Defined in:
modules/monitoring/manifests/service.pp

Overview

Parameters:

  • description (Optional[String])
  • check_command (String)
  • notes_url (String)
  • host (Variant[Stdlib::Host,String]) (defaults to: $::hostname)
  • retries (Integer) (defaults to: 3)
  • group (Optional[String]) (defaults to: undef)
  • ensure (Wmflib::Ensure) (defaults to: present)
  • critical (Boolean) (defaults to: false)
  • passive (Boolean) (defaults to: false)
  • freshness (Integer) (defaults to: 36000)
  • check_interval (Integer) (defaults to: 1)
  • retry_interval (Integer) (defaults to: 1)
  • contact_group (String) (defaults to: lookup('contactgroups', {'default_value' => 'admins'}))
  • config_dir (Stdlib::Unixpath) (defaults to: '/etc/nagios')
  • event_handler (Optional[Variant[Boolean,String]]) (defaults to: undef)
  • notifications_enabled (Optional[Variant[Integer[0, 1],Boolean,String]]) (defaults to: $::profile::base::notifications_enabled)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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
# File 'modules/monitoring/manifests/service.pp', line 1

define monitoring::service(
    Optional[String] $description,
    String $check_command,
    String $notes_url,
    Variant[Stdlib::Host,String] $host = $::hostname,
    Integer $retries        = 3,
    Optional[String] $group = undef,
    Wmflib::Ensure $ensure  = present,
    Boolean $critical       = false,
    Boolean $passive        = false,
    Integer $freshness      = 36000,
    Integer $check_interval = 1,
    Integer $retry_interval = 1,
    String $contact_group   = lookup('contactgroups', {'default_value' => 'admins'}), # FIXME, defines should not have calls to hiera/lookup
    Stdlib::Unixpath $config_dir = '/etc/nagios',
    Optional[Variant[Boolean,String]] $event_handler = undef,
    Optional[Variant[Integer[0, 1],Boolean,String]] $notifications_enabled = $::profile::base::notifications_enabled, # FIXME, base modules should not reference variables in the profile name space
){

    # the list of characters is the default for illegal_object_name_chars
    # nagios/icinga option
    if $description {
        $description_safe = regsubst($description, '[`~!$%^&*"|\'<>?,()=]', '-', 'G')
    } else {
        $description_safe = ''
    }

    if $check_command =~ /\\n/ {
        fail("Parameter check_command cannot contain newlines: ${check_command}")
    }

    if ! $host {
        fail("Parameter ${host} not defined!")
    }

    $cluster_name = lookup('cluster')

    $servicegroups = $group ? {
        /.+/    => $group,
        default => hiera('nagios_group',"${cluster_name}_${::site}")
    }

    $notification_interval = $critical ? {
        true    => 240,
        default => 0,
    }

    # If a service is set to critical and
    # paging is not disabled for this machine in hiera,
    # then use the "sms" contact group which creates pages.
    $do_paging = hiera('do_paging', true)

    case $critical {
        true: {
            case $do_paging {
                true:    {
                  $real_contact_groups = "${contact_group},sms,admins"
                  $real_description = "${description_safe} #page"
                }
                default: {
                  $real_contact_groups = "${contact_group},admins"
                  $real_description = $description_safe
                }
            }
        }
        default: {
          $real_contact_groups = $contact_group
          $real_description = $description_safe
        }
    }

    $is_active = $passive ? {
        true    => 0,
        default => 1,
    }

    $check_volatile = $passive ? {
        true    => 1,
        default => 0,
    }

    $check_fresh = $passive ? {
        true    => 1,
        default => 0,
    }

    $is_fresh = $passive ? {
        true    => $freshness,
        default => undef,
    }

    # Safeguard against notifications enabled not being defined due to class
    # declarations
    if $notifications_enabled {
        $real_notifications_enabled = $notifications_enabled
    } else {
        $real_notifications_enabled = '1'
    }

    # the nagios service instance
    $service = {
        "${::hostname} ${title}" => {
            ensure                 => $ensure,
            host_name              => $host,
            servicegroups          => $servicegroups,
            service_description    => $real_description,
            check_command          => $check_command,
            max_check_attempts     => $retries,
            check_interval         => $check_interval,
            retry_interval         => $retry_interval,
            check_period           => '24x7',
            notification_interval  => $notification_interval,
            notification_period    => '24x7',
            notification_options   => 'c,r,f',
            notifications_enabled  => $real_notifications_enabled,
            contact_groups         => $real_contact_groups,
            passive_checks_enabled => 1,
            active_checks_enabled  => $is_active,
            is_volatile            => $check_volatile,
            check_freshness        => $check_fresh,
            freshness_threshold    => $is_fresh,
            event_handler          => $event_handler,
            notes_url              => $notes_url,
        },
    }
    # This is a hack. We detect if we are running on the scope of an icinga
    # host and avoid exporting the resource if yes
    if defined(Class['icinga']) {
        create_resources(nagios_service, $service)
    } else {
        create_resources('monitoring::exported_nagios_service', $service)
    }
}