Allow the addition of custom checks based on config_context, add roles to hostgroups

This commit is contained in:
Salt 2021-10-03 11:48:53 -05:00
parent 18655b7d62
commit 7669234df9

View File

@ -77,15 +77,26 @@ define service {
{% endif %} {% endif %}
# Hostgroups # 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) %} {% 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 { define hostgroup {
hostgroup_name tag-{{ tag.value.slug }} hostgroup_name tag-{{ tag.value.slug }}
alias {{ tag.value.display }} alias {{ tag.value.display }}
} }
{% endfor %} {% 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)%} {% 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 %} {% if host.value.primary_ip %}
{% for tag in host.value.tags %} {% for tag in host.value.tags %}
@ -98,12 +109,24 @@ define host {
hostgroups ansible{% for tag in host.value.tags %},tag-{{ tag.slug }}{% endfor %} 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 %} {% endif %}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% endfor %} {% 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) %} {% for service in query('netbox.netbox.nb_lookup', 'services', api_endpoint='https://netbox.desu.ltd', token=netbox_token) %}
{% if service.value.device %} {% if service.value.device %}
{% set host_name = service.value.device.name %} {% set host_name = service.value.device.name %}