From 4c2bfb996c248d2b99ffd8801428a2653909799d Mon Sep 17 00:00:00 2001 From: Salt Date: Sun, 8 Aug 2021 02:24:59 -0500 Subject: [PATCH] Actually add that Nagios template --- playbooks/tasks/web/nagios-hosts.cfg.j2 | 94 +++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 playbooks/tasks/web/nagios-hosts.cfg.j2 diff --git a/playbooks/tasks/web/nagios-hosts.cfg.j2 b/playbooks/tasks/web/nagios-hosts.cfg.j2 new file mode 100644 index 0000000..33e1ef8 --- /dev/null +++ b/playbooks/tasks/web/nagios-hosts.cfg.j2 @@ -0,0 +1,94 @@ +# This file is managed via Ansible +# Any changes made WILL be overwritten + +# Templates +define host { + name ansible-linux-server + check_period 24x7 + check_interval 5 + retry_interval 1 + max_check_attempts 10 + check_command check-host-alive + notification_period 24x7 + notification_interval 120 + hostgroups ansible + check_period 24x7 + contacts salt + register 0 +} +define service { + use generic-service + name ansible-generic-service + max_check_attempts 5 + check_interval 5 + retry_interval 1 + register 0 +} + +# Contacts +define contact { + contact_name salt + host_notifications_enabled 1 + host_notification_period 24x7 + host_notification_commands notify-host-by-email + service_notifications_enabled 1 + service_notification_period 24x7 + service_notification_commands notify-service-by-email + email rehashedsalt@cock.li +} + +# Default hostgroup and its checks +define hostgroup { + hostgroup_name ansible + alias Ansible-managed Hosts +} +define service { + use ansible-generic-service + service_description SSH + check_command check_ssh + hostgroup_name ansible +} + +# Commands +# Ain't nobody here but us chickens... + +# 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 +} + +# 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) %} +define hostgroup { + hostgroup_name {{ 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 +{% 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 %} +{% if tag.slug == "nagios" %} +define host { + use ansible-linux-server + host_name {{ host.value.name }} + alias {{ host.value.display }} + address {{ host.value.primary_ip.address.split('/',1)[0] }} + hostgroups ansible{% for tag in host.value.tags %},{{ tag.slug }}{% endfor %} + +} +{% endif %} +{% endfor %} +{% endif %} +{% endfor %}