Help with different kind of check

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

Help with different kind of check

Dimitri Yioulos-3

Hello, all.

 

I’m trying to have Monit restart a service based on a keyword in a particular file.  That file changes name by appending today’s date at the end, as in “myprogram-server.log.processed-2017-05-13”.  So, I have to craft a check that takes the changing date into account.  Here’s what I’ve created:

 

check file messages with path /data1/myprogram/log/myprogram-server.log.processed-($date +"%Y-%m-%d")

    if match "FATAL" then exec "/data1/myprogram/myprogram-mta/sm-server server restart"

 

The problem is in how to do the date part.  I’ve tried every combination of parens, quotes, back ticks, etc., but Monit won’t start because it doesn’t like the date part.  Can anyone help with this?

 

Also, I’d like an email alert to say that the that the service has been restarted.  As the check is presently written, it sends an email with e.g.May 15 13:36:30 satest03 systemd: Stopped The Apache HTTP Server.”  Here’s that check (and it’s only a test):

 

check file messages with path /var/log/messages

    if match "Stopped The Apache HTTP Server" then exec "/bin/systemctl restart httpd"  <- note that the match is what appears in the email message.  Can you help with this, too.

 

Many thanks.

 

Diggy


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

Re: Help with different kind of check

Bryan Harris
Perhaps run a daily cron to link the file so it's easier to use with monit.

crontab 0 0 * * * /some/script.sh

contents of script.sh
#!/bin/bash
rm /path/to/file-current
ln /path/to/real-file-YYYY-MM-DD /path/to/file-current

And have Monit always watches linked file.  I guess the inode will change but it was going to change the old way too.

On Mon, May 15, 2017 at 1:43 PM, Dimitri Yioulos <[hidden email]> wrote:

Hello, all.

 

I’m trying to have Monit restart a service based on a keyword in a particular file.  That file changes name by appending today’s date at the end, as in “myprogram-server.log.processed-2017-05-13”.  So, I have to craft a check that takes the changing date into account.  Here’s what I’ve created:

 

check file messages with path /data1/myprogram/log/myprogram-server.log.processed-($date +"%Y-%m-%d")

    if match "FATAL" then exec "/data1/myprogram/myprogram-mta/sm-server server restart"

 

The problem is in how to do the date part.  I’ve tried every combination of parens, quotes, back ticks, etc., but Monit won’t start because it doesn’t like the date part.  Can anyone help with this?

 

Also, I’d like an email alert to say that the that the service has been restarted.  As the check is presently written, it sends an email with e.g.May 15 13:36:30 satest03 systemd: Stopped The Apache HTTP Server.”  Here’s that check (and it’s only a test):

 

check file messages with path /var/log/messages

    if match "Stopped The Apache HTTP Server" then exec "/bin/systemctl restart httpd"  <- note that the match is what appears in the email message.  Can you help with this, too.

 

Many thanks.

 

Diggy


--
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: Help with different kind of check

Dimitri Yioulos-3

Thanks, Bryan.  Yeah, could do that, where this would work:  ln /path/to/real-file-`date +"%Y-%m-%d"` /path/to/file-current, and run the cron job at 12:01AM.  Nonetheless, I’m still hoping that there’s a solution within just Monit itself.

 

 

From: monit-general [mailto:monit-general-bounces+dyioulos=[hidden email]] On Behalf Of Bryan Harris
Sent: Monday, May 15, 2017 1:48 PM
To: This is the general mailing list for monit <[hidden email]>
Subject: Re: Help with different kind of check

 

Perhaps run a daily cron to link the file so it's easier to use with monit.

 

crontab 0 0 * * * /some/script.sh

 

contents of script.sh

#!/bin/bash

rm /path/to/file-current

ln /path/to/real-file-YYYY-MM-DD /path/to/file-current

 

And have Monit always watches linked file.  I guess the inode will change but it was going to change the old way too.

 

On Mon, May 15, 2017 at 1:43 PM, Dimitri Yioulos <[hidden email]> wrote:

Hello, all.

 

I’m trying to have Monit restart a service based on a keyword in a particular file.  That file changes name by appending today’s date at the end, as in “myprogram-server.log.processed-2017-05-13”.  So, I have to craft a check that takes the changing date into account.  Here’s what I’ve created:

 

check file messages with path /data1/myprogram/log/myprogram-server.log.processed-($date +"%Y-%m-%d")

    if match "FATAL" then exec "/data1/myprogram/myprogram-mta/sm-server server restart"

 

The problem is in how to do the date part.  I’ve tried every combination of parens, quotes, back ticks, etc., but Monit won’t start because it doesn’t like the date part.  Can anyone help with this?

 

Also, I’d like an email alert to say that the that the service has been restarted.  As the check is presently written, it sends an email with e.g.May 15 13:36:30 satest03 systemd: Stopped The Apache HTTP Server.”  Here’s that check (and it’s only a test):

 

check file messages with path /var/log/messages

    if match "Stopped The Apache HTTP Server" then exec "/bin/systemctl restart httpd"  <- note that the match is what appears in the email message.  Can you help with this, too.

 

Many thanks.

 

Diggy


--
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: Help with different kind of check

Lutz Mader
In reply to this post by Dimitri Yioulos-3
Hello Dimitri,
maybe I'm wrong, but the configuration loaded by monit is static only.
I use a script to generate some parts of the config dependent to some
relationships and do a reload to load the modifications.

> check file messages with path /data1/myprogram/log/myprogram-server.log.processed-($date +"%Y-%m-%d")
>     if match "FATAL" then exec "/data1/myprogram/myprogram-mta/sm-server server restart"
>
> The problem is in how to do the date part.  I've tried every combination of parens, quotes, back ticks, etc., but Monit won't start because it doesn't like the date part.  Can anyone help with this?

You can use a script to creat a modified config and load the config one
time a day (I use include files to split the whole config into small parts).

This is a suggestion only,
but Martin Pala should know the way,
Lutz


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