aboutsummaryrefslogtreecommitdiffstats
path: root/roles/nagios_server/templates/etc/nagios/objects/services.cfg.j2
blob: 032fbbae25791aaa53808fdcab0fbf6bf8c88632 (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
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
###############
# Local checks
###############

# Upstream packet loss
define service {
  service_description upstream-packet-loss
  host_name           {{ inventory_hostname }}
  use                 generic-service
  check_command       check_ping!{{ nagios_connectivity_check_host }}!{{ nagios_connectivity_check_count }}!{{ nagios_connectivity_check_rtt_warn }},{{ nagios_connectivity_check_loss_warn | replace('%', '') }}%!{{ nagios_connectivity_check_rtt_crit }},{{ nagios_connectivity_check_loss_crit | replace('%', '') }}%
}

# Nagios web gui
define service {
  service_description https
  host_name           {{ inventory_hostname }}
  use                 generic-service
  check_command       check_https!$_HOSTFQDN$!{{ nagios_certificate_warn }}!{{ nagios_certificate_crit }}!{{ nagios_http_warn }}!{{ nagios_http_crit }}!-e 'HTTP/1.1 401'
  servicegroups       https
}

###############
# DNS checks
###############

{% for item in nagios_check_dns %}
# {{ item.name }} - {{ item.qtype | default('A') | upper }}
define service {
  {% if (item.qtype | default('A') | upper) == 'A' %}
  service_description dns-{{ item.name }}
  {% else %}
  service_description dns-{{ item.name }}-{{ item.qtype | lower }}
  {% endif %}
  host_name           {{ inventory_hostname }}
  use                 generic-service
  check_command       check_dns_response!{{ item.server }}!{{ item.name }}!{{ item.qtype | default('A') | upper }}!{{ item.expect }}
  servicegroups       dns
}

{% endfor %}


###############
# Common checks
###############

# SSH
define service {
  service_description  ssh
  hostgroups           nagios_check_ssh
  use                  generic-service
  check_command        check_ssh
}

# Systemd
define service {
  service_description  systemd
  hostgroups           nagios_check_systemd
  use                  generic-service
  check_command        check_systemd_by_ssh
  servicegroups        ssh
}

# Check if services need restart or system needs reboot
define service {
  service_description      needs-restart
  hostgroups               nagios_el_clients
  use                      generic-service
  check_command            check_needs_restart_by_ssh
  servicegroups            ssh
  check_interval           60
  # only alert if needs-restart doesn't resolve within 24h
  first_notification_delay 1440
}

{% for host in groups.nagios_check_load %}
# Load - {{ host }}
define service {
  service_description  load
  host_name            {{ host }}
  use                  generic-service
  check_command        check_snmp_load!{{ hostvars[host].nagios_load_1m_warn }},{{ hostvars[host].nagios_load_5m_warn }},{{ hostvars[host].nagios_load_15m_warn }}!{{ hostvars[host].nagios_load_1m_crit }},{{ hostvars[host].nagios_load_5m_crit }},{{ hostvars[host].nagios_load_15m_crit }}
  servicegroups        snmp
}

{% endfor %}

{% for host in groups.nagios_check_mem %}
# Memory / Swap - {{ host }}
{% if host in groups.nagios_check_zfs %}
define service {
  service_description  mem
  host_name            {{ host }}
  use                  generic-service
  check_command        check_mem_by_ssh!{{ hostvars[host].nagios_mem_warn | replace('%', '') }}!{{ hostvars[host].nagios_mem_crit | replace('%', '') }}
  servicegroups        ssh
}
define service {
  service_description  swap
  host_name            {{ host }}
  use                  generic-service
  check_command        check_swap_by_ssh!{{ 100 - (hostvars[host].nagios_swap_warn | replace('%', '') | int) }}%!{{ 100 - (hostvars[host].nagios_swap_crit | replace('%', '') | int) }}%
  servicegroups        ssh
}
{% else %}
define service {
  service_description  mem
  host_name            {{ host }}
  use                  generic-service
  check_command        check_snmp_mem!{{ hostvars[host].nagios_mem_warn | replace('%', '') }},{{ hostvars[host].nagios_swap_warn | replace('%', '') }}!{{ hostvars[host].nagios_mem_crit | replace('%', '') }},{{ hostvars[host].nagios_swap_crit | replace('%', '') }}
  servicegroups        snmp
}
{% endif %}

{% endfor %}

{% for host in groups.nagios_check_disk %}
# Disk Usage - {{ host }}
{% for disk in hostvars[host].nagios_disks %}
define service {
  service_description {% if disk is string %}{{ disk }}{% elif disk.description is defined %}{{ disk.description }}{% else %}{{ disk.path }}{% endif %}

  host_name      {{ host }}
  use            generic-service
  check_command  check_snmp_storage{% if disk.terse | default(false) %}_terse{% endif %}!{% if disk is string %}{{ disk }}{% elif disk.regex is defined %}{{ disk.regex | replace('!', '\\!') }}{% else %}{{ disk.path }}{% endif %}!{{ disk.warn | default(hostvars[host].nagios_disk_warn) }}!{{ disk.crit | default(hostvars[host].nagios_disk_crit) }}!{% if disk.exclude | default(false) %}--exclude{% endif %} {% if disk.regex is not defined %}--noregexp{% endif %}

  servicegroups  snmp
}

{% endfor %}
{% endfor %}

{% for host in groups.nagios_check_interfaces %}
# Network Interfaces - {{ host }}
{% for intf in hostvars[host].nagios_interfaces %}
define service {
  service_description  {% if intf is string %}{{ intf }}{% elif intf.description is defined %}{{ intf.description }}{% else %}{{ intf.name }}{% endif %}

  host_name            {{ host }}
  use                  generic-service
  check_interval       5
  retry_interval       5
  check_command        check_snmp_interface!{% if intf is string %}{{ intf }}{% elif intf.regex is defined %}{{ intf.regex | replace('!', '\\!') }}{% else %}{{ intf.name }}{% endif %}!{{ intf.bandwidth_warn | default(hostvars[host].nagios_interface_bandwidth_warn) }},{{ intf.bandwidth_warn | default(hostvars[host].nagios_interface_bandwidth_warn) }},{{ intf.error_warn | default(hostvars[host].nagios_interface_error_warn) }},{{ intf.error_warn | default(hostvars[host].nagios_interface_error_warn) }},{{ intf.discard_warn | default(hostvars[host].nagios_interface_discard_warn) }},{{ intf.discard_warn | default(hostvars[host].nagios_interface_discard_warn) }}!{{ intf.bandwidth_crit | default(hostvars[host].nagios_interface_bandwidth_crit) }},{{ intf.bandwidth_crit | default(hostvars[host].nagios_interface_bandwidth_crit) }},{{ intf.error_crit | default(hostvars[host].nagios_interface_error_crit) }},{{ intf.error_crit | default(hostvars[host].nagios_interface_error_crit) }},{{ intf.discard_crit | default(hostvars[host].nagios_interface_discard_crit) }},{{ intf.discard_crit | default(hostvars[host].nagios_interface_discard_crit) }}!{% if intf.down_ok | default(false) %}--down{% endif %} {% if intf.regex is not defined %}--noregexp{% endif %}
  servicegroups        snmp
}

{% endfor %}
{% endfor %}


############
# ZFS Checks
############

{% for host in groups.nagios_check_zfs %}
# zpools - {{ host }}
define service {
  service_description  zpool
  host_name            {{ host }}
  use                  generic-service
  check_command        check_zpools_by_ssh!{{ 100 - (hostvars[host].nagios_disk_warn|replace('%','') | int) }}!{{ 100 - (hostvars[host].nagios_disk_crit|replace('%','') | int) }}
  servicegroups        ssh
}

{% endfor %}


#######################
# Infrastructure Checks
#######################

# UPS
define service {
  service_description  status
  hostgroups           ups
  use                  generic-service
  check_command        check_cyberpower!status
  servicegroups        snmp
}

define service {
  service_description  health
  hostgroups           ups
  use                  generic-service
  check_command        check_cyberpower!health
  servicegroups        snmp
}

define service {
  service_description  battery
  hostgroups           ups
  use                  generic-service
  check_command        check_cyberpower!battery
  servicegroups        snmp
}

define service {
  service_description  transfer
  hostgroups           ups
  use                  generic-service
  check_command        check_cyberpower!transfer
  servicegroups        snmp
}

{% for host in groups.ups %}
# UPS Temp - {{ host }}
define service {
  service_description  temp
  host_name            {{ host }}
  use                  generic-service
  check_command        check_cyberpower!temp!-w {{ hostvars[host].nagios_temp_warn }} -c {{ hostvars[host].nagios_temp_crit }}
  servicegroups        snmp
}

define service {
# UPS Load - {{ host }}
  service_description  load
  host_name            {{ host }}
  use                  generic-service
  check_command        check_cyberpower!load! -w {{ hostvars[host].nagios_power_draw_warn | replace('%', '') }} -c {{ hostvars[host].nagios_power_draw_crit | replace('%', '') }}
  servicegroups        snmp
}

{% endfor %}


#################
# Asterisk Checks
#################

define service {
  service_description registrations
  hostgroups          asterisk_servers
  use                 generic-service
  check_command       check_asterisk_registrations
}

{% for host in groups.asterisk_servers %}
# endpoints - {{ host }}
define service {
  service_description endpoints
  host_name           {{ host }}
  use                 generic-service
  check_command       check_asterisk_endpoints!{{ hostvars[host].asterisk_https_port | default(8089) }}!nagios!{{ hostvars[host].asterisk_ari_users | selectattr('name', '==', 'nagios') | map(attribute='password') | first }}!{{ (hostvars[host].asterisk_sip_trunks + hostvars[host].asterisk_sip_extensions) | map(attribute='name') | join(' ' ) }}
}
{% endfor %}


######################
# SMTP Checks
######################

{% for host in groups.mail_servers %}
define service {
  service_description smtp
  host_name           {{ host }}
  use                 generic-service
  check_command       check_smtp!{{ hostvars[host].nagios_certificate_warn }}!{{ hostvars[host].nagios_certificate_crit }}!{{ hostvars[host].nagios_smtp_warn }}!{{ hostvars[host].nagios_smtp_crit }}
}

define service {
  service_description mailq
  host_name           {{ host }}
  use                 generic-service
  check_command       check_mailq!{{ hostvars[host].nagios_mailq_warn }}!{{ hostvars[host].nagios_mailq_crit }}
}

{% endfor %}


######################
# IMAP Checks
######################

{% for host in groups.imap_servers %}
define service {
  service_description imap
  host_name           {{ host }}
  use                 generic-service
  check_command       check_imap!{{ hostvars[host].nagios_certificate_warn }}!{{ hostvars[host].nagios_certificate_crit }}!{{ hostvars[host].nagios_imap_warn }}!{{ hostvars[host].nagios_imap_crit }}
}

{% endfor %}


######################
# XMPP Checks
######################

{% for host in groups.xmpp_servers %}
{% for vhost in hostvars[host].prosody_vhosts %}
define service {
  service_description xmpp-{{ vhost }}
  host_name           {{ host }}
  use                 generic-service
  check_command       check_xmpp!{{ vhost }}!{{ hostvars[host].nagios_certificate_warn }}!{{ hostvars[host].nagios_certificate_crit }}
}

{% endfor %}
{% for vhost in hostvars[host].prosody_conference_vhosts | default(['conference.'] | product(hostvars[host].prosody_vhosts) | map('join') | list) %}
define service {
  service_description xmpp-{{ vhost }}
  host_name           {{ host }}
  use                 generic-service
  check_command       check_xmpp!{{ vhost }}!{{ hostvars[host].nagios_certificate_warn }}!{{ hostvars[host].nagios_certificate_crit }}
}

{% endfor %}
{% endfor %}


######################
# PostgreSQL Checks
######################

{% for host in groups.postgresql_servers %}
define service {
  service_description postgres
  host_name           {{ host }}
  use                 generic-service
  check_command       check_postgres!{{ hostvars[host].nagios_certificate_warn }}!{{ hostvars[host].nagios_certificate_crit }}
}

{% endfor %}


######################
# HTTPS Checks
######################

{% for host in groups.nagios_check_https %}
# {{ host }}
{% for vhost in hostvars[host].nagios_https_vhosts | default(['$_HOSTFQDN$']) %}
define service {
  service_description {{ 'https' if loop.length == 1 else 'https-'~(vhost if vhost is string else vhost.name) }}
  host_name           {{ host }}
  use                 generic-service
  check_command       check_https!{{ vhost if vhost is string else vhost.name }}!{{ hostvars[host].nagios_certificate_warn }}!{{ hostvars[host].nagios_certificate_crit }}!{{ hostvars[host].nagios_http_warn }}!{{ hostvars[host].nagios_http_crit }}!{{ '-e HTTP/1.1 '~vhost.status if vhost.status is defined else '-e HTTP/1.1 '~hostvars[host].nagios_http_status if hostvars[host].nagios_http_status is defined else '' }}
  servicegroups       https
}
{% endfor %}

{% endfor %}


######################
# DNS Checks
######################

{% for host in groups.authoritative_nameservers %}
{% for zone in hostvars[host].nsd_zones | map(attribute='name') %}
define service {
  service_description dns-{{ zone }}
  host_name           {{ host }}
  use                 generic-service
  check_command       check_dns!{{ zone }}!SOA
}

{% endfor %}
{% endfor %}


######################
# FreeIPA Checks
######################

define service {
  service_description dns
  hostgroups          freeipa_servers
  use                 generic-service
  check_command       check_dns!{{ domain }}!SOA
}

{% for host in groups.freeipa_servers %}
define service {
  service_description ldap
  hostgroups          freeipa_servers
  use                 generic-service
  check_command       check_ldaps!{{ freeipa_basedn }}!{{ hostvars[host].nagios_certificate_warn }}!{{ hostvars[host].nagios_certificate_crit }}
}

{% endfor %}