From 8e845b5f4e1e8c4dc06005dad2eef13508fd789b Mon Sep 17 00:00:00 2001 From: Salt Date: Mon, 6 Sep 2021 19:43:54 -0500 Subject: [PATCH] Modularize out all our service checks I want them in DATA STRUCTURES God dammit. Get them out of the config file. --- playbooks/tasks/web/nagios-ansible.cfg.j2 | 93 ++++------------------- playbooks/tasks/web/nagios.yml | 47 ++++++++++++ 2 files changed, 61 insertions(+), 79 deletions(-) diff --git a/playbooks/tasks/web/nagios-ansible.cfg.j2 b/playbooks/tasks/web/nagios-ansible.cfg.j2 index ec84707..490f2ad 100644 --- a/playbooks/tasks/web/nagios-ansible.cfg.j2 +++ b/playbooks/tasks/web/nagios-ansible.cfg.j2 @@ -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 diff --git a/playbooks/tasks/web/nagios.yml b/playbooks/tasks/web/nagios.yml index 9e00526..2070b0c 100644 --- a/playbooks/tasks/web/nagios.yml +++ b/playbooks/tasks/web/nagios.yml @@ -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