diff --git a/check_nagios/check_nagios_configuration b/check_nagios/check_nagios_configuration new file mode 100755 index 0000000..3e7ef74 --- /dev/null +++ b/check_nagios/check_nagios_configuration @@ -0,0 +1,38 @@ +#!/bin/sh + + +PERFDATA="" +MESSAGE="Nagios configuration is valid" +EXIT_CODE=3 + +TMPFILE=`mktemp` +nagios -v /etc/nagios/nagios.cfg > $TMPFILE +RESULT=$? + +# grep -E '^\s+Checked' +warnings=`grep -c -E "^Warning:" "$TMPFILE"` +errors=`grep -c -E "^Error:" "$TMPFILE"` +PERFDATA="warnings=$warnings errors=$errors" + + +# If there are any warnings +if [ $warnings -gt 0 ]; then + MESSAGE="nagios.cfg has $warnings warnings" + EXIT_CODE=1 +fi + + +# If nagios -v fails. Config is invalid +if [ $RESULT -gt 0 ]; then + MESSAGE="Could not validate Nagios configuration." + EXIT_CODE=2 +fi + +if [ $EXIT_CODE -eq "3" ]; then + EXIT_CODE=0 +fi + +echo "$MESSAGE | $PERFDATA" +grep -E "^Error|^Warning" "$TMPFILE" +rm -f TMPFILE +exit $EXIT_CODE diff --git a/misc/check_nagios_ghostservices b/check_nagios/check_nagios_ghostservices old mode 100644 new mode 100755 similarity index 75% rename from misc/check_nagios_ghostservices rename to check_nagios/check_nagios_ghostservices index 11e7e18..f1a67cb --- a/misc/check_nagios_ghostservices +++ b/check_nagios/check_nagios_ghostservices @@ -13,16 +13,16 @@ sort | uniq > $TMP LINES=`cat $TMP | wc -l` -PERFDATA="'ghost_clients'=$LINES" +PERFDATA="'ghost_services'=$LINES" if [ $LINES -gt 0 ]; then - echo "$LINES ghost clients found in Nagios log files | $PERFDATA" + echo "$LINES ghost services found in Nagios log files | $PERFDATA" echo "" cat $TMP rm -f $TMP exit 1 fi -echo "No ghost clients found in Nagios log files | $PERFDATA" +echo "No ghost services found in Nagios log files | $PERFDATA" rm -f $TMP exit 0 diff --git a/check_nagios/nrpe.d/check_nagios.cfg b/check_nagios/nrpe.d/check_nagios.cfg new file mode 100644 index 0000000..39ce1d1 --- /dev/null +++ b/check_nagios/nrpe.d/check_nagios.cfg @@ -0,0 +1,2 @@ +command[check_nagios_configuration]=/usr/lib64/nagios/plugins/check_nagios_configuration +command[check_nagios_ghostservices]=/usr/lib64/nagios/plugins/check_nagios_ghostservices