Home /  MMonit /  Pushover Notification

Introduction | M/Monit | Monit

In this example we use pushover.net, an online service which can send alerts to your iPhone or Android Phone. To send notification, you simply use curl, which is a command-line tool for sending HTTP requests. Curl is probably already installed on your system.

You will need to obtain an API key and setup an application token over at pushover.net and download the client app on your phone (not free, but inexpensive and sending messages are free).


Once you have your pushover account setup, go into M/Monit -> Admin -> Alerts and copy the following "script" into the execute program box:

 curl -s \
   -F "token=your_mmonit_or_monit_app_token" \
   -F "user=your_pushover_net_user_token" \
   --form-string "message=[$MONIT_HOST] $MONIT_SERVICE - \
   $MONIT_DESCRIPTION" https://api.pushover.net/1/messages.json

Monit environment variables are used to compose the alert message. An overview of available environment variables can be found in the inline help text in the alerts page and also in the Monit manual. The screenshot below illustrate the setup and how a notification might look on your phone.


You can do the same from Monit if you don't use M/Monit. Below is a program check in Monit which will send an alert using pushover if the check fails. But first, let's create a simple script which Monit can use to send Pushover notification:

/usr/bin/curl -s \
  -F "token=your_mmonit_or_monit_app_token" \
  -F "user=your_pushover_net_user_token" \
  --form-string "message=[$MONIT_HOST] $MONIT_SERVICE - $MONIT_DESCRIPTION" \

Save the script above to a file called, for instance, pushover.sh. We can now use this script in our Monit control file (.monitrc) to get pushover alerts if a check fails :

  check program check-mysql with path "/opt/monit/check_mysql.sh"
     if status != 0 then exec /path/to/pushover.sh

Note also that the content of the environment variable $MONIT_DESCRIPTION is anything your check program script (check_mysql.sh above) outputs to stdout/stderr. Which makes it possible to compose a detailed description of what went wrong.