From 36cfe3a769ff36682e4a7caf4b9dff8aff8137ca Mon Sep 17 00:00:00 2001 From: Stephen Smoogen Date: Fri, 1 Dec 2017 01:44:30 +0000 Subject: [PATCH] try some logic in nagios jinja template to allow for hosts not to be defined --- inventory/host_vars/ns13.rdu2.fedoraproject.org | 6 ++++++ roles/nagios_server/templates/nagios/hostgroups/all.cfg.j2 | 2 +- .../templates/nagios/hostgroups/checkswap.cfg.j2 | 2 +- .../templates/nagios/hostgroups/vpnclients.cfg.j2 | 2 +- .../templates/nagios/hosts/bodhost-hosts.cfg.j2 | 2 +- .../templates/nagios/hosts/coloamer-hosts.cfg.j2 | 2 +- .../templates/nagios/hosts/dedicatedsolutions-hosts.cfg.j2 | 2 +- .../templates/nagios/hosts/host1plus-hosts.cfg.j2 | 2 +- .../templates/nagios/hosts/ibiblio-hosts.cfg.j2 | 2 +- .../templates/nagios/hosts/internetx-hosts.cfg.j2 | 2 +- .../templates/nagios/hosts/osuosl-hosts.cfg.j2 | 2 +- .../templates/nagios/hosts/phx2-external.cfg.j2 | 2 +- .../nagios_server/templates/nagios/hosts/phx2-hosts.cfg.j2 | 2 +- .../templates/nagios/hosts/rdu-cc-hosts.cfg.j2 | 2 +- .../templates/nagios/hosts/staging-hosts.cfg.j2 | 2 +- .../nagios_server/templates/nagios/hosts/tummy-hosts.cfg.j2 | 2 +- 16 files changed, 21 insertions(+), 15 deletions(-) diff --git a/inventory/host_vars/ns13.rdu2.fedoraproject.org b/inventory/host_vars/ns13.rdu2.fedoraproject.org index b028c53ea0..4e7d35244a 100644 --- a/inventory/host_vars/ns13.rdu2.fedoraproject.org +++ b/inventory/host_vars/ns13.rdu2.fedoraproject.org @@ -26,3 +26,9 @@ nrpe_procs_crit: 1400 collectd_graphite: True ansible_ssh_common_args: '-o ProxyCommand="ssh -W %h:%p -q root@bastion13.fedoraproject.org"' + +nagios_Check_Services: + nrpe: false + sshd: false + swap: false + ping: false diff --git a/roles/nagios_server/templates/nagios/hostgroups/all.cfg.j2 b/roles/nagios_server/templates/nagios/hostgroups/all.cfg.j2 index 049d490045..445c3e5700 100644 --- a/roles/nagios_server/templates/nagios/hostgroups/all.cfg.j2 +++ b/roles/nagios_server/templates/nagios/hostgroups/all.cfg.j2 @@ -18,7 +18,7 @@ define hostgroup{ define hostgroup{ hostgroup_name mincheckgrp alias mincheckgrp - members {% for host in groups['all'] %}{% if hostvars[host].nagios_Check_Services['nrpe'] != true %}{{host}}, {% endif %}{% endfor %} + members {% for host in groups['all'] %}{% if hostvars[host].nagios_Check_Services['nrpe'] != true and hostvars[host].nagios_Check_Services['ping'] == true %}{{host}}, {% endif %}{% endfor %} } diff --git a/roles/nagios_server/templates/nagios/hostgroups/checkswap.cfg.j2 b/roles/nagios_server/templates/nagios/hostgroups/checkswap.cfg.j2 index b133ee01d4..e36c3c5152 100644 --- a/roles/nagios_server/templates/nagios/hostgroups/checkswap.cfg.j2 +++ b/roles/nagios_server/templates/nagios/hostgroups/checkswap.cfg.j2 @@ -1,6 +1,6 @@ define hostgroup { hostgroup_name CheckSwap alias Swap-Is-Low - members {% for host in groups['all'] %}{% if hostvars[host].nagios_Check_Services['swap'] == true %}{{host}}{% if not loop.last %},{% endif %} {% endif %} {% endfor %} + members {% for host in groups['all'] %}{% if hostvars[host].nagios_Check_Services['swap'] == true and hostvars[host].nagios_Check_Services['ping'] == true %}{{host}}{% if not loop.last %},{% endif %} {% endif %} {% endfor %} } diff --git a/roles/nagios_server/templates/nagios/hostgroups/vpnclients.cfg.j2 b/roles/nagios_server/templates/nagios/hostgroups/vpnclients.cfg.j2 index 964cff5213..3a9d97b349 100644 --- a/roles/nagios_server/templates/nagios/hostgroups/vpnclients.cfg.j2 +++ b/roles/nagios_server/templates/nagios/hostgroups/vpnclients.cfg.j2 @@ -3,6 +3,6 @@ define hostgroup { hostgroup_name vpnclients alias vpnclients - members !download-rdu01.fedoraproject.org, !virthost-rdu01.fedoraproject.org, !bastion02.phx2.fedoraproject.org, {% for host in groups['all'] %}{% if ( hostvars[host].vpn == true ) %}{{host}},{% endif %} {% endfor %} + members {% for host in groups['all'] %}{% if ( hostvars[host].vpn == true ) and ( hostvars[host].nagios_Check_Services['ping'] == true ) %}{{host}},{% endif %} {% endfor %} } diff --git a/roles/nagios_server/templates/nagios/hosts/bodhost-hosts.cfg.j2 b/roles/nagios_server/templates/nagios/hosts/bodhost-hosts.cfg.j2 index b3c435c661..b8e0e34f34 100644 --- a/roles/nagios_server/templates/nagios/hosts/bodhost-hosts.cfg.j2 +++ b/roles/nagios_server/templates/nagios/hosts/bodhost-hosts.cfg.j2 @@ -1,5 +1,5 @@ {% for host in groups['all'] %} -{% if hostvars[host].datacenter == 'bodhost' %} +{% if hostvars[host].datacenter == 'bodhost' and hostvars[host].nagios_Check_Services['ping'] == true %} define host { {% if vars['nagios_location'] == 'internal' %} use defaulttemplate diff --git a/roles/nagios_server/templates/nagios/hosts/coloamer-hosts.cfg.j2 b/roles/nagios_server/templates/nagios/hosts/coloamer-hosts.cfg.j2 index 9f57973c2f..3fc1d4eac9 100644 --- a/roles/nagios_server/templates/nagios/hosts/coloamer-hosts.cfg.j2 +++ b/roles/nagios_server/templates/nagios/hosts/coloamer-hosts.cfg.j2 @@ -1,5 +1,5 @@ {% for host in groups['all'] %} -{% if hostvars[host].datacenter == 'coloamer' %} +{% if hostvars[host].datacenter == 'coloamer' and hostvars[host].nagios_Check_Services['ping'] == true %} define host { {% if vars['nagios_location'] == 'internal' %} use defaulttemplate diff --git a/roles/nagios_server/templates/nagios/hosts/dedicatedsolutions-hosts.cfg.j2 b/roles/nagios_server/templates/nagios/hosts/dedicatedsolutions-hosts.cfg.j2 index 38e56da70c..951a4a0d69 100644 --- a/roles/nagios_server/templates/nagios/hosts/dedicatedsolutions-hosts.cfg.j2 +++ b/roles/nagios_server/templates/nagios/hosts/dedicatedsolutions-hosts.cfg.j2 @@ -1,5 +1,5 @@ {% for host in groups['all'] %} -{% if hostvars[host].datacenter == 'dedicatedsolutions' %} +{% if hostvars[host].datacenter == 'dedicatedsolutions' and hostvars[host].nagios_Check_Services['ping'] == true %} define host { {% if vars['nagios_location'] == 'internal' %} use defaulttemplate diff --git a/roles/nagios_server/templates/nagios/hosts/host1plus-hosts.cfg.j2 b/roles/nagios_server/templates/nagios/hosts/host1plus-hosts.cfg.j2 index 8c80061f0c..da88baf257 100644 --- a/roles/nagios_server/templates/nagios/hosts/host1plus-hosts.cfg.j2 +++ b/roles/nagios_server/templates/nagios/hosts/host1plus-hosts.cfg.j2 @@ -1,5 +1,5 @@ {% for host in groups['all'] %} -{% if hostvars[host].datacenter == 'host1plus' %} +{% if hostvars[host].datacenter == 'host1plus' and hostvars[host].nagios_Check_Services['ping'] == true %} define host { {% if vars['nagios_location'] == 'internal' %} use defaulttemplate diff --git a/roles/nagios_server/templates/nagios/hosts/ibiblio-hosts.cfg.j2 b/roles/nagios_server/templates/nagios/hosts/ibiblio-hosts.cfg.j2 index 2f7c20c3f6..8f4e248852 100644 --- a/roles/nagios_server/templates/nagios/hosts/ibiblio-hosts.cfg.j2 +++ b/roles/nagios_server/templates/nagios/hosts/ibiblio-hosts.cfg.j2 @@ -1,5 +1,5 @@ {% for host in groups['all'] %} -{% if hostvars[host].datacenter == 'ibiblio' %} +{% if hostvars[host].datacenter == 'ibiblio' and hostvars[host].nagios_Check_Services['ping'] == true %} define host { {% if vars['nagios_location'] == 'internal' %} use defaulttemplate diff --git a/roles/nagios_server/templates/nagios/hosts/internetx-hosts.cfg.j2 b/roles/nagios_server/templates/nagios/hosts/internetx-hosts.cfg.j2 index f4edb6c96e..fc3c01d773 100644 --- a/roles/nagios_server/templates/nagios/hosts/internetx-hosts.cfg.j2 +++ b/roles/nagios_server/templates/nagios/hosts/internetx-hosts.cfg.j2 @@ -1,5 +1,5 @@ {% for host in groups['all'] %} -{% if hostvars[host].datacenter == 'internetx' %} +{% if hostvars[host].datacenter == 'internetx' and hostvars[host].nagios_Check_Services['ping'] == true %} define host { {% if vars['nagios_location'] == 'internal' %} use defaulttemplate diff --git a/roles/nagios_server/templates/nagios/hosts/osuosl-hosts.cfg.j2 b/roles/nagios_server/templates/nagios/hosts/osuosl-hosts.cfg.j2 index 1d8b017011..efba7769e9 100644 --- a/roles/nagios_server/templates/nagios/hosts/osuosl-hosts.cfg.j2 +++ b/roles/nagios_server/templates/nagios/hosts/osuosl-hosts.cfg.j2 @@ -1,5 +1,5 @@ {% for host in groups['all'] %} -{% if hostvars[host].datacenter == 'osuosl' %} +{% if hostvars[host].datacenter == 'osuosl' and hostvars[host].nagios_Check_Services['ping'] == true %} define host { {% if vars['nagios_location'] == 'internal' %} use defaulttemplate diff --git a/roles/nagios_server/templates/nagios/hosts/phx2-external.cfg.j2 b/roles/nagios_server/templates/nagios/hosts/phx2-external.cfg.j2 index 9e711cedb4..26cae60da0 100644 --- a/roles/nagios_server/templates/nagios/hosts/phx2-external.cfg.j2 +++ b/roles/nagios_server/templates/nagios/hosts/phx2-external.cfg.j2 @@ -1,4 +1,4 @@ -{% for host in vars["phx2_external"] %} +{% for host in vars["phx2_external"] and hostvars[host].nagios_Check_Services['ping'] == true %} define host { host_name {{ host }} alias {{ host }} diff --git a/roles/nagios_server/templates/nagios/hosts/phx2-hosts.cfg.j2 b/roles/nagios_server/templates/nagios/hosts/phx2-hosts.cfg.j2 index 72e78528d3..986614d8e7 100644 --- a/roles/nagios_server/templates/nagios/hosts/phx2-hosts.cfg.j2 +++ b/roles/nagios_server/templates/nagios/hosts/phx2-hosts.cfg.j2 @@ -1,5 +1,5 @@ {% for host in groups['all'] %} -{% if hostvars[host].datacenter == 'phx2' %} +{% if hostvars[host].datacenter == 'phx2' and hostvars[host].nagios_Check_Services['ping'] == true %} define host { {% if hostvars[host].nagios_Check_Services['nrpe'] == true %} use defaulttemplate diff --git a/roles/nagios_server/templates/nagios/hosts/rdu-cc-hosts.cfg.j2 b/roles/nagios_server/templates/nagios/hosts/rdu-cc-hosts.cfg.j2 index c0cf73d3ce..c8cf518e89 100644 --- a/roles/nagios_server/templates/nagios/hosts/rdu-cc-hosts.cfg.j2 +++ b/roles/nagios_server/templates/nagios/hosts/rdu-cc-hosts.cfg.j2 @@ -1,5 +1,5 @@ {% for host in groups['all'] %} -{% if hostvars[host].datacenter == 'rdu-cc' %} +{% if hostvars[host].datacenter == 'rdu-cc' and hostvars[host].nagios_Check_Services['ping'] == true %} define host { {% if vars['nagios_location'] == 'internal' %} use defaulttemplate diff --git a/roles/nagios_server/templates/nagios/hosts/staging-hosts.cfg.j2 b/roles/nagios_server/templates/nagios/hosts/staging-hosts.cfg.j2 index 168c3d476d..0ffb90320e 100644 --- a/roles/nagios_server/templates/nagios/hosts/staging-hosts.cfg.j2 +++ b/roles/nagios_server/templates/nagios/hosts/staging-hosts.cfg.j2 @@ -1,5 +1,5 @@ {% for host in groups['all'] %} -{% if hostvars[host].datacenter == 'staging' %} +{% if hostvars[host].datacenter == 'staging' and hostvars[host].nagios_Check_Services['ping'] == true %} define host { {% if hostvars[host].nagios_Check_Services['nrpe'] == true %} use defaulttemplate diff --git a/roles/nagios_server/templates/nagios/hosts/tummy-hosts.cfg.j2 b/roles/nagios_server/templates/nagios/hosts/tummy-hosts.cfg.j2 index cc5e6d7067..a374035b8a 100644 --- a/roles/nagios_server/templates/nagios/hosts/tummy-hosts.cfg.j2 +++ b/roles/nagios_server/templates/nagios/hosts/tummy-hosts.cfg.j2 @@ -1,5 +1,5 @@ {% for host in groups['all'] %} -{% if hostvars[host].datacenter == 'tummy' %} +{% if hostvars[host].datacenter == 'tummy' and hostvars[host].nagios_Check_Services['ping'] == true %} define host { {% if vars['nagios_location'] == 'internal' %} use defaulttemplate