Puppet Class: profile::icinga

Defined in:
modules/profile/manifests/icinga.pp

Overview

Class: profile::icinga

Sets up a icinga instance which checks services and hosts for Wikimedia Production cluster

Parameters

Parameters:

  • monitoring_groups (Hash[String, Hash]) (defaults to: lookup('monitoring::groups'))
  • ldap_config (Hash[String, String]) (defaults to: lookup('ldap', {'merge' => 'hash'}))
  • active_host (String) (defaults to: lookup('profile::icinga::active_host'))
  • partners (Array[String]) (defaults to: lookup('profile::icinga::partners'))
  • ensure_service (Enum['stopped', 'running']) (defaults to: lookup('profile::icinga::ensure_service'))
  • virtual_host (String) (defaults to: lookup('profile::icinga::virtual_host'))
  • icinga_user (String) (defaults to: lookup('profile::icinga::icinga_user'))
  • icinga_group (String) (defaults to: lookup('profile::icinga::icinga_group'))
  • retention_file (Stdlib::Unixpath) (defaults to: lookup('profile::icinga::retention_file'))
  • max_concurrent_checks (Integer) (defaults to: lookup('profile::icinga::max_concurrent_checks'))
  • check_result_path (Stdlib::Unixpath) (defaults to: lookup('profile::icinga::check_result_path'))
  • temp_path (Stdlib::Unixpath) (defaults to: lookup('profile::icinga::temp_path'))
  • temp_file (Stdlib::Unixpath) (defaults to: lookup('profile::icinga::temp_file'))
  • status_file (Stdlib::Unixpath) (defaults to: lookup('profile::icinga::status_file'))
  • apache2_htpasswd_salt (String) (defaults to: lookup('profile::icinga::apache2_htpasswd_salt'))
  • apache2_auth_users (Hash[String, String]) (defaults to: lookup('profile::icinga::apache2_auth_users'))
  • datacenters (Array[String]) (defaults to: lookup('datacenters'))
  • atlas_measurements (Hash[String, Hash]) (defaults to: lookup('ripeatlas_measurements'))
  • logs_keep_days (Integer[1]) (defaults to: lookup('profile::icinga::logs_keep_days'))


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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'modules/profile/manifests/icinga.pp', line 8

