2021-09-24 20:48:41 -05:00
# {{ ansible_managed }}
2021-08-08 02:24:59 -05:00
# Templates
define host {
name ansible-linux-server
check_period 24x7
2021-12-18 08:20:24 -06:00
check_interval 10
2022-01-03 17:49:09 -06:00
retry_interval 3
2021-08-08 02:24:59 -05:00
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
2022-01-04 17:33:34 -06:00
max_check_attempts 10
2021-12-18 08:20:24 -06:00
check_interval 10
2022-01-04 17:33:34 -06:00
retry_interval 2
2021-08-08 02:24:59 -05:00
register 0
}
2021-09-07 13:31:04 -05:00
# Default hostgroup
2021-08-08 02:24:59 -05:00
define hostgroup {
hostgroup_name ansible
alias Ansible-managed Hosts
}
2021-10-06 15:30:12 -05:00
{% if nagios_contacts is defined %}
# Contacts
# Everything here is defined in nagios_contacts
{% for contact in nagios_contacts %}
define contact {
contact_name {{ contact.name }}
alias {{ contact.alias | default(contact.name, true ) }}
host_notifications_enabled {{ contact.host_notifications_enabled | default('1', true) }}
host_notification_period {{ contact.host_notification_period | default('24x7', true) }}
host_notification_options {{ contact.host_notification_options | default('d,u,r,f', true ) }}
host_notification_commands {{ contact.host_notification_commands }}
service_notifications_enabled {{ contact.service_notifications_enabled | default('1', true) }}
service_notification_period {{ contact.service_notification_period | default('24x7', true) }}
service_notification_options {{ contact.service_notification_options | default('w,c,r,f', true ) }}
service_notification_commands {{ contact.service_notification_commands }}
{% if contact.extra is defined %}
{% for kvp in contact.extra %}
{{ kvp.key }} {{ kvp.value }}
{% endfor %}
{% endif %}
}
{% endfor %}
{% endif %}
2021-12-24 16:56:06 -06:00
# And a contactgroup
define contactgroup {
contactgroup_name ansible
alias Ansible notification contacts
members nagiosadmin
}
2021-10-06 15:13:55 -05:00
{% if nagios_commands is defined %}
2021-08-08 02:24:59 -05:00
# Commands
2021-09-07 13:31:04 -05:00
# Everything here is defined in nagios_commands
{% for command in nagios_commands %}
2021-08-15 14:24:35 -05:00
define command {
2021-09-07 13:31:04 -05:00
command_name {{ command.name }}
2021-09-07 14:27:23 -05:00
command_line {{ command.command }}
2021-09-07 13:31:04 -05:00
{% if command.extra is defined %}
{% for kvp in command.extra %}
{{ kvp.key }} {{ kvp.value }}
{% endfor %}
{% endif %}
2021-08-15 14:24:35 -05:00
}
2021-09-07 13:31:04 -05:00
{% endfor %}
{% endif %}
2021-08-08 02:24:59 -05:00
2021-10-06 15:13:55 -05:00
{% if nagios_services is defined %}
2021-09-06 19:43:54 -05:00
# Services
# Everything here is defined in nagios_services
{% for service in nagios_services %}
2021-08-08 02:24:59 -05:00
define service {
use ansible-generic-service
2021-09-06 19:43:54 -05:00
service_description {{ service.name }}
check_command {{ service.command }}
2021-09-07 14:27:23 -05:00
hostgroup_name {{ service.hostgroup | default('ansible', true) }}
2021-12-24 16:56:06 -06:00
contact_groups ansible
2021-09-06 19:43:54 -05:00
{% if service.extra is defined %}
{% for kvp in service.extra %}
{{ kvp.key }} {{ kvp.value }}
{% endfor %}
{% endif %}
2021-08-23 18:18:53 -05:00
}
2021-09-06 19:43:54 -05:00
{% endfor %}
{% endif %}
2021-08-15 14:24:35 -05:00
2021-08-08 02:24:59 -05:00
# Hostgroups
2021-10-03 11:48:53 -05:00
{% 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 %}
2021-08-08 02:24:59 -05:00
{% for tag in query('netbox.netbox.nb_lookup', 'tags', api_endpoint='https://netbox.desu.ltd', token=netbox_token) %}
2021-10-03 11:48:53 -05:00
# Tag: {{ tag.value.name }}
# Description: {{ tag.value.description }}
2021-08-08 02:24:59 -05:00
define hostgroup {
2021-09-26 10:23:46 -05:00
hostgroup_name tag-{{ tag.value.slug }}
2021-08-08 02:24:59 -05:00
alias {{ tag.value.display }}
}
{% endfor %}
2021-10-03 11:48:53 -05:00
# Hosts
2021-08-08 02:24:59 -05:00
{% 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" %}
2021-11-07 08:55:05 -06:00
# {{ host }}
2021-08-08 02:24:59 -05:00
define host {
use ansible-linux-server
host_name {{ host.value.name }}
alias {{ host.value.display }}
address {{ host.value.primary_ip.address.split('/',1)[0] }}
2021-11-07 08:55:05 -06:00
hostgroups ansible{% for tag in host.value.tags %},tag-{{ tag.slug }}{% endfor %}{% if host.value.device_role is defined -%},role-{{ host.value.device_role.slug }}{% endif %}{% if host.value.role is defined %},role-{{ host.value.role.slug }}{% endif %}
2021-08-08 02:24:59 -05:00
2021-12-24 16:56:06 -06:00
contact_groups ansible
2021-08-08 02:24:59 -05:00
}
2021-10-03 11:48:53 -05:00
{% 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 }}
2021-12-24 16:56:06 -06:00
contact_groups ansible
2021-10-03 11:48:53 -05:00
}
{% endfor %}
{% endif %}
{# #}
2021-08-08 02:24:59 -05:00
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
2021-08-15 02:29:56 -05:00
2021-10-03 11:48:53 -05:00
# Services unique to hosts
2021-08-15 02:29:56 -05:00
{% 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 %}
{# #}
2021-12-24 14:53:09 -06:00
{% if tag.slug == "nagios-checkminecraft" %}
{% for port in service.value.ports %}
define service {
use ansible-generic-service
service_description Minecraft - {{ service.value.name }} - {{ port }}
check_command check_by_ssh!/usr/local/bin/monitoring-scripts/check_minecraft -H {{ host_name }} -p {{ port }} -m "{{ service.value.description }}" -f -w 3 -c 5
host_name {{ host_name }}
2021-12-24 16:56:06 -06:00
contact_groups ansible
2021-12-24 14:53:09 -06:00
}
{% endfor %}
{% endif %}
{# #}
2021-08-15 02:29:56 -05:00
{% if tag.slug == "nagios-checkhttp" %}
2021-11-21 13:59:05 -06:00
{% for port in service.value.ports %}
2021-08-15 02:29:56 -05:00
define service {
use ansible-generic-service
2021-11-21 13:59:05 -06:00
service_description HTTP - {{ service.value.name }} - {{ port }}
check_command check_http!-H {{ service.value.name }} -p {{ port }} -f sticky
2021-08-15 02:29:56 -05:00
host_name {{ host_name }}
2021-12-24 16:56:06 -06:00
contact_groups ansible
2021-08-15 02:29:56 -05:00
}
2021-11-21 13:59:05 -06:00
{% endfor %}
2021-08-15 02:29:56 -05:00
{% endif %}
2021-11-21 13:59:05 -06:00
{# #}
{% if tag.slug == "nagios-checkhttps" %}
{% for port in service.value.ports %}
2021-08-15 02:29:56 -05:00
define service {
use ansible-generic-service
2021-11-21 13:59:05 -06:00
service_description HTTPS - {{ service.value.name }} - {{ port }}
check_command check_http!--ssl -H {{ service.value.name }} -p {{ port }} -f sticky
2021-08-15 02:29:56 -05:00
host_name {{ host_name }}
2021-12-24 16:56:06 -06:00
contact_groups ansible
2021-08-15 02:29:56 -05:00
}
2021-11-21 13:59:05 -06:00
{% endfor %}
2021-08-15 02:29:56 -05:00
{% endif %}
{# #}
{% if tag.slug == "nagios-checktcp" %}
{% for port in service.value.ports %}
define service {
use ansible-generic-service
2021-08-15 02:44:42 -05:00
service_description TCP {{ service.value.name }} - {{ port }}
2021-08-15 02:29:56 -05:00
check_command check_tcp!{{ port }}
host_name {{ host_name }}
2021-12-24 16:56:06 -06:00
contact_groups ansible
2021-08-15 02:29:56 -05:00
}
{% endfor %}
{% endif %}
{# #}
{% endfor %}
{% endfor %}