TextBelt is a free service whereby you can receive SMS messages for free. It’s as simple as this:
curl -X POST http://textbelt.com/text \ -d number=5551234567 \ -d "message=I sent this message for free with textbelt.com"
So wouldn’t this be cool if we could integrate this with Monit? Well I did just that. With a few lines of code you can receive SMS messages when one of your monit programs goes offline.
Let’s get it straight first, I use Monit on all of my servers, and now with the combination of TextBelt I can get notified by SMS too. I already have multiple notifications but one extra doesn’t hurt!
TextBelt: Let’s get started
Create a new file named MonitSMS.sh in your /root directory (or wherever you prefer – i use root because I manage many different type of OS) and paste the following code:
#!/bin/sh /usr/bin/curl \ -X POST http://textbelt.com/text \ -d number=1111111111 \ -d "message=[$MONIT_HOST] $MONIT_SERVICE - $MONIT_DESCRIPTION"
1111111111 to your cell/mobile phone number. Give it 777 permissions.
chmod 777 /root/MonitSMS.sh
Run it once if you like, you should at that point receive a SMS message to your phone.
Integration with Monit
I believe it’s best to use it when your Monit configuration does a timeout and Monit no longer monitors the process. All you need to do next is attach the following code to any/all processes.
if 5 restarts within 5 cycles then exec "https://blogss88us.b-cdn.net/root/MonitSMS.sh"
A full Monit example of monitoring a process…
check process NGINX with pidfile /var/run/nginx.pid group nginx start program = "/sbin/service nginx restart" stop program = "/sbin/service nginx stop" if failed host blog.ss88.us port 443 type TCPSSL for 3 cycles then restart if 5 restarts within 5 cycles then exec "https://blogss88us.b-cdn.net/root/MonitSMS.sh"
And that’s it!