summaryrefslogtreecommitdiff
path: root/sitemodules/profiles/manifests/icinga2_agent.pp
blob: 285ba743c94ec141724becc8ba0e28c636bb00a3 (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
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
# Class: profiles::icinga2_agent
# ==============================
#
# This class installs and configures an Icinga2 agent.
#
# Parameters
# ----------
#
# @param pki_api_user       Icinga2 API user name for retrieving a
#                           ticket for a certificate signing request
# @param pki_api_password   Icinga2 API password for retrieving a ticket
#                           for a certificate signing request
#
# Examples
# --------
#
# @example
#   class roles::myhost {
#     include profiles::icinga2_agent
#   }
#
# Authors
# -------
#
# Jan Dittberner <jandd@cacert.org>
#
# Copyright
# ---------
#
# Copyright 2019 Jan Dittberner
class profiles::icinga2_agent (
  String $pki_api_user,
  String $pki_api_password,
) {
  include 'profiles::icinga2_common'

  file { '/var/lib/icinga2/setup_agent.sh':
    ensure  => file,
    content => epp('profiles/icinga2_agent/setup_agent.sh.epp', {
      pki_api_user     => $pki_api_user,
      pki_api_password => $pki_api_password,
      master_host      => $::profiles::icinga2_common::master_host,
    }),
    owner   => 'nagios',
    group   => 'nagios',
    mode    => '0700',
  }
  exec { '/bin/sh /var/lib/icinga2/setup_agent.sh':
    creates => "/etc/icinga2/pki/${::fqdn}.key",
    require => [
      File['/var/lib/icinga2/setup_agent.sh'],
      File['/var/lib/icinga2/certs/ca.crt'],
      File["/var/lib/icinga2/certs/${::profiles::icinga2_common::master_host}.crt"],
      Package['icinga2'],
    ],
  }
  Exec['/bin/sh /var/lib/icinga2/setup_agent.sh'] ~> Service<| name == 'icinga2' |>

  @@icinga2::object::endpoint { $::fqdn:
    ensure        => present,
    target        => "/etc/icinga2/zones.d/${::fqdn}.conf",
  }

  @@icinga2::object::zone { $::fqdn:
    ensure    => present,
    endpoints => [$::fqdn],
    parent    => $::profiles::icinga2_common::master_host,
    target        => "/etc/icinga2/zones.d/${::fqdn}.conf",
  }
}