From 1f889969f132532780bc461403f7c156d6dc3bd8 Mon Sep 17 00:00:00 2001 From: Stephen Smoogen Date: Tue, 10 Jan 2017 01:02:05 +0000 Subject: [PATCH] ok this should just make staging have a few test hosts --- .../nagios/services-staging/templates.cfg | 200 ++++++++++++++++++ roles/nagios_server/tasks/main.yml | 32 ++- .../templates/nagios/hostgroups/all.cfg.j2 | 17 +- .../templates/nagios/hosts/phx2-hosts.cfg.j2 | 32 +++ 4 files changed, 273 insertions(+), 8 deletions(-) create mode 100644 roles/nagios_server/files/nagios/services-staging/templates.cfg diff --git a/roles/nagios_server/files/nagios/services-staging/templates.cfg b/roles/nagios_server/files/nagios/services-staging/templates.cfg new file mode 100644 index 0000000000..eb220aaa83 --- /dev/null +++ b/roles/nagios_server/files/nagios/services-staging/templates.cfg @@ -0,0 +1,200 @@ +############################################################################### +############################################################################### +# +# SERVICE TEMPLATES +# +############################################################################### +############################################################################### + +# Generic service definition template - This is NOT a real service, just a template! + +define service{ + name generic-service ; The 'name' of this service template + active_checks_enabled 1 ; Active service checks are enabled + passive_checks_enabled 1 ; Passive service checks are enabled/accepted + parallelize_check 1 ; Active service checks should be parallelized (disabling this can lead to major performance problems) + obsess_over_service 1 ; We should obsess over this service (if necessary) + check_freshness 0 ; Default is to NOT check service 'freshness' + notifications_enabled 1 ; Service notifications are enabled + event_handler_enabled 1 ; Service event handler is enabled + flap_detection_enabled 1 ; Flap detection is enabled + process_perf_data 1 ; Process performance data + retain_status_information 1 ; Retain status information across program restarts + retain_nonstatus_information 1 ; Retain non-status information across program restarts + is_volatile 0 ; The service is not volatile + check_period 24x7 ; The service can be checked at any time of the day + max_check_attempts 3 ; Re-check the service up to 3 times in order to determine its final (hard) state + normal_check_interval 10 ; Check the service every 10 minutes under normal conditions + retry_check_interval 2 ; Re-check the service every two minutes until a hard state can be determined + contact_groups admins ; Notifications get sent out to everyone in the 'admins' group + notification_options w,u,c,r ; Send notifications about warning, unknown, critical, and recovery events + notification_interval 60 ; Re-notify about service problems every hour + notification_period 24x7 ; Notifications can be sent out at any time + register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE! + } + + +# Local service definition template - This is NOT a real service, just a template! + +define service{ + name local-service ; The name of this service template + use generic-service ; Inherit default values from the generic-service definition + max_check_attempts 4 ; Re-check the service up to 4 times in order to determine its final (hard) state + normal_check_interval 5 ; Check the service every 5 minutes under normal conditions + retry_check_interval 1 ; Re-check the service every minute until a hard state can be determined + register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE! + } + + + +define service { + name criticaltemplate + max_check_attempts 4 + normal_check_interval 5 + retry_check_interval 1 + check_period 24x7 + notification_interval 15 + notification_period 24x7 + notification_options w,u,c,r + contact_groups fedora-sysadmin-ircbot + + register 0 +} + + +define service { + name defaulttemplate + max_check_attempts 3 + normal_check_interval 10 + retry_check_interval 1 + check_period 24x7 + notification_interval 15 + notification_period 24x7 + notification_options w,u,c,r + contact_groups fedora-sysadmin-ircbot + + register 0 +} + +define service { + name disktemplate + max_check_attempts 3 + normal_check_interval 30 + retry_check_interval 1 + check_period 24x7 + notification_interval 40 + notification_period 24x7 + notification_options w,u,c,r + contact_groups fedora-sysadmin-ircbot + + register 0 +} + +define service { + name builderdisktemplate + max_check_attempts 12 + normal_check_interval 30 + retry_check_interval 1 + check_period 24x7 + notification_interval 40 + notification_period 24x7 + notification_options w,u,c,r + contact_groups fedora-sysadmin-ircbot + + register 0 +} + +define service { + name lighttemplate + max_check_attempts 3 + normal_check_interval 480 + retry_check_interval 5 + check_period 16x7 + notification_interval 490 + notification_period 16x7 + notification_options w,u,c,r + contact_groups fedora-sysadmin-ircbot + + register 0 +} + +define service { + name websitetemplate + max_check_attempts 3 + normal_check_interval 5 + retry_check_interval 1 + check_period 24x7 + notification_interval 15 + notification_period 24x7 + notification_options w,u,c,r + contact_groups fedora-sysadmin-ircbot + + register 0 +} + +define service { + name internalwebsitetemplate + max_check_attempts 3 + normal_check_interval 5 + retry_check_interval 1 + check_period 24x7 + notification_interval 15 + notification_period 24x7 + notification_options w,u,c,r + contact_groups fedora-sysadmin-ircbot + + register 0 +} + + define service { + use defaulttemplate + name passivetemplate + active_checks_enabled 0 + passive_checks_enabled 1 + check_command check_dummy!0 + check_period 24x7 + check_freshness 0 + register 0 +} + +#define service { +# name autoqatemplate +# max_check_attempts 3 +# normal_check_interval 10 +# retry_check_interval 1 +# check_period 24x7 +# notification_interval 360 +# notification_period 24x7 +# notification_options w,u,c,r +# contact_groups sysadmin-qa-email +# +# register 0 +#} + +define service { + name ppc-secondarytemplate + max_check_attempts 3 + normal_check_interval 10 + retry_check_interval 1 + check_period 24x7 + notification_interval 15 + notification_period 24x7 + notification_options w,u,c,r + contact_groups fedora-sysadmin-ircbot + + register 0 +} + +define service { + name retracetemplate + max_check_attempts 3 + normal_check_interval 10 + retry_check_interval 1 + check_period 24x7 + notification_interval 15 + notification_period 24x7 + notification_options w,u,c,r + contact_groups fedora-sysadmin-ircbot + + register 0 +} diff --git a/roles/nagios_server/tasks/main.yml b/roles/nagios_server/tasks/main.yml index 97f9eabf0a..8be774d369 100644 --- a/roles/nagios_server/tasks/main.yml +++ b/roles/nagios_server/tasks/main.yml @@ -79,13 +79,13 @@ ## Copy over system configs # TODO: Make this a template once they're closer together -- name: Copy httpd config +- name: Copy httpd config (production) copy: src=httpd/nagios.conf dest=/etc/httpd/conf.d/nagios.conf when: env == "production" tags: - nagios_server -- name: Copy httpd config +- name: Copy httpd config (staging) copy: src=httpd/nagios-new.conf dest=/etc/httpd/conf.d/nagios.conf when: env == "staging" tags: @@ -149,11 +149,21 @@ notify: restart nagios ## Copy over the services -- name: Copy /etc/nagios/services +- name: Copy /etc/nagios/services (production) synchronize: src=nagios/services/ dest=/etc/nagios/services/ tags: - nagios-config - nagios_server + when: env == "production" + notify: restart nagios + +## Copy over the services +- name: Copy /etc/nagios/services (staging) + synchronize: src=nagios/services-staging/ dest=/etc/nagios/services/ + tags: + - nagios-config + - nagios_server + when: env == "staging" notify: restart nagios ## Copy over the servicegroups @@ -194,7 +204,7 @@ tags: - nagios_server -- name: Build out nagios host templates +- name: Build out nagios host templates (production) template: src=nagios/hosts/{{item}}.j2 dest=/etc/nagios/hosts/{{item}} mode=0644 owner=root group=root with_items: - bodhost-hosts.cfg @@ -211,6 +221,17 @@ - rdu-cc-hosts.cfg - rdu-hosts.cfg - tummy-hosts.cfg + when: env == "production" + tags: + - nagios_server + +- name: Build out nagios host templates (staging) + template: src=nagios/hosts/{{item}}.j2 dest=/etc/nagios/hosts/{{item}} mode=0644 owner=root group=root + with_items: + - phx2-hosts.cfg + - staging-hosts.cfg + - phx2-mgmt-hosts.cfg + when: env == "staging" tags: - nagios_server @@ -234,9 +255,6 @@ # - mgmt-http.cfg # - mirrorlist.cfg # - retrace.cfg - -## -## not implemented yet # - zanata2fedmsg.cfg tags: - nagios_server diff --git a/roles/nagios_server/templates/nagios/hostgroups/all.cfg.j2 b/roles/nagios_server/templates/nagios/hostgroups/all.cfg.j2 index c8a282b292..fc14fe6db9 100644 --- a/roles/nagios_server/templates/nagios/hostgroups/all.cfg.j2 +++ b/roles/nagios_server/templates/nagios/hostgroups/all.cfg.j2 @@ -3,6 +3,17 @@ ############### {% for key, value in groups.iteritems() %} +{% if env == "staging" %} +{% if groups[key] %} +define hostgroup{ + hostgroup_name {{ key }} + alias {{ key }} + members {% for host in groups[key] %}{% if hostvars[host].env == 'staging' %}{{host}}, {% endif %}{% endfor %} + +} + +{% endif %} +{% else %} {% if groups[key] %} define hostgroup{ hostgroup_name {{ key }} @@ -10,7 +21,9 @@ define hostgroup{ members {% for host in groups[key] %}{{host}}, {% endfor %} } -{% endif %} + + +{$ endif %} {% endfor %} define hostgroup { @@ -20,9 +33,11 @@ define hostgroup { } +{% if env != "staging" %} define hostgroup { hostgroup_name vpnclients alias vpnclients members {% for host in groups['all'] %}{% if hostvars[host].vpn %}{{host}},{% endif %} {% endfor %} } +{% endif %} 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 cdd6ad04d9..d6acb55426 100644 --- a/roles/nagios_server/templates/nagios/hosts/phx2-hosts.cfg.j2 +++ b/roles/nagios_server/templates/nagios/hosts/phx2-hosts.cfg.j2 @@ -1,3 +1,33 @@ +{% if env == "staging" %} +{% for host in groups['all'] %} +{% if hostvars[host].datacenter == 'phx2' and hostvars[host].env == 'staging' %} +define host { + use defaulttemplate + host_name {{ host }} +{% if hostvars[host].ansible_hostname is defined %} + alias {{ hostvars[host].ansible_hostname }} +{% else %} + alias {{ host }} +{% endif %} +{% if hostvars[host].eth0_ip is defined %} + address {{ hostvars[host].eth0_ip }} +{% elif hostvars[host].ansible_default_ipv4 is defined %} +{% if hostvars[host].ansible_default_ipv4.address is defined %} + address {{ hostvars[host].ansible_default_ipv4.address }} +{% endif %} +{% else %} + address {{ host }} +{% endif %} +{% if hostvars[host]['vmhost'] is defined %} + parents {{ hostvars[host]['vmhost'] }} +{% elif hostvars[host].datacenter is defined %} + parents phx2-gw +{% endif %} +} + +{% endif %} +{% endfor %} +{% else %} {% for host in groups['all'] %} {% if hostvars[host].datacenter == 'phx2' %} define host { @@ -23,5 +53,7 @@ define host { parents phx2-gw {% endif %} } + {% endif %} {% endfor %} +{% endif %}