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

A list of changes and fixes in the iPhone 2.1 Firmware

There is a full list of changes and fixes in the new iPhone 2.1 firware on Apples site, which you can read here: http://www.apple.com/iphone/softwareupdate/ I've also included them below:
General Updates * Decrease in call set-up failures and dropped calls. * Significantly better battery life for most users. * Dramatically reduced time to backup to iTunes. * Improved email reliability, notably fetching email from POP and Exchange accounts. * Faster installation of 3rd party applications.
Read More