[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Conditionally check file content

From: Paul Theodoropoulos
Subject: Re: Conditionally check file content
Date: Wed, 17 Jun 2015 15:13:26 -0700
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.0

I'd recommend putting your tests/conditionals into a shell script, then check for the exit code from the script, for example:

cat /usr/local/bin/my_test_script
if [ ! -e $MYERRLOG ];then             # If the error log doesn't exist, all is good, so exit 'happy'
    exit 1
grep "^.*FATAL.*$" $MYERRLOG >/dev/null 2>&1  # the file exists, this will be reached. grep the file for the error line, and check the return status
if [ "$STAT" -eq "0" ];then
    exit 0    # if the return status shows that the error was found, exit with 'unhappy' status
    exit 1     # otherwise, all is good

and your monit script:
check program my_test_script  with path /usr/local/bin/my_test_script
if status != 1 then alert
if status != 1 for 3 cycles then alert

There's obviously other, probably 'cleaner' ways to do this, but that's the sort of construct I use.

On 6/17/15 12:57 AM, Ben Soot wrote:
Hi there,

I want to be alerted if file content (in an error log file) matches a pattern. The difficulty is that the file itself might not exist at all, which is ok.

How would you do that?

My current clause gives me a read flag in mmonit when the file does not exist:

check file myapp-err.log  with path /var/www/myapp/log/myapp-err.log
    if match
          "^.*FATAL.*$"  then alert

Thanks Ben

To unsubscribe:

Paul Theodoropoulos

reply via email to

[Prev in Thread] Current Thread [Next in Thread]