diff --git a/smartgears/resource_checker_se_plugin/defaults/main.yml b/smartgears/resource_checker_se_plugin/defaults/main.yml index 8ecfb6ab..0de08bfa 100644 --- a/smartgears/resource_checker_se_plugin/defaults/main.yml +++ b/smartgears/resource_checker_se_plugin/defaults/main.yml @@ -8,3 +8,5 @@ resource_checker_se_plugin_name: 'resource-checker-se-plugin' resource_checker_se_plugin_extension: 'jar' resource_checker_se_plugin_classifier: 'jar-with-dependencies' resource_checker_se_plugin_file: '{{ resource_checker_se_plugin_name }}-{{ resource_checker_se_plugin_version }}-jar-with-dependencies.{{ resource_checker_se_plugin_extension }}' + +resource_checker_nagios_nrpe: True diff --git a/smartgears/resource_checker_se_plugin/tasks/main.yml b/smartgears/resource_checker_se_plugin/tasks/main.yml index 4282354b..629c87e2 100644 --- a/smartgears/resource_checker_se_plugin/tasks/main.yml +++ b/smartgears/resource_checker_se_plugin/tasks/main.yml @@ -12,3 +12,16 @@ become_user: '{{ smartgears_user }}' when: resource_checker_se_plugin_install tags: [ 'smartgears', 'resource_checker_se', 'tomcat' ] + +- block: + - name: Install the resource checker nagios check + template: src=check_missing_resources.sh.j2 dest={{ nagios_plugdir | default('/usr/lib/nagios/plugins') }}/check_missing_resources mode=0755 + + - name: Install the nrpe job to run the check + template: src=resource_checker_nrpe.cfg.j2 dest=/etc/nagios/nrpe.d/resource_checker_nrpe.cfg owner=root group=root mode=0444 + notify: Reload NRPE server + + become: False + when: resource_checker_se_plugin_install and resource_checker_nagios_nrpe + tags: [ 'smartgears', 'resource_checker_se', 'nagios' ] + diff --git a/smartgears/resource_checker_se_plugin/templates/check_missing_resources.sh.j2 b/smartgears/resource_checker_se_plugin/templates/check_missing_resources.sh.j2 new file mode 100644 index 00000000..2481e020 --- /dev/null +++ b/smartgears/resource_checker_se_plugin/templates/check_missing_resources.sh.j2 @@ -0,0 +1,26 @@ +#!/bin/bash + +COMMON_SH_LIB={{ nagios_isti_plugdir }}/check_library.sh +RESOURCES_STATUS_FILE={{ smartgears_user_home }}/missing_resources/identifiers + +if [ -f $COMMON_SH_LIB ] ; then + . $COMMON_SH_LIB +else + echo "UNKNOWN - Library file $COMMON_SH_LIB does not exist" + exit $NAGIOS_UNKNOWN +fi + +if [ ! -f $RESOURCES_STATUS_FILE ] ; then + echo "UNKNOWN - File $RESOURCES_STATUS_FILE does not exist" + exit $NAGIOS_UNKNOWN +fi + +RESOURCES_DATA=$( cat $RESOURCES_STATUS_FILE ) +if [ "$RESOURCES_DATA" == "none" ] ; then + echo "OK - No resources are missing" + exit $NAGIOS_OK +else + echo "CRITICAL - Missing resources: $RESOURCES_DATA" + exit $NAGIOS_CRITICAL +fi + diff --git a/smartgears/resource_checker_se_plugin/templates/resource_checker_nrpe.cfg.j2 b/smartgears/resource_checker_se_plugin/templates/resource_checker_nrpe.cfg.j2 new file mode 100644 index 00000000..97f77a5e --- /dev/null +++ b/smartgears/resource_checker_se_plugin/templates/resource_checker_nrpe.cfg.j2 @@ -0,0 +1,2 @@ +command[nrpe_resource_checker]={{ nagios_plugdir | default('/usr/lib/nagios/plugins') }}/check_missing_resources +