aboutsummaryrefslogtreecommitdiff
path: root/modules/profile/manifests/monitoring/local_service.pp
blob: 0caf72ee941475ce2424559246bc4bc2eb4645eb (plain) (blame)
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
define profile::monitoring::local_service (
  Optional[Hash] $sudos  = {},
  Optional[Hash] $common = {},
  Optional[Hash] $master = {},
  Optional[Hash] $local  = {},
) {
  $service_description = $title
  $real_hostname = lookup("base_installation::real_hostname")

  Nagios_service {
    ensure  => "present",
    owner   => "naemon",
    group   => "naemon",
    notify  => Service["naemon"],
    before  => Service["naemon"],
    require => File["/etc/naemon"],
  }

  $service_generic = {
    active_checks_enabled        => "1",
    check_freshness              => "0",
    check_interval               => "10",
    check_period                 => "24x7",
    contact_groups               => "admins",
    event_handler_enabled        => "1",
    flap_detection_enabled       => "1",
    is_volatile                  => "0",
    max_check_attempts           => "3",
    notification_interval        => "60",
    notification_options         => "w,u,c,r",
    notification_period          => "24x7",
    notifications_enabled        => "0",
    obsess_over_service          => "1",
    passive_checks_enabled       => "1",
    process_perf_data            => "1",
    retain_nonstatus_information => "1",
    retain_status_information    => "1",
    retry_interval               => "2",
  }

  $service_local = merge($service_generic, {
    host_name          => $real_hostname,
    check_interval     => "5",
    max_check_attempts => "4",
    retry_interval     => "1",
    })

  $sudos.each |$sudo_name, $content| {
    sudo::conf { $sudo_name:
      content        => $content,
      before         => Nagios_service[$service_description],
    }
  }

  [true, false].each |$services_for_master| {
    if $services_for_master {
      $default_local = {
        mode           => "0644",
        target         => "/etc/naemon/services_for_master.cfg",
        check_interval => $service_local["check_interval"],
        retry_interval => $service_local["retry_interval"],
        host_name      => $service_local["host_name"],
        use            => "external-service",
        notify         => [],
      }
      $t = "master - "
      $services_key = $master
    } else {
      $default_local = merge($service_local, { target => "/etc/naemon/objects.cfg" })
      $t = ""
      $services_key = $local
    }

    $hash = merge($default_local, $common, $services_key)

    nagios_service { "$t$service_description":
      service_description => $service_description,
      *                   => $hash
    }
  }
}