class profile::icinga(
    Hash[String, Hash]            $monitoring_groups     = lookup('monitoring::groups'),
    Hash[String, String]          $ldap_config           = lookup('ldap', {'merge' => 'hash'}),
    String                        $active_host           = lookup('profile::icinga::active_host'),
    Array[String]                 $partners              = lookup('profile::icinga::partners'),
    Enum['stopped', 'running']    $ensure_service        = lookup('profile::icinga::ensure_service'),
    String                        $virtual_host          = lookup('profile::icinga::virtual_host'),
    String                        $icinga_user           = lookup('profile::icinga::icinga_user'),
    String                        $icinga_group          = lookup('profile::icinga::icinga_group'),
    Stdlib::Unixpath              $retention_file        = lookup('profile::icinga::retention_file'),
    Integer                       $max_concurrent_checks = lookup('profile::icinga::max_concurrent_checks'),
    Stdlib::Unixpath              $check_result_path     = lookup('profile::icinga::check_result_path'),
    Stdlib::Unixpath              $temp_path             = lookup('profile::icinga::temp_path'),
    Stdlib::Unixpath              $temp_file             = lookup('profile::icinga::temp_file'),
    Stdlib::Unixpath              $status_file           = lookup('profile::icinga::status_file'),
    String                        $apache2_htpasswd_salt = lookup('profile::icinga::apache2_htpasswd_salt'),
    Hash[String, String]          $apache2_auth_users    = lookup('profile::icinga::apache2_auth_users'),
    Array[String]                 $datacenters           = lookup('datacenters'),
    Hash[String, Hash]            $atlas_measurements    = lookup('ripeatlas_measurements'),
    Integer[1]                    $logs_keep_days        = lookup('profile::icinga::logs_keep_days'),
){
    $is_passive = !($::fqdn == $active_host)

    require_package('mariadb-client')

    # leaving address blank means also using IPv6
    class { 'rsync::server':
        address => '',
    }

    class { 'netops::monitoring':
        atlas_measurements => $atlas_measurements,
    }
    class { 'facilities': }
    class { 'service::monitor': }
    # Experimental load-balancer monitoring for services using service-checker
    class { 'lvs::monitor_services':
        main_datacenters => ['eqiad', 'codfw'],
        all_datacenters  => $datacenters,
    }
    class { 'icinga::monitor::checkpaging': }

    class { 'icinga::nsca::daemon':
        icinga_user  => $icinga_user,
        icinga_group => $icinga_group,
    }

    class { 'icinga::monitor::wikidata': }

    class { 'icinga::monitor::ores':
        icinga_user  => $icinga_user,
        icinga_group => $icinga_group,
    }

    class { 'icinga::monitor::toollabs': }
    class { 'icinga::monitor::legal': }
    class { 'icinga::monitor::certs': }
    class { 'icinga::monitor::commons': }

    class { 'icinga::monitor::elasticsearch::cirrus_cluster_checks': }

    # Experimental load-balancer monitoring for cloudelastic service using service-checker
    # This was isolated from lvs::monitor_services as cloudelastic use case deviates from
    # the usual use case. see T229621
    class { 'icinga::monitor::cloudelastic': }

    class { 'icinga::monitor::wdqs': }
    class { 'icinga::monitor::performance': }
    class { 'icinga::monitor::services': }
    class { 'icinga::monitor::reading_web': }
    class { 'icinga::monitor::traffic': }
    class { 'icinga::monitor::gerrit': }
    class { 'icinga::monitor::librenms': }

    # check planet for cert expiration and regular content updates
    # warn/crit = hours before content is considered stale
    class { 'icinga::monitor::planet':
        url  => 'https://en.planet.wikimedia.org/',
        warn => 24,
        crit => 48,
    }

    class { 'icinga::event_handlers::raid':
        icinga_user  => $icinga_user,
        icinga_group => $icinga_group,
    }

    class { 'profile::bird::anycast_monitoring': }
    class { 'profile::prometheus::alerts': }
    class { 'profile::thanos::alerts': }
    class { 'profile::maps::alerts': }
    class { 'profile::cache::kafka::alerts': }
    class { 'profile::mediawiki::alerts': }
    class { 'profile::swift::alerts': }
    class { 'profile::ceph::alerts': }
    class { 'profile::logstash::alerts': }

    class { 'profile::prometheus::icinga_exporter': }

    # Check that the public eventstreams endpoint's recentchange stream has data.
    # See also: T215013. (The default params use the public endpoint.)
    class { 'profile::eventstreams::monitoring': }

    class { 'icinga::monitor::etcd_mw_config':
        icinga_user => $icinga_user,
    }


    class { 'snmp::mibs': }

    create_resources(monitoring::group, $monitoring_groups)

    monitoring::service { 'https':
        description   => 'HTTPS',
        check_command => "check_ssl_http_letsencrypt!${virtual_host}",
        notes_url     => 'https://wikitech.wikimedia.org/wiki/Icinga',
    }

    $ircbot_present = $is_passive ? {
        false => 'present', #aka active
        true  => 'absent',
    }
    $enable_notifications = $is_passive ? {
        false => 1, #aka active
        true  => 0,
    }
    $enable_event_handlers = $is_passive ? {
        false => 1, #aka active
        true  => 0,
    }

    class { 'icinga':
        enable_notifications  => $enable_notifications,
        enable_event_handlers => $enable_event_handlers,
        ensure_service        => $ensure_service,
        icinga_user           => $icinga_user,
        icinga_group          => $icinga_group,
        max_concurrent_checks => $max_concurrent_checks,
        retention_file        => $retention_file,
        logs_keep_days        => $logs_keep_days,
    }

    class { 'sslcert::dhparam': }
    class { 'icinga::web':
        icinga_user           => $icinga_user,
        icinga_group          => $icinga_group,
        virtual_host          => $virtual_host,
        apache2_htpasswd_salt => $apache2_htpasswd_salt,
        apache2_auth_users    => $apache2_auth_users,
        ldap_server           => $ldap_config['ro-server'],
        ldap_server_fallback  => $ldap_config['ro-server-fallback'],
    }
    include profile::idp::client::httpd
    include profile::icinga::external_monitoring

    class { 'icinga::naggen':
        icinga_user  => $icinga_user,
        icinga_group => $icinga_group,
    }

    class { 'profile::icinga::ircbot':
        ensure => $ircbot_present,
    }

    if ($is_passive) {

        file { '/etc/icinga/active_host':
          ensure  => present,
          owner   => 'root',
          group   => 'root',
          mode    => '0444',
          content => $active_host,
        }

        file { '/usr/local/sbin/sync_icinga_state':
          ensure  => present,
          owner   => 'root',
          group   => 'root',
          mode    => '0755',
          content => file('role/icinga/sync_icinga_state.sh'),
        }

        base::service_auto_restart { 'apache2': }

    }

    # In order to do failovers, we need to be able to rsync state
    # from any one to any other, whether or not Puppet has run any subset
    # of the hosts.
    $all_icinga_hosts = $partners + $active_host

    $all_icinga_hosts.each |String $partner| {
        ferm::service { "icinga-rsync-${partner}":
            proto  => 'tcp',
            port   => 873,
            srange => "(@resolve(${partner}) @resolve(${partner}, AAAA))",
        }
    }

    rsync::server::module { 'icinga-tmpfs':
        read_only   => 'yes',
        path        => '/var/icinga-tmpfs',
        hosts_allow => $all_icinga_hosts
    }
    rsync::server::module { 'icinga-cache':
        read_only   => 'yes',
        path        => '/var/cache/icinga',
        hosts_allow => $all_icinga_hosts
    }
    rsync::server::module { 'icinga-lib':
        read_only   => 'yes',
        path        => '/var/lib/icinga',
        hosts_allow => $all_icinga_hosts
    }

    # access to the web interface
    ferm::service { 'icinga-https':
      proto => 'tcp',
      port  => 443,
    }

    ferm::service { 'icinga-http':
      proto => 'tcp',
      port  => 80,
    }

    # allow NSCA (Nagios Service Check Acceptor)
    # connections on port 5667/tcp
    ferm::service { 'icinga-nsca':
        proto  => 'tcp',
        port   => '5667',
        srange => '($DOMAIN_NETWORKS $FRACK_NETWORKS)',
    }

    # We absent the cron on active hosts, should only exist on passive ones
    $cron_presence = $is_passive ? {
        true  => 'present',
        false => 'absent',
    }

    cron { 'sync-icinga-state':
        ensure  => $cron_presence,
        minute  => '33',
        command => "/usr/bin/systemd-cat -t 'sync_icinga_state' /usr/local/sbin/run-no-puppet /usr/local/sbin/sync_icinga_state",
    }

    # On the passive host, replace the downtime script with a warning.
    $absent_script = @("SCRIPT")
    #!/bin/sh
    echo 'This is not the active Icinga host. Please go to ${active_host} instead.'
    exit 127
    | SCRIPT
    $downtime_script = $is_passive ? {
        true  => $absent_script,
        false => file('profile/icinga/icinga-downtime.sh'),
    }

    # script to schedule host/service downtimes
    file { '/usr/local/bin/icinga-downtime':
        ensure  => present,
        content => $downtime_script,
        owner   => 'root',
        group   => 'root',
        mode    => '0550',
    }

    # On the passive host, display a warning in the MOTD.
    $motd_presence = $is_passive ? {
        true  => 'present',
        false => 'absent',
    }

    motd::script { 'inactive_warning':
        ensure   => $motd_presence,
        priority => 1,
        content  => template('profile/icinga/inactive.motd.erb'),
    }

    $metamonitor_home = '/var/lib/metamonitor'
    user { 'metamonitor':
        ensure     => present,
        system     => true,
        home       => $metamonitor_home,
        managehome => true,
        shell      => '/bin/bash',
        groups     => $icinga_group,
    }

    file { "${metamonitor_home}/.ssh":
        ensure => directory,
        owner  => 'metamonitor',
        group  => 'metamonitor',
        mode   => '0700',
    }

    file { "${metamonitor_home}/.ssh/known_hosts":
        ensure => present,
        source => 'puppet:///modules/profile/icinga/metamonitor_known_hosts',
        owner  => 'metamonitor',
        group  => 'metamonitor',
        mode   => '0644',
    }

    ::keyholder::agent { 'metamonitor':
        trusted_groups => ['metamonitor'],
    }

    systemd::timer::job { 'sync_check_icinga_contacts':
        ensure                    => present,
        description               => 'Automatically sync the Icinga contacts to the metamonitoring host',
        command                   => '/usr/local/bin/sync-check-icinga-contacts',
        interval                  => {
            'start'    => 'OnCalendar',
            # Daily splayed by hostname at minute 19.
            # Depending on fqdn_rand seed there's the risk of not splaying
            # evenly throught the day.
            'interval' => "*-*-* ${sprintf('%02d', fqdn_rand(24, 1))}:19:00",
        },
        logging_enabled           => false,
        monitoring_enabled        => true,
        monitoring_contact_groups => 'admins',
        user                      => 'metamonitor',
        require                   => File['/usr/local/bin/sync-check-icinga-contacts'],
    }
}