[Top][All Lists]

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

Re: Conditionally check file content

From: Ben Soot
Subject: Re: Conditionally check file content
Date: Sat, 20 Jun 2015 02:11:17 +0200
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.0.1

Yes i could do that but as far as i know monit remembers the last file position and does only scan new entries each cycle.

I would then basically have to replicate this logic - suboptimal...

On 18.06.2015 00:13, Paul Theodoropoulos wrote:
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

To unsubscribe:

reply via email to

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