From 7669234df944f0d9eb291754603775af8cfd6915 Mon Sep 17 00:00:00 2001 From: Salt Date: Sun, 3 Oct 2021 11:48:53 -0500 Subject: [PATCH] Allow the addition of custom checks based on config_context, add roles to hostgroups --- playbooks/tasks/web/nagios-ansible.cfg.j2 | 29 ++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/playbooks/tasks/web/nagios-ansible.cfg.j2 b/playbooks/tasks/web/nagios-ansible.cfg.j2 index ac43218..587881e 100644 --- a/playbooks/tasks/web/nagios-ansible.cfg.j2 +++ b/playbooks/tasks/web/nagios-ansible.cfg.j2 @@ -77,15 +77,26 @@ define service { {% endif %} # Hostgroups -# Everything here is dynamically-generated based on tags from Netbox +{% for role in query('netbox.netbox.nb_lookup', 'device-roles', api_endpoint='https://netbox.desu.ltd', token=netbox_token) %} +# Device Role: {{ role.value.name }} +# Description: {{ role.value.description }} +# Created: {{ role.value.created }} +# Updated: {{ role.value.last_updated }} +define hostgroup { + hostgroup_name role-{{ role.value.slug }} + alias {{ role.value.display }} +} +{% endfor %} {% for tag in query('netbox.netbox.nb_lookup', 'tags', api_endpoint='https://netbox.desu.ltd', token=netbox_token) %} +# Tag: {{ tag.value.name }} +# Description: {{ tag.value.description }} define hostgroup { hostgroup_name tag-{{ tag.value.slug }} alias {{ tag.value.display }} } {% endfor %} -# This list of hosts is dynamically generated based on devices and VMs tagged with "nagios" in Netbox +# Hosts {% for host in query('netbox.netbox.nb_lookup', 'devices', api_endpoint='https://netbox.desu.ltd', token=netbox_token) + query('netbox.netbox.nb_lookup', 'virtual-machines', api_endpoint='https://netbox.desu.ltd', token=netbox_token)%} {% if host.value.primary_ip %} {% for tag in host.value.tags %} @@ -98,12 +109,24 @@ define host { hostgroups ansible{% for tag in host.value.tags %},tag-{{ tag.slug }}{% endfor %} } +{% if host.value.config_context.extra_checks is defined %} +{% for check in host.value.config_context.extra_checks %} + define service { + # Config Context check + use ansible-generic-service + service_description {{ check.description }} + check_command {{ check.command }} + host_name {{ host.value.name }} + } +{% endfor %} +{% endif %} +{# #} {% endif %} {% endfor %} {% endif %} {% endfor %} -# This list of services is dynamically generated based on services in Netbox and how they're tagged +# Services unique to hosts {% for service in query('netbox.netbox.nb_lookup', 'services', api_endpoint='https://netbox.desu.ltd', token=netbox_token) %} {% if service.value.device %} {% set host_name = service.value.device.name %}