2011-06-30 15:15:42 +02:00
|
|
|
#!/bin/sh
|
|
|
|
TMP=`mktemp`
|
|
|
|
LAST_HOUR=`date "+%b %e %H:" -d "1 hour ago"`
|
|
|
|
CURRENT_HOUR=`date "+%b %e %H:"`
|
|
|
|
|
2013-05-22 23:23:50 +02:00
|
|
|
exit_unknown() {
|
|
|
|
msg="$1"
|
|
|
|
|
|
|
|
echo "${msg}"
|
|
|
|
exit 3
|
|
|
|
}
|
|
|
|
|
|
|
|
find_nagios_log() {
|
|
|
|
# Try to locate the nagios log, fallback to messages log
|
|
|
|
for log in /var/log/nagios/nagios.log /var/log/nagios3/nagios.log /var/log/messages
|
|
|
|
do
|
|
|
|
if [ -e "${log}" ]; then
|
|
|
|
echo ${log}
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return 3
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG=$(find_nagios_log) || exit_unknown "Unable to locate logfile for parsing"
|
|
|
|
|
|
|
|
tail -n 1 ${LOG} &> ${TMP} || exit_unknown "Unable to parse logfile: $(cat ${TMP})"
|
|
|
|
tail -n 2000 ${LOG} | \
|
2011-06-30 15:15:42 +02:00
|
|
|
grep -E "$CURRENT_HOUR|$LAST_HOUR" | \
|
|
|
|
grep "Passive check result was received" | \
|
|
|
|
grep -i "could not be found" | \
|
|
|
|
sed 's/.*Passive check result was received for service //' | \
|
|
|
|
sed 's/, but the host could not be found.*//' | \
|
|
|
|
sort | uniq > $TMP
|
|
|
|
|
|
|
|
|
|
|
|
LINES=`cat $TMP | wc -l`
|
2011-10-24 19:21:17 +02:00
|
|
|
PERFDATA="'ghost_services'=$LINES"
|
2011-06-30 15:15:42 +02:00
|
|
|
if [ $LINES -gt 0 ]; then
|
2011-10-24 19:21:17 +02:00
|
|
|
echo "$LINES ghost services found in Nagios log files | $PERFDATA"
|
2011-06-30 15:15:42 +02:00
|
|
|
echo ""
|
|
|
|
cat $TMP
|
|
|
|
rm -f $TMP
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-10-24 19:21:17 +02:00
|
|
|
echo "No ghost services found in Nagios log files | $PERFDATA"
|
2011-06-30 15:15:42 +02:00
|
|
|
rm -f $TMP
|
|
|
|
exit 0
|
|
|
|
|