custom script

Martinus Nel martinus.nel at scarceskills.com
Thu Nov 18 14:57:29 CET 2004


Andreas,

Thank you.  Yes, my bad I tested with root.  Normally users such as 
nagios is set on /bin/false...

I don't fully understand the line you suggested:

[ -f "$LOG_FILE" ] || (echo "CRITICAL - $LOG_FILE is not a file"; exit 2)

Martinus.

Andreas Ericsson wrote:

> 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
>
>


-- 
Martinus Nel
System Administrator
Scarce Skills Ltd.
http://www.scarceskills.com
Tel: +44 (0) 1633 225461

---------------------------------------------------------------------------
DISCLAIMER
This e-mail message and any attachments are confidential and may also be a
privileged communication. It is intended solely for the person(s) to whom it
is addressed. If you are not the intended addressee of the message you must
take no action based on it. Please reply to this message to let us know you
received it in error and also delete the message from your system.
Internet e-mails are not necessarily secure and you should be mindful of
this when e-mailing us.

The contents of an attachment to this e-mail may contain software viruses
which could damage your own computer system. Whilst we have taken every
reasonable precaution to minimise this risk, we cannot accept liability for
any damage which you sustain as a result of software viruses. You should
carry out your own virus checks before opening the attachment.
---------------------------------------------------------------------------




-------------------------------------------------------
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