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
#!/bin/sh
MYERRLOG=/var/www/myapp/log/myapp-err.log
if [ ! -e $MYERRLOG ];then # If the error log doesn't exist, all is good, so exit 'happy'
    exit 1
fi
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
STAT=$?
if [ "$STAT" -eq "0" ];then
exit 0 # if the return status shows that the error was found, exit with 'unhappy' status
else
    exit 1     #otherwise, all is good
fi

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:
https://lists.nongnu.org/mailman/listinfo/monit-general

--
Paul Theodoropoulos
www.anastrophe.com


--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general

--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general

Reply via email to