How To Make monit Send SMS Alerts When Your Server Goes Down

Version 1.0
Author: Falko Timme

This tutorial explains how you can configure monit to send alert messages per SMS to your mobile phone when a service fails. Because monit can send only emails but not SMS, we will use an email-to-sms gateway where monit will send its emails to, and the email-to-sms gateway will convert the emails to SMS messages.

This document comes without warranty of any kind! I want to say that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!


1 Preliminary Note

I'm assuming that you have already set up monit, e.g. as shown here: or here:

In this tutorial I want to monitor a web server (with the web site to see if it's still running or not. I therefore use monit on a second server ( so that monit can send alerts if the web server goes down for whatever reason (imagine you installed monit on the web server - if the server goes down, monit cannot send out any alerts...).

The SMS service I'm using here is (if you want to use that service, you must register first and pay at least 5 EUR to your prepaid account). As explained on (in German), the emails that you send to the gateway need the following format:

Subject: Text of the SMS
Text of the Mail: Email2SMS-Key#Recipient#SMS Type#Sender

You can specify the email2sms key in your account settings; the recipient is the phone number of your mobile phone (if you want to send the message to multiple recipients, separate the phone numbers by commas); as SMS type we use basicplus which costs only 3,5 cents (EUR cents) per SMS. The sender is optional so I leave it out.

I will tell monit to format its alert messages so that they match the required format.

You can, of course, use any other email-to-sms gateway. This is just an example of how to do it, and I have no relationship to


2 Configuring monit

Open /etc/monit/monitrc on and add the following stanza to it (at the end of the file):

vi /etc/monit/monitrc
check host with address
   if failed port 80 protocol http and request "/index.php" for 4 cycles then alert
   if failed icmp type echo count 5 with timeout 15 seconds for 4 cycles then alert
   alert [email protected] { connection, timeout, icmp } with mail-format {
      from: [email protected]
      subject: $SERVICE $EVENT at $DATE on $HOST
      message: 123456#0170123456789#basicplus

As you see, with this configuration monit will request the file index.php from, and in addition to that it will try to ping the host To make sure that monit doesn't send out too many false positives, it will send an alert only if the tests have failed for four consecutive times (for 4 cycles) - this should indicate that there's really a problem.

Alerts will be sent to the email-to-sms gateway email address, but only if there was a connection error, a timeout, or lost pings (a list of all available events can be found here:, and the mail-format section specifies the format of the alert email. The variables that you can use in the email are also listed on

Please adjust this to your email-to-sms gateway!

Restart monit afterwards:

/etc/init.d/monit restart

That's it!


Share this page:

9 Comment(s)