2011-10-24 19:21:17 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
|
|
PERFDATA=""
|
|
|
|
MESSAGE="Nagios configuration is valid"
|
|
|
|
EXIT_CODE=3
|
|
|
|
|
|
|
|
TMPFILE=`mktemp`
|
2012-03-04 17:22:37 +01:00
|
|
|
trap "rm -f $TMPFILE" EXIT
|
2011-10-24 19:21:17 +02:00
|
|
|
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"
|
2013-04-19 13:15:59 +02:00
|
|
|
rm -f $TMPFILE
|
2011-10-24 19:21:17 +02:00
|
|
|
exit $EXIT_CODE
|