Genericize manually-defined checks into tagged Netbox services

This commit is contained in:
Salt 2021-08-15 02:29:56 -05:00
parent 73abab9607
commit 9ab0f62442

View File

@ -74,35 +74,6 @@ define service {
hostgroup_name snmp
}
# Manually-defined services for hosts
# web1.desu.ltd
{% for site in ["9iron.club","desu.ltd","nc.desu.ltd","git.desu.ltd"] %}
define service {
use ansible-generic-service
service_description HTTPS - {{ site }}
check_command check_http!--ssl -H {{ site }}
host_name web1.desu.ltd
}
{% endfor %}
# web2.desu.ltd
{% for site in ["cowfee.moe","tube.cowfee.moe"] %}
define service {
use ansible-generic-service
service_description HTTPS - {{ site }}
check_command check_http!--ssl -H {{ site }}
host_name web2.desu.ltd
}
{% endfor %}
# web3.desu.ltd
{% for site in ["netbox.desu.ltd","nagios.desu.ltd -e 401"] %}
define service {
use ansible-generic-service
service_description HTTPS - {{ site }}
check_command check_http!--ssl -H {{ site }}
host_name web3.desu.ltd
}
{% endfor %}
# Hostgroups
# Everything here is dynamically-generated based on tags from Netbox
{% for tag in query('netbox.netbox.nb_lookup', 'tags', api_endpoint='https://netbox.desu.ltd', token=netbox_token) %}
@ -129,3 +100,49 @@ define host {
{% endfor %}
{% endif %}
{% endfor %}
# This list of services is dynamically generated based on services in Netbox and how they're tagged
{% 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 %}
{% elif service.value.virtual_machine %}
{% set host_name = service.value.virtual_machine.name %}
{% endif %}
# {{ host_name }} - {{ service.value.display }}
# Description: {{ service.value.description }}
# Created: {{ service.value.created }}
# Updated: {{ service.value.last_updated }}
{% for tag in service.value.tags %}
{# #}
{% if tag.slug == "nagios-checkhttp" %}
{% if 80 in service.value.ports %}
define service {
use ansible-generic-service
service_description HTTP - {{ service.value.name }}
check_command check_http!-H {{ service.value.name }} -f stickyport
host_name {{ host_name }}
}
{% endif %}
{% if 443 in service.value.ports %}
define service {
use ansible-generic-service
service_description HTTPS - {{ service.value.name }}
check_command check_http!--ssl -H {{ service.value.name }} -f stickyport
host_name {{ host_name }}
}
{% endif %}
{% endif %}
{# #}
{% if tag.slug == "nagios-checktcp" %}
{% for port in service.value.ports %}
define service {
use ansible-generic-service
service_description TCP {{ port }} - {{ service.value.name }}
check_command check_tcp!{{ port }}
host_name {{ host_name }}
}
{% endfor %}
{% endif %}
{# #}
{% endfor %}
{% endfor %}