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

Sun Microsystems Acquires MySQL

I woke up to a very big announcement today. I was browsing digg and found that MySQL was acquired by Sun Microsystems. You can read more about the acquisition on the MySQL blog of Kaj Arno about the acquisition of MySQL by Sun Microsystems. My take, with Sun releasing Solaris into the Open Source realm, this is just another piece of software that they can put under their belt and package with Solaris. I have included some blurbs from Kaj Arno's blog below.
Read More

Apples iPhone Firmware 2.0.2 Causes More Issues Than It Fixes

I just saw this article on Slashdot... Slashdot | Apple's IPhone 3G Firmware Update Bombs Yahoo posted the news article... Apple's iPhone 3G Firmware Update Bombs (NewsFactor) by NewsFactor: Yahoo! Tech Both articles comment on the 2.0.1 firmware. However if you read the original article, it speaks about the new firmware which is 2.0.2 and was released on the 18th. NewsFactor Network | Apple Reportedly Plans Another Fix for the iPhone Either way, I don't have problems with my phone aside from MobileChat crashing and other Applications as well.
Read More