Defined Type: monitoring::service

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

Overview

Parameters:

  • check_command (String)
  • notes_url (String)
  • ensure (Wmflib::Ensure) (defaults to: present)
  • description (Optional[String]) (defaults to: undef)
  • retries (Integer) (defaults to: 3)
  • 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)
  • config_dir (Stdlib::Unixpath) (defaults to: '/etc/nagios')
  • host (Variant[Stdlib::Host,String]) (defaults to: $facts['hostname'])
  • contact_group (Optional[String]) (defaults to: undef)
  • group (Optional[String]) (defaults to: undef)
  • notifications_enabled (Optional[Boolean]) (defaults to: undef)
  • event_handler (Optional[Variant[Boolean,String]]) (defaults to: undef)


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
# File 'modules/monitoring/manifests/service.pp', line 1

define monitoring::service(
    String                            $check_command,
    String                            $notes_url,
    Wmflib::Ensure                    $ensure                = present,
    Optional[String]                  $description           = undef,
    Integer                           $retries               = 3,
    Boolean                           $critical              = false,
    Boolean                           $passive               = false,
    Integer                           $freshness             = 36000, # sec
    Integer                           $check_interval        = 1, # min
    Integer                           $retry_interval        = 1, # min
    Stdlib::Unixpath                  $config_dir            = '/etc/nagios',
    Variant[Stdlib::Host,String]      $host                  = $facts['hostname'],
    Optional[String]                  $contact_group         = undef,
    Optional[String]                  $group                 = undef,
    Optional[Boolean]                 $notifications_enabled = undef,
    Optional[Variant[Boolean,String]] $event_handler         = undef,
){

    include monitoring
    $cluster_name           = $monitoring::cluster
    $do_paging              = $monitoring::do_paging
    # cast undef to an empty string
    # lint:ignore:only_variable_string
    $description_safe       = "${description}".regsubst('[`~!$%^&*"|\'<>?,()=]', '-', 'G')
    # lint:endignore
    $_notifications_enabled = pick($notifications_enabled, $monitoring::notifications_enabled)
    $servicegroups          = pick($group, $monitoring::nagios_group)
    $_contact_group         = pick($contact_group, $monitoring::contact_group)

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

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

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

    $check_volatile = $passive.bool2num
    $check_fresh = $passive.bool2num
    $is_active = (!$passive).bool2num

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

    # 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  => $_notifications_enabled.bool2str('1', '0'),
            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)
    }
}