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/check_nagios_needs_reload b/check_nagios/check_nagios_needs_reload new file mode 100755 index 0000000..b239e59 --- /dev/null +++ b/check_nagios/check_nagios_needs_reload @@ -0,0 +1,20 @@ +#!/usr/bin/python +# Checks if nagios service needs a reload + +import sys +try: + from pynag.Parsers import config + + c = config(cfg_file='/etc/nagios/nagios.cfg') + c.parse() + result = c.needs_reparse() + + if result == True: + print "Warning - Nagios configuration has changed since last restart" + sys.exit(1) + else: + print "OK - Nagios service has been restarted since last config change" + sys.exit(0) +except Exception, e: + print "Unknown - Error running script: %s" % e + sys.exit(3) diff --git a/check_nagios/check_nagios_plugin_existance b/check_nagios/check_nagios_plugin_existance new file mode 100755 index 0000000..5281aa2 --- /dev/null +++ b/check_nagios/check_nagios_plugin_existance @@ -0,0 +1,10 @@ +#!/usr/bin/python + +import sys,os +sys.path.append('/opt/pynag') +from pynag import Model + +all_commands = Model.Command.objects.all +for c in all_commands: + print c.command_line + diff --git a/check_nagios/nrpe.d/check_nagios.cfg b/check_nagios/nrpe.d/check_nagios.cfg new file mode 100644 index 0000000..cd1860f --- /dev/null +++ b/check_nagios/nrpe.d/check_nagios.cfg @@ -0,0 +1,4 @@ +command[check_nagios_configuration]=/usr/lib64/nagios/plugins/check_nagios_configuration +command[check_nagios_ghostservices]=/usr/lib64/nagios/plugins/check_nagios_ghostservices +command[check_nagios_needs_reload]=/usr/lib64/nagios/plugins/check_nagios_needs_reload +command[check_nagios_plugin_existance]=/usr/lib64/nagios/plugins/check_nagios_plugin_existance diff --git a/check_proc/check_procs.sh b/check_proc/check_procs.sh new file mode 100755 index 0000000..4dc3a8b --- /dev/null +++ b/check_proc/check_procs.sh @@ -0,0 +1,6 @@ +#!/bin/bash +LINE=`/usr/lib64/nagios/plugins/check_procs $*` +RC=$? +COUNT=`echo $LINE | awk '{print $3}'` +echo $LINE \| procs=$COUNT +exit $RC diff --git a/check_yum/trunk/check_yum b/check_yum/trunk/check_yum index b54b90b..32da255 100755 --- a/check_yum/trunk/check_yum +++ b/check_yum/trunk/check_yum @@ -6,7 +6,11 @@ __author__ = "Hari Sekhon" __title__ = "Nagios Plugin for Yum updates on RedHat/CentOS systems" -__version__ = "0.7.1" +__version__ = "0.7.2" + +# Changes: +# 0.7.2 added support for rhel6-style yum output + # Standard Nagios return codes OK = 0 @@ -29,19 +33,19 @@ from optparse import OptionParser DEFAULT_TIMEOUT = 30 -def end(status, message): +def end(status, message, perfdata=''): """Exits the plugin with first arg as the return code and the second arg as the message to output""" check = "YUM " if status == OK: - print "%sOK: %s" % (check, message) + print "%sOK: %s | %s" % (check, message, perfdata) sys.exit(OK) elif status == WARNING: - print "%sWARNING: %s" % (check, message) + print "%sWARNING: %s | %s" % (check, message, perfdata) sys.exit(WARNING) elif status == CRITICAL: - print "%sCRITICAL: %s" % (check, message) + print "%sCRITICAL: %s | %s" % (check, message, perfdata) sys.exit(CRITICAL) else: print "UNKNOWN: %s" % message @@ -316,23 +320,33 @@ class YumTester: cmd = "%s --security check-update" % YUM output = self.run(cmd) - - re_security_summary = \ - re.compile("Needed \d+ of \d+ packages, for security") - re_no_security_updates_available = \ - re.compile("No packages needed, for security, \d+ available") + + re_security_summary_rhel5 = re.compile("Needed \d+ of \d+ packages, for security") + re_security_summary_rhel6 = re.compile("\d+ package\(s\) needed for security, out of \d+ available") + re_no_security_updates_available_rhel5 = re.compile("No packages needed, for security, \d+ available") + re_no_security_updates_available_rhel6 = re.compile("No packages needed for security; \d+ packages available") summary_line_found = False for line in output: - if re_no_security_updates_available.match(line): + if re_no_security_updates_available_rhel5.match(line): summary_line_found = True number_security_updates = 0 number_total_updates = line.split()[5] break - elif re_security_summary.match(line): + if re_no_security_updates_available_rhel6.match(line): + summary_line_found = True + number_security_updates = 0 + number_total_updates = line.split()[5] + break + if re_security_summary_rhel5.match(line): summary_line_found = True number_security_updates = line.split()[1] number_total_updates = line.split()[3] break + if re_security_summary_rhel6.match(line): + summary_line_found = True + number_security_updates = line.split()[0] + number_total_updates = line.split()[7] + break if not summary_line_found: end(WARNING, "Cannot find summary line in yum output. Please " \ diff --git a/check_yum/trunk/nagios-okplugin-check_yum.spec b/check_yum/trunk/nagios-okplugin-check_yum.spec index 817f04c..f497159 100644 --- a/check_yum/trunk/nagios-okplugin-check_yum.spec +++ b/check_yum/trunk/nagios-okplugin-check_yum.spec @@ -2,8 +2,8 @@ Summary: Nagios plugin to test for Yum updates on RedHat/CentOS Linux. Name: nagios-okplugin-check_yum -Version: 0.7.1 -Release: 1%{?dist} +Version: 0.7.2 +Release: 2%{?dist} License: GPLv2+ Group: Applications/System URL: http://opensource.is/trac/wiki/check_yum