1
0
mirror of https://github.com/opinkerfi/nagios-plugins.git synced 2024-11-05 01:53:44 +01:00

Modified to parse on epoch rather that syslog date

Issue #1
This commit is contained in:
Tomas Edwardsson 2013-05-22 22:41:03 +00:00
parent 3828a94a3e
commit 9840c23642

View File

@ -1,7 +1,6 @@
#!/bin/sh #!/bin/sh
TMP=`mktemp` TMP=`mktemp`
LAST_HOUR=`date "+%b %e %H:" -d "1 hour ago"` EPOCH_HOUR_AGO=$(( $(date +%s) - 3600 ))
CURRENT_HOUR=`date "+%b %e %H:"`
exit_unknown() { exit_unknown() {
msg="$1" msg="$1"
@ -12,7 +11,8 @@ exit_unknown() {
find_nagios_log() { find_nagios_log() {
# Try to locate the nagios log, fallback to messages 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 for log in /var/log/nagios/nagios.log /var/log/nagios3/nagios.log /var/spool/nagios/nagios.log \
/usr/local/nagios/var/nagios.log
do do
if [ -e "${log}" ]; then if [ -e "${log}" ]; then
echo ${log} echo ${log}
@ -26,7 +26,7 @@ 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 1 ${LOG} &> ${TMP} || exit_unknown "Unable to parse logfile: $(cat ${TMP})"
tail -n 2000 ${LOG} | \ tail -n 2000 ${LOG} | \
grep -E "$CURRENT_HOUR|$LAST_HOUR" | \ awk "BEGIN { FS=\"[\\\\[\\\\]]\" } \$2 > ${EPOCH_HOUR_AGO} {print \$0}" | \
grep "Passive check result was received" | \ grep "Passive check result was received" | \
grep -i "could not be found" | \ grep -i "could not be found" | \
sed 's/.*Passive check result was received for service //' | \ sed 's/.*Passive check result was received for service //' | \