File content match not alerting

Issue #404 closed
Andrew Cutler created an issue

I have a results file that contains 0 or some other exit status. However the following config does not alert when the file content changes:

check file s3-backup.service path /etc/monit/results/s3-backup.service.result
  if content != "^0" then alert
  if timestamp > 32 hour then alert
  if does not exist then alert

Comments (2)

  1. Tildeslash repo owner

    Hello,

    the problem is most probably caused by the content ... monit remembers the position between cycles and resets it only under certain conditions, manual snip:

    On startup the read position is set to the end of the file and Monit continues to scan to the end of the file on each cycle.
    If the file size should decrease or inode changed, the read position is set to the start of the file.
    Only lines ending with a newline character are inspected.
    

    If you don't append to that file, but rewrite it, then monit the file size must change in order to catch the change (also the line has to be NL terminated).

  2. Andrew Cutler reporter

    Thanks, and sorry for the bother. I completely glossed over that section of the docs. (May I suggest moving those sentences up to the intro, or prefacing with NB.)

    I've updated the script to explicitly write a new file and append a second newline, and it now works:

    rm -f s3-backup.service.result; echo $EXIT_STATUS | (cat -; echo -n -e '\n') > s3-backup.service.result

  3. Log in to comment