CHECK FILE with script to determine filepath

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

CHECK FILE with script to determine filepath

Marc Rossi
Have an app that like many other apps has a timestamp in the filename. Would like to monitor this logfile without having to create a symlink.

Something like below.

check file foo.log
    with path `ls -rt /var/log/foo*| tail -n1`
    if content = "ERROR" then alert

Anyone have a solution for this given I don't believe it is supported by monit.

TIA.
    

--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general
Reply | Threaded
Open this post in threaded view
|

Re: CHECK FILE with script to determine filepath

Szépe Viktor
Idézem/Quoting Marc Rossi <[hidden email]>:

> Have an app that like many other apps has a timestamp in the filename.
> Would like to monitor this logfile without having to create a symlink.
>
> Something like below.
>
> check file foo.log
>     with path `ls -rt /var/log/foo*| tail -n1`
>     if content = "ERROR" then alert

You may monitor a shell script's output that does regexp matching.
See *_script files in  
https://github.com/szepeviktor/debian-server-tools/tree/master/monitoring/monit/services



SZÉPE Viktor, honlap üzemeltetés / Running your application
https://github.com/szepeviktor/debian-server-tools/blob/master/CV.md
--
ügyelet/hotline: +36-20-4242498  [hidden email]  skype: szepe.viktor
Budapest, III. kerület






--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general
Reply | Threaded
Open this post in threaded view
|

Re: CHECK FILE with script to determine filepath

Marc Rossi
Thanks for reply.  

Maybe I'm not understanding. We already run several different scripts for monitoring other things but I would like to use the simple file content monitoring supported out of the box.
I already do this for several other apps that have a fixed name logfile (or their startup scripts create a soft-link to the logfile that I use) but for a few apps we are deploying now the logfile has a timestamp embedded in it which obviously can't be represented by a static entry on the "with path" line -- so I would like to have monit execute a script every time it runs this check to determine the logfile path.



On Wed, Dec 12, 2018 at 4:28 PM SZÉPE Viktor <[hidden email]> wrote:
Idézem/Quoting Marc Rossi <[hidden email]>:

> Have an app that like many other apps has a timestamp in the filename.
> Would like to monitor this logfile without having to create a symlink.
>
> Something like below.
>
> check file foo.log
>     with path `ls -rt /var/log/foo*| tail -n1`
>     if content = "ERROR" then alert

You may monitor a shell script's output that does regexp matching.
See *_script files in 
https://github.com/szepeviktor/debian-server-tools/tree/master/monitoring/monit/services



SZÉPE Viktor, honlap üzemeltetés / Running your application
https://github.com/szepeviktor/debian-server-tools/blob/master/CV.md
--
ügyelet/hotline: +36-20-4242498  [hidden email]  skype: szepe.viktor
Budapest, III. kerület






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

--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general
Reply | Threaded
Open this post in threaded view
|

Re: CHECK FILE with script to determine filepath

Lutz Mader
Hello Marc,
monit doesn't handle varying log file namens.

check file Manager_Log with path "/var/log/em.log"
  if not exist then exec "/usr/local/etc/monit/scripts/emlog.sh"
  if size > 10 MB for 15 cycles then exec
"/usr/local/etc/monit/scripts/emlog.sh"
  ignore match "^.*\[INFO\].*"
  if match "^FATAL ERROR:.*" then exec
"/usr/local/etc/monit/scripts/emnotify.sh"
#  if match "^.*\[ERROR\].*" then alert
  group Manager

This is the way how monit handle logs, unfortunately there is no way to
handle log files with varying names or multiple log files in one step.

I try to handle this by using a script to create a link to the file with
the varying name in the past. But this is useful as long as the varying
log file will deleted or moved only.

check directory Log path "/var/log"
   if changed timestamp then exec "/usr/local/etc/monit/scripts/linklog.sh"
  group Manager

But I spend no time to write a script to handle directory changes to
detect/find new log files in the log folder and create a link.

No useful suggestion,
Lutz


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