Defined Type: nrpe::monitor_systemd_unit_state

Defined in:
modules/nrpe/manifests/monitor_systemd_unit_state.pp

Overview

Define: nrpe::monitor_systemd_unit_state

Installs a check for a systemd unit state using systemctl

Parameters:

  • unit (Any) (defaults to: $title)
  • description (Any) (defaults to: "${title} service")
  • contact_group (Any) (defaults to: 'admins')
  • retries (Any) (defaults to: 3)
  • timeout (Any) (defaults to: 10)
  • critical (Any) (defaults to: false)
  • ensure (Any) (defaults to: 'present')
  • expected_state (Any) (defaults to: 'active')
  • lastrun (Any) (defaults to: '')
  • notes_url (Stdlib::Httpsurl) (defaults to: 'https://wikitech.wikimedia.org/wiki/Monitoring/systemd_unit_state')
  • check_interval (Any) (defaults to: 1)


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
# File 'modules/nrpe/manifests/monitor_systemd_unit_state.pp', line 4

define nrpe::monitor_systemd_unit_state(
    $unit = $title,
    $description = "${title} service",
    $contact_group = 'admins',
    $retries = 3,
    $timeout = 10,
    $critical = false,
    $ensure = 'present',
    $expected_state = 'active',
    $lastrun = '',
    Stdlib::Httpsurl $notes_url = 'https://wikitech.wikimedia.org/wiki/Monitoring/systemd_unit_state',
    $check_interval = 1,
    ){

    if $::initsystem != 'systemd' {
        fail('nrpe::monitor_systemd_unit can only work on systemd-enabled systems')
    }
    require nrpe::systemd_scripts

    # Temporary hack until we fix the downstream modules
    if $critical {
        $nagios_critical = true
    } else {
        $nagios_critical = false
    }

    nrpe::monitor_service { "${unit}-state":
        ensure         => $ensure,
        description    => $description,
        nrpe_command   => "/usr/local/bin/nrpe_check_systemd_unit_state '${unit}' ${expected_state} ${lastrun}",
        retries        => $retries,
        timeout        => $timeout,
        critical       => $nagios_critical,
        notes_url      => $notes_url,
        check_interval => $check_interval,
    }
}