diff --git a/tomcat-instance/tasks/main.yml b/tomcat-instance/tasks/main.yml index 836443da..65070a02 100644 --- a/tomcat-instance/tasks/main.yml +++ b/tomcat-instance/tasks/main.yml @@ -4,6 +4,7 @@ register: tomcat_instance_stat - include: tomcat.yml +- include: nagios.yml - include: check.yml - include: user.yml - include: systemd.yml diff --git a/tomcat-instance/tasks/nagios.yml b/tomcat-instance/tasks/nagios.yml new file mode 100644 index 00000000..805e4e77 --- /dev/null +++ b/tomcat-instance/tasks/nagios.yml @@ -0,0 +1,20 @@ +--- +- name: Intall monitorings plugins + apt: + name: monitoring-plugins + state: present + +- name: Mount /usr in rw + command: mount -o remount,rw /usr warn=no + changed_when: False + +- name: Create Nagios plugins dir + file: + path: '/usr/local/lib/nagios/plugins' + state: directory + +- name: Copy Tomcat instance check + template: + src: 'templates/check_tomcat_instance.sh.j2' + dest: '/usr/local/lib/nagios/plugins/check_tomcat_instance.sh' + mode: 0755 diff --git a/tomcat-instance/templates/check_tomcat_instance.sh.j2 b/tomcat-instance/templates/check_tomcat_instance.sh.j2 new file mode 100644 index 00000000..8ed63475 --- /dev/null +++ b/tomcat-instance/templates/check_tomcat_instance.sh.j2 @@ -0,0 +1,18 @@ +#!/bin/bash + +TOMCAT_ROOT='{{ tomcat_instance_root }}' +alert=0 + +for instance in $(ls $TOMCAT_ROOT); do + port=$(id -u $instance) + if [ -h ${TOMCAT_ROOT}/${instance}/.config/systemd/user/default.target.wants/tomcat.service ]; then + echo -n "$instance ($port) : " + /usr/lib/nagios/plugins/check_tcp -p $port + ret=$? + if [ $ret != 0 ]; then + alert=$ret + fi + fi +done + +exit $alert