Page 1 of 1

Passive checks by cron

Posted: Fri Jan 07, 2011 1:25 pm
by Kazak
Hi to everyone, sorry for my english.

I have couple servers running on FreeBSD 8x monitored by Nagios+nsca, and now I'm trying to configure passive checks for some of my services. Everything is ok when I'm running my scripts "manualy"- Nagios detects it and reacts properly, but when I'm trying to run my script by cron Nagios shows no reaction on it .

I'm a newbie in this part of "nagios crafting" so I tried to make my script primitive as possible - almost everything is hardcoded, all procedures are primitive, and so on.
Script runs a "check_hdd_health" plugin (downloaded from http://exchange.nagios.org/) and then "printf" forms output in a such way:

Code: Select all

gateway# printf "%s\t%s\t%d\t%s\n" "localhost" "ad2_health" "0" "TEST"
localhost       ad2_health      0       TEST (... I hope it's correct)
Script:

Code: Select all

#!/bin/sh
#ad2 health checker
WMSG="/usr/local/etc/scripts/ad2stats"
RMSG=`cat  /usr/local/etc/scripts/ad2stats`
W_AD2="/usr/local/etc/scripts/ad2state"
R_AD2=`cat /usr/local/etc/scripts/ad2state`

/usr/local/libexec/nagios/check_hdd_health -d /dev/ad2 > ${WMSG}
cat /usr/local/etc/scripts/ad2stats | grep "OK" > /dev/null 2>&1 && echo "0" > ${W_AD2}
cat /usr/local/etc/scripts/ad2stats | grep "WARNING"  > /dev/null 2>&1 && echo "1" > ${W_AD2}
cat /usr/local/etc/scripts/ad2stats | grep "CRITICAL" > /dev/null 2>&1 && echo "2" > ${W_AD2}
cat /usr/local/etc/scripts/ad2stats | grep "UNKNOWN"  > /dev/null 2>&1&& echo "3" > ${W_AD2}

printf "%s\t%s\t%d\t%s\n" "localhost" "ad2_health" "$R_AD2"  "${RMSG}" | send_nsca -H 192.168.0.1 -c /usr/local/etc/nagios/send_nsca.cfg

exit
My Crontab:

Code: Select all

#AD2 health checker
*/1      *       *       *       *       root   /usr/local/etc/scripts/ad2health.sh 2>&1 > /dev/null 
I'll be thankfull for any help,
best regards Kazak