summaryrefslogtreecommitdiff
path: root/puppet/modules/site_nagios/manifests/add_host.pp
blob: 94352de464b5b3e3c527a284ae41efa8eaff2e3e (plain)
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
define site_nagios::add_host (
  $domain_internal,
  $ip_address,
  $services,
  $openvpn_gateway_address='' ) {

    $nagios_hostname = $domain_internal

    # Add Nagios host
    nagios_host { $nagios_hostname:
      address => $ip_address,
      use     => 'generic-host',
    }

    # Add Nagios service

    # First, we need to turn the serice array into hash, using a "hash template"
    # see https://github.com/ashak/puppet-resource-looping
    $nagios_service_hashpart = {
      'hostname'    => $nagios_hostname,
      'ip_address'  => $ip_address,
      'openvpn_gw'  => $openvpn_gateway_address,
    }
    $dynamic_parameters = {
      'service' => '%s'
    }
    $nagios_servicename = "${nagios_hostname}_%s"

    $nagios_service_hash = create_resources_hash_from($nagios_servicename, $services, $nagios_service_hashpart, $dynamic_parameters)

    create_resources ( site_nagios::add_service, $nagios_service_hash )
}