custom script

Andreas Ericsson ae at op5.se
Thu Nov 18 14:20:28 CET 2004


Martinus Nel wrote:
> Dear all,
> 
> I created a custom check_log script, but I have a minor problem.
> 
> Attached is the script.
> 
>  From the machine that the script resides, all is ok.
> 
> NRPE config:
> command[check_log_test]=/usr/local/nagios/check_logs rel1.repost.Aug2604
> 
> Output from machine running NRPE:
> 
> # /usr/local/nagios/check_logs rel1.repost.Aug2604
> *** Repost of all pending candidates started at 10:00:01 PM *** : *** 
> Repost finished at 10:27:49 PM ***
> #
> 
> Good.
> 

Not good. If you're running it as root it just won't behave as it will 
when NRPE runs it. Never, ever test anything as the root user. It just 
won't give you th right results.

> Output from machine running Nagios:
> 
> # /usr/lib/nagios/plugins/check_nrpe -H xxx.xxx.xxx.xxx -p 5666 -c 
> check_log_test
> File does not exist.
> 
> Not good.
> 

Which goes to prove my point.

Are you sure the nrpe pseudo-user has permissions to grep the files in 
/home/admin/logs?

You can also add a stupid line to the script to catch possible argument 
distortion.
[ -f "$LOG_FILE" ] || (echo "CRITICAL - $LOG_FILE is not a file"; exit 2)

> The standard checks work all good, so I know there is nothing wrong with 
> nagios / NRPE.
> 
> I had a look at the stock check_log, but could not find any help there.
> Any help appreciated.
> 
> 
> ------------------------------------------------------------------------
> 
> #!/bin/sh
> 
> # Custom script for Nagios to monitor rel1 log files
> 
> # Data that we want to extract from the logs:
> # 	start and end time
> #	any errors
> 
> # Define possible exit status.
> OK=0
> WARNING=1
> CRITICAL=2
> UNKNOWN=3
> 
> # Make sure we get the right input.
> if [ $# -ne 1 ]
> then
>         echo "Usage: $0 log_file_name."
>         exit $UNKNOWN
> fi
> 
> LOG_FILE=/home/admin/logs/$1
> 
> # Check if file exists.
> if [ ! -f $LOG_FILE ]
> then
> 	echo "File does not exist."
> 	exit $CRITICAL
> fi
> 
> # Get start and end time of log.
> START_TIME=`grep "started at" $LOG_FILE`
> END_TIME=`grep "finished at" $LOG_FILE`
> 
> if [ "$START_TIME" = "" ] || [ "$END_TIME" = "" ]
> then
> 	echo "No start or end time."
> 	exit $CRITICAL
> fi
> 
> # Find errors.
> ERROR=`grep --ignore-case -e "ERROR" -e "Exception" $LOG_FILE`
> if [ "$ERROR" != "" ]
> then
> 	echo "Error found: $ERROR"
> 	exit $CRITICAL
> fi
> 
> # All is OK & send start & end time.
> echo "$START_TIME : $END_TIME"
> exit $OK

-- 
Andreas Ericsson                   andreas.ericsson at op5.se
OP5 AB                             www.op5.se
Lead Developer


-------------------------------------------------------
This SF.Net email is sponsored by: InterSystems CACHE
FREE OODBMS DOWNLOAD - A multidimensional database that combines
robust object and relational technologies, making it a perfect match
for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list