From 3828a94a3e765c1457b9b7d0de766e41b4dbbb49 Mon Sep 17 00:00:00 2001 From: Tomas Edwardsson Date: Wed, 22 May 2013 21:23:50 +0000 Subject: [PATCH] Emit unknown if unable to open the logfile and detect location Issue #1 --- check_nagios/check_nagios_ghostservices | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/check_nagios/check_nagios_ghostservices b/check_nagios/check_nagios_ghostservices index f1a67cb..4e2352e 100755 --- a/check_nagios/check_nagios_ghostservices +++ b/check_nagios/check_nagios_ghostservices @@ -3,7 +3,29 @@ TMP=`mktemp` LAST_HOUR=`date "+%b %e %H:" -d "1 hour ago"` CURRENT_HOUR=`date "+%b %e %H:"` -tail -n 2000 /var/log/messages | \ +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} | \ grep -E "$CURRENT_HOUR|$LAST_HOUR" | \ grep "Passive check result was received" | \ grep -i "could not be found" | \