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

Error’d: Crashing Las Vegas

This is awesome. I recently took a trick to Las Vegas, and wondered about all of the the neat hardware that runs the screens and lights.
Error'd: Crashing Las Vegas -

Surely, you’ve seen the commercials and are familiar with Las Vegas’ First-Commandment / Clever-Marketing-Tagline: What Happens in Vegas, Stays in Vegas. I suppose we can bend that rule today and share a couple pictures that Christopher Kimbell snapped while he was walking down the strip…

… and later that day …

As for the rest of the pictures that Chris found on his camera after his vacation? I think we'll just leave those in Vegas…

[The Daily WTF]
Read More