[Nagiosplug-help] Calling PERL script from within a BASH Plug-in

Russ Nealis russ.nealis at highwinds.com
Fri Jul 13 21:45:50 CEST 2007


Hi Guys,

I wrote a very basic plug-in to grep through my syslog. Instead of 
parsing my entire syslog, which can get up to 1 gig, I only grep through 
at least the past 10 minutes. To do this I grab a syslog line at a 
predetermined line and run a PERL script on it to parse the time stamp. 
This PERL script will then tell me how many seconds back the line was... 
if more than 10 minutes then the amount of lines used is sufficient. In 
any event, my basic problem is that from the command line the script 
works properly, but when I use it through NRPE/Nagios it fails to call 
the PERL script properly.

 From the command line:

# ./check_syslog
SYSLOG CRITICAL: Error found in: Jul 13 11:07:42 newsfe01 root: kernel 
panic <--- fake error I wrote it to syslog with logger

 From NRPE:

[/home/nagios/bin:#]- /home/nagios/bin/check_nrpe -n -H *.*.*.* -c 
check_syslog
SYSLOG OK: No errors found in /var/log/syslog for 0 seconds

The script itself:

LINES="1000 2000 3000"
LOGFILE="/var/log/syslog"
ERRORLIST="error.list"


# establish how many seconds old the specified log file entry is


for LINE in $LINES

        do
                SECONDS=$(tail -n $LINE $LOGFILE | head -n 1 | awk 
'{print $1,$2,$3}' | ./str2time -age | awk '{print $1}')

                if (($SECONDS > 600))
                then
                        break;
                fi
        done

# grep through and find errors. if output = null then OK, else critical

ERROR=$(tail -n $LINE $LOGFILE | egrep -m 5 -i -f $ERRORLIST)

if [ -n "$ERROR" ]
        then
                echo "SYSLOG CRITICAL: Error found in: $ERROR"
                exit 0;
        else
                echo "SYSLOG OK: No errors found in $LOGFILE for 
$SECONDS seconds"
                exit 2;
fi





More information about the Help mailing list