Configure Monit To Send SMS Instead Of Email
This tutorial helps you configure monit to send alert messages using SMS to your mobile phone when a service fails instead of traditional email notification. 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.
Why monit with SMS?
First obvious reason is that you will not need physical presence or access to your email account in order to get notified about the problem with some server process. On another hand, imagine having monit to monitor email server. How do you get alert if email server goes down?
In this tutorial we want to monit to check if file exist (will be using /tmp/somefile) and trigger an SMS alert if such file does not exist.
We will be using CS Networks sms gateway. To configure monit, you need to grab a free account with CS Networks, get some test credits, and purchase more latter once you confirm everything work as expected.
Assuming you already have monit installed up and running, let's open monit configuration file located at /etc/monit/monitrc.
sudo joe /etc/monit/monitrc
Now let's set the cs-networks server as a primary mail server for monit.
set mailserver api.cs-networks.net port 225
username "csnetworksusername" password "csnetworkspassword", localhost
with timeout 15 seconds
Now let's setup monit to check if /tmp/somefile exist and send a message if message does not exist.
check file with path /tmp/somefile
if does not exist then alert
alert [email protected]
That's it. Completed. Soon after restart, you should start receiving alerts on your phone instead of email.