summaryrefslogtreecommitdiff
path: root/sitemodules/profiles/manifests/icinga2_master.pp
blob: ae1f18bab5c298b4fd541861da2267ce7fb944e7 (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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# Class: profiles::icinga2_master
# ===============================
#
# This class installs and configures the Icinga2 master with
# PostgreSQL IDO backend
#
# Parameters
# ----------
#
# @param web2_database_name     database name for IcingaWeb2 database
# @param web2_database_user     database user for IcingaWeb2 database
# @param web2_database_password database password for IcingaWeb2 database
# @param api_users              Icinga2 API users
# @param ca_key                 Icinga2 CA private key content
# @param ca_certificate         Icinga2 CA certificate content
# @param master_key             Icinga2 master private key content
# @param master_csr             Icinga2 master CSR
#
# Examples
# --------
#
# @example
#   class roles::myhost {
#     include profiles::icinga2_master
#   }
#
# Authors
# -------
#
# Jan Dittberner <jandd@cacert.org>
#
# Copyright
# ---------
#
# Copyright 2019 Jan Dittberner
class profiles::icinga2_master (
  String $ido_database_password,
  String $web2_database_password,
  Hash[String, Hash[String, Variant[String, Tuple[String, 1]]]] $api_users,
  String $pki_ticket_salt,
  String $ca_key,
  String $ca_certificate,
  String $master_key,
  String $master_csr,
) {
  include profiles::icinga2_common
  include postgresql::server

  class { '::icinga2':
    manage_repo => false,
    features    => ['mainlog', 'checker'],
    constants   => {
      'TicketSalt' => $pki_ticket_salt,
      'ZoneName'   => $::fqdn,
    },
  }

  class { '::icinga2::pki::ca':
    ca_cert => $ca_certificate,
    ca_key  => $ca_key,
  }

  postgresql::server::db { 'icinga2':
    user     => 'icinga2',
    password => postgresql_password('icinga2', $ido_database_password),
  }

  class { '::icinga2::feature::idopgsql':
    user          => 'icinga2',
    password      => $ido_database_password,
    database      => 'icinga2',
    import_schema => true,
    require       => Postgresql::Server::Db['icinga2'],
  }

  class { '::icinga2::feature::api':
    pki         => 'icinga2',
    ticket_salt => $pki_ticket_salt,
    endpoints   => {
      $::fqdn => {},
    },
    zones       => {
      $::fqdn => {
        'endpoints' => [$::fqdn],
      },
    },
  }

  icinga2::object::zone { 'global-templates':
    global => true,
  }

  #file { '/etc/icinga2/conf.d/api-users.conf':
  #  ensure  => file,
  #  content => epp('profiles/icinga2_master/conf.d/api-users.conf.epp', {
  #    'api_users' => $api_users
  #  }),
  #  owner   => 'root',
  #  group   => 'nagios',
  #  mode    => '0640',
  #  require => Package['icinga2'],
  #}

  create_resources(icinga2::object::apiuser, $api_users)
  #file { "/var/lib/icinga2/certs/${::facts['fqdn']}.key":
  #  ensure  => file,
  #  owner   => 'nagios',
  #  group   => 'nagios',
  #  mode    => '0600',
  #  content => $master_key,
  #  require => File['/var/lib/icinga2/certs'],
  #}
  #file { "/var/lib/icinga2/certs/${::facts['fqdn']}.csr":
  #  ensure  => file,
  #  owner   => 'nagios',
  #  group   => 'nagios',
  #  mode    => '0644',
  #  content => $master_csr,
  #  require => File['/var/lib/icinga2/certs'],
  #}
  #file { '/var/lib/icinga2/ca':
  #  ensure  => directory,
  #  owner   => 'nagios',
  #  group   => 'nagios',
  #  mode    => '0700',
  #  require => Package['icinga2'],
  #}
  #file { '/var/lib/icinga2/ca/ca.key':
  #  ensure  => file,
  #  content => $ca_key,
  #  owner   => 'nagios',
  #  group   => 'nagios',
  #  mode    => '0600',
  #  require => File['/var/lib/icinga2/ca'],
  #}
  #file { '/var/lib/icinga2/ca/ca.crt':
  #  ensure  => file,
  #  content => $::profiles::icinga2_common::ca_certificate,
  #  owner   => 'nagios',
  #  group   => 'nagios',
  #  mode    => '0644',
  #  require => File['/var/lib/icinga2/ca'],
  #}
  #exec { "/usr/sbin/icinga2 node setup --master":
  #  creates => "/etc/icinga2/features-enabled/api.conf",
  #  require => [
  #    Package['icinga2'],
  #    File['/var/lib/icinga2/ca/ca.key'],
  #    File["/var/lib/icinga2/certs/${::facts['fqdn']}.key"]
  #  ],
  #  notify  => Service['icinga2'],
  #}
  #exec { '/usr/sbin/icinga2 feature enable ido-pgsql':
  #  creates => "/etc/icinga2/features-enabled/ido-pgsql.conf",
  #  require => Package['icinga2-ido-pgsql'],
  #  notify  => Service['icinga2'],
  #}
  #service { 'icinga2':
  #  ensure    => 'running',
  #  enable    => true,
  #  require   => [
  #    Package['icinga2'],
  #    Package['icinga2-ido-pgsql'],
  #  ],
  #  subscribe => [
  #    File['/etc/icinga2/icinga2.conf'],
  #    File['/etc/icinga2/init.conf'],
  #    File['/etc/icinga2/features-enabled/checker.conf'],
  #    File['/etc/icinga2/features-enabled/mainlog.conf'],
  #    File['/etc/icinga2/features-enabled/notification.conf'],
  #    File['/etc/icinga2/zones.conf'],
  #    File['/etc/icinga2/conf.d/api-users.conf'],
  #    File['/var/lib/icinga2/ca'],
  #    File['/var/lib/icinga2/ca/ca.key'],
  #    File['/var/lib/icinga2/ca/ca.crt'],
  #    File['/var/lib/icinga2/certs/ca.crt'],
  #  ],
  #}

  Icinga2::Object::Zone <<| |>> ~> Service['icinga2']
  Icinga2::Object::Endpoint <<| |>> ~> Service['icinga2']
}