Modularize out all our service checks

I want them in DATA STRUCTURES God dammit. Get them out of the config file.
This commit is contained in:
Salt 2021-09-06 19:43:54 -05:00
parent d3e51301bb
commit 8e845b5f4e
2 changed files with 61 additions and 79 deletions

View File

@ -56,88 +56,23 @@ define command {
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
# Services for all hosts
# Services
# Everything here is defined in nagios_services
{% if nagios_services is defined %}
{% for service in nagios_services %}
define service {
use ansible-generic-service
service_description HTTP
check_command check_http
hostgroup_name nagios-checkhttp
}
define service {
use ansible-generic-service
service_description HTTPS
check_command check_http!--ssl
hostgroup_name nagios-checkhttp
}
# Services for NRPE-capable hosts
define service {
use ansible-generic-service
service_description Disk Usage
check_command check_nrpe!check_disk_all
hostgroup_name nagios-nrpe
}
define service {
use ansible-generic-service
service_description Users
check_command check_nrpe!check_users
hostgroup_name nagios-nrpe
}
define service {
use ansible-generic-service
service_description CPU Load
check_command check_nrpe!check_load
hostgroup_name nagios-nrpe
}
define service {
use ansible-generic-service
service_description Reboot Required
check_command check_nrpe!check_reboot_required
hostgroup_name nagios-nrpe
}
# Systemd unit checks
define service {
use ansible-generic-service
service_description Unit ansible-pull.service
check_command check_nrpe!check_systemd_ansiblepull_service
hostgroup_name ansible-pull
}
define service {
use ansible-generic-service
service_description Unit backup.service
check_command check_nrpe!check_systemd_backup_service
hostgroup_name nagios-nrpe
}
define service {
use ansible-generic-service
service_description Unit backup.timer
check_command check_nrpe!check_systemd_backup_timer
hostgroup_name nagios-nrpe
}
define service {
use ansible-generic-service
service_description Unit ansible-pull.timer
check_command check_nrpe!check_systemd_ansiblepull_timer
hostgroup_name ansible-pull
}
define service {
use ansible-generic-service
service_description Unit docker.service
check_command check_nrpe!check_systemd_docker_service
hostgroup_name nagios-nrpe
}
define service {
use ansible-generic-service
service_description Swap Usage
check_command check_nrpe!check_swap
hostgroup_name nagios-nrpeswap
}
define service {
use ansible-generic-service
service_description PostgreSQL
check_command check_nrpe!check_pgsql
hostgroup_name nagios-checkpgsql
service_description {{ service.name }}
check_command {{ service.command }}
hostgroup_name {{ service.hostgroup }}
{% if service.extra is defined %}
{% for kvp in service.extra %}
{{ kvp.key }} {{ kvp.value }}
{% endfor %}
{% endif %}
}
{% endfor %}
{% endif %}
# Hostgroups
# Everything here is dynamically-generated based on tags from Netbox

View File

@ -4,6 +4,53 @@
tags: [ nagios ]
- name: template out config for nagios
template: src=nagios-ansible.cfg.j2 dest=/data/nagios/etc/objects/ansible.cfg owner=root group=root mode=0644
vars:
nagios_services:
# Agentless checks
- name: HTTP
command: check_http
hostgroup: nagios-checkhttp
- name: HTTPS
command: check_http!--ssl
hostgroup: nagios-checkhttp
# Agented checks
- name: CPU Load
command: check_nrpe!check_load
hostgroup: nagios-nrpe
- name: Disk Usage
command: check_nrpe!check_disk_all
hostgroup: nagios-nrpe
- name: Reboot Required
command: check_nrpe!check_reboot_required
hostgroup: nagios-nrpe
- name: Unit backup.service
command: check_nrpe!check_systemd_backup_service
hostgroup: nagios-nrpe
- name: Unit backup.timer
command: check_nrpe!check_systemd_backup_timer
hostgroup: nagios-nrpe
- name: Unit docker.service
command: check_nrpe!check_systemd_docker_service
hostgroup: nagios-nrpe
- name: Users
command: check_nrpe!check_users
hostgroup: nagios-nrpe
# Tag-specific checks
# ansible-pull
- name: Unit ansible-pull.service
command: check_nrpe!check_systemd_ansiblepull_service
hostgroup: ansible-pull
- name: Unit ansible-pull.timer
command: check_nrpe!check_systemd_ansiblepull_timer
hostgroup: ansible-pull
# nagios-checkpgsql
- name: PostgreSQL
command: check_nrpe!check_pgsql
hostgroup: nagios-checkpgsql
# nagios-nrpeswap
- name: Swap Usage
command: check_nrpe!check_swap
hostgroup: nagios-nrpeswap
register: config
tags: [ nagios, template ]
- name: assure config file is loaded