From 911c331ee9889897c041804693e21998a701f771 Mon Sep 17 00:00:00 2001 From: Chris Hines <chris.hines@monash.edu> Date: Mon, 2 May 2016 03:33:05 +0000 Subject: [PATCH] updates to the nagios_config role to facilitate a shared nagios server --- roles/apache2/tasks/apacheDebian.yml | 4 -- roles/apache2/tasks/main.yml | 8 ++++ roles/nagios_config/files/commands.cfg | 52 ++++++++++++++++++++++++++ roles/nagios_config/tasks/main.yml | 13 +++++-- 4 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 roles/nagios_config/files/commands.cfg diff --git a/roles/apache2/tasks/apacheDebian.yml b/roles/apache2/tasks/apacheDebian.yml index acfada37..b62913c6 100644 --- a/roles/apache2/tasks/apacheDebian.yml +++ b/roles/apache2/tasks/apacheDebian.yml @@ -27,8 +27,4 @@ sudo: true notify: restart apache2 -- - name: "Starting Apache2" - service: name=apache2 state=started enabled=yes - sudo: true diff --git a/roles/apache2/tasks/main.yml b/roles/apache2/tasks/main.yml index 0783dadd..f09076e6 100644 --- a/roles/apache2/tasks/main.yml +++ b/roles/apache2/tasks/main.yml @@ -30,3 +30,11 @@ name: "Change permissions for /var/www" file: path=/var/www state=directory owner=root group={{ apache_user }} mode=0775 sudo: true + +- + name: "Starting Apache2" + service: name=apache2 state=started enabled=yes + sudo: true + when: ansible_os_family=="Debian" + + diff --git a/roles/nagios_config/files/commands.cfg b/roles/nagios_config/files/commands.cfg new file mode 100644 index 00000000..a32097f0 --- /dev/null +++ b/roles/nagios_config/files/commands.cfg @@ -0,0 +1,52 @@ +############################################################################### +# COMMANDS.CFG - SAMPLE COMMAND DEFINITIONS FOR NAGIOS +############################################################################### + + +################################################################################ +# NOTIFICATION COMMANDS +################################################################################ + + +# 'notify-host-by-email' command definition +define command{ + command_name notify-host-by-email + command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$ + } + +# 'notify-service-by-email' command definition +#define command{ +# command_name notify-service-by-email +# command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ +# } + + + + + +################################################################################ +# HOST CHECK COMMANDS +################################################################################ + +# On Debian, check-host-alive is being defined from within the +# nagios-plugins-basic package + +################################################################################ +# PERFORMANCE DATA COMMANDS +################################################################################ + + +# 'process-host-perfdata' command definition +define command{ + command_name process-host-perfdata + command_line /usr/bin/printf "%b" "$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HOSTATTEMPT$\t$HOSTSTATETYPE$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$\n" >> /var/lib/nagios3/host-perfdata.out + } + + +# 'process-service-perfdata' command definition +define command{ + command_name process-service-perfdata + command_line /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" >> /var/lib/nagios3/service-perfdata.out + } + + diff --git a/roles/nagios_config/tasks/main.yml b/roles/nagios_config/tasks/main.yml index c99e088a..2743e363 100644 --- a/roles/nagios_config/tasks/main.yml +++ b/roles/nagios_config/tasks/main.yml @@ -1,6 +1,6 @@ --- - name: configure monitoring - template: src={{ item }}_nagios2.cfg.j2 dest=/etc/nagios3/conf.d/{{ item }}_nagios2.cfg + copy: src={{ item }}_nagios2.cfg dest=/etc/nagios3/conf.d/{{ item }}_nagios2.cfg with_items: - 'hostgroups' - 'hosts' @@ -8,19 +8,26 @@ - 'services' - 'contactgroup' - 'contacts' + - 'generic-host' + - 'generic-service' sudo: true - name: remove unwanted configure files - file: path={{ item }}_nagios2.cfg.j2 state=absent + file: path=/etc/nagios3/conf.d/{{ item }}_nagios2.cfg state=absent with_items: - 'localhost' - 'extinfo' sudo: true - name: change cgi config - template: src=cgi.cfg.j2 dest=/etc/nagios3/cgi.cfg + copy: src=cgi.cfg dest=/etc/nagios3/cgi.cfg sudo: true +- name: change the default email command + copy: src=commands.cfg dest=/etc/nagios3/commands.cfg + become: true + become_user: root + - name: nagios restart service: name=nagios3 state=restarted sudo: true -- GitLab