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

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Thu, 2008-08-07 10:33. :: Linux | Monitoring

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

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 08/05/2008

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: http://www.howtoforge.com/server_monitoring_with_munin_monit_debian_etch or here: http://www.howtoforge.com/server_monitoring_with_munin_monit_fedora_7.

In this tutorial I want to monitor a web server (with the web site www.mywebsite.com) to see if it's still running or not. I therefore use monit on a second server (monit.example.com) 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 SMS77.de (if you want to use that service, you must register first and pay at least 5 EUR to your prepaid account). As explained on http://www.sms77.de/email2sms.html (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 SMS77.de 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 SMS77.de.

 

2 Configuring monit

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

vi /etc/monit/monitrc

[...]
check host www.mywebsite.com with address www.mywebsite.com
   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 email2sms@sms77.de { connection, timeout, icmp } with mail-format {
      from: monit@monit.example.com
      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 www.mywebsite.com, and in addition to that it will try to ping the host www.mywebsite.com. 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: http://www.tildeslash.com/monit/doc/manual.php#alert_message_layout), 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 http://www.tildeslash.com/monit/doc/manual.php#alert_message_layout.

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

Restart monit afterwards:

/etc/init.d/monit restart

That's it!

 

3 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by harsh_shukla (registered user) on Thu, 2009-12-31 00:17.
you could find a new api that you dont need to configure on your server, it monitors your server from the its own hosted and reliable bulk sms gateway for the service you like to monitor for sending sms if it goes down you could check here http://www.shreeweb.com/sms-gateway
Submitted by AdrienneDrew (not registered) on Tue, 2010-11-30 13:37.
What do you mean that there is a service right now that can monitor SMS sending, is this in a mobile application platform format?  What is the use of monitoring these messages? 
Submitted by Andrew Miklas (not registered) on Fri, 2009-07-17 01:14.

If you're looking for a way to get phone and SMS alerts from Monit, check out our startup -- PagerDuty.  PagerDuty places automated phone calls or SMS messages in response to any email alert (including Monit).  It can also route alerts differently depending on the day-of-the week, letting you set up on-call rotations.

Submitted by tregi (not registered) on Sat, 2009-06-06 10:41.
Great article! I'm using another reliably SMS-Gateway from SMS-Expert.
Submitted by free sms (not registered) on Fri, 2010-04-09 14:51.
Dunno if this is obsolote but you can try this for Free SMS
Submitted by Anonymous (not registered) on Wed, 2008-10-01 09:17.

I know an other sms gateway which permit to send SMS. An API is available here :

http://www.envoyersms.org/

Antoine

Submitted by Anonymous (not registered) on Sun, 2011-08-28 11:09.

Try this http://www.sms4mail.com/smsmail/smscmd.htm

Simple Window and Linux sms command to send sms . No installation required.

Just download and run. There provides global SMS network and free try.

 

Submitted by Anonymous (not registered) on Wed, 2009-01-21 18:42.
I know an other sms gateway which permit to send SMS and very professionnal. An API is available here : 123-sms.net Marc