Using Monit Environment Variables with exec

If you read the Monit documentation, it tells you exactly how to use Monit environment variables when using exec.

No environment variables are used by Monit. However, when Monit executes a start/stop/restart program or an exec action, it will set several environment variables which can be utilised by the executable to get information about the event, which triggered the action.

https://mmonit.com/monit/documentation/monit.html#ENVIRONMENT

I can be smart, but sometimes I can be daft. You don’t want to use the variables within your monit configuration, but instead, you want to use these variables in your exec script.

Here’s a great example of how to use $MONIT_EVENT. First set up a monit check

check system $HOST-steal
    if cpu (steal) > 0.1% for 1 cycles
        then exec "script.sh"
        AND repeat every 10 cycles

Now here’s script.sh which will use $MONIT_EVENT

#!/bin/bash
echo "Monit Event: $MONIT_EVENT" | mail -s "$MONIT_EVENT" [email protected]

I was in a rush and felt I had to post this to help others who might overlook this.


Did you like this article?


0 Shares:
You May Also Like

SueTube: sex, copyright, and rock & roll

Give this a gander. All of the current lawsuits against YouTube/Google, when they started taking down videos of Russel Peters and other popular shows. I cried.
SueTube: sex, copyright, and rock & roll -

Since its launch, YouTube has been a magnet for controversy. Ars looks at the popular video site's history of threats, lawsuits, and bans with an eye towards understanding what the landscape will look like once the dust settles.

Read More...

[Ars Technica]
Read More