Yesterday I finally set up one of my main goals. SMS notifications.
I originally started out in the blind because the Zabbix forums did not seem to have any information at all about how to go about setting that up (And “SMS” is too small a word to search for, grrr). For some reason, people either had it set up or hadn’t. No one seemed to want to know how to do it. So I started searching in the Intarwebs and I came upong the solution eventually.
I used the program smssend which comes also in a debian package (This is where a good choice of distro helps 😉 ).
After installing it I started searching around for ways to use it. My initial plan was to create the script and test to see how it’s working and then implement it into Zabbix. After a bit of reading and a few other failed attempts, I decided to use the Clickatell service which is international, has pretty low fares and gives 10 free credits (about 12 local SMS) which was perfect for testing (although I did end up creating a second account).
Within this guide I will also guide you through setting up an account with Clickatell, which is free (and no, I’m not getting a commision) which you can use to test your script. If you want to use another smssend script, feel free but you’ll have to read up on it on your own.
So, to get things started, point your browser to http://www.clickatell.com/central/login.php and once there, click on Register for HTTP/S on the lower right corner and follow the instructions.
Once that is done and you have completed the registration procedure you should be logged in and you should have in front of you a screen where you are about to create an HTTP API.
Add a new API by the name Zabbix and submit. You don’t need to fill the other fields (IP Lock Down, Dial Prefix, Callback Url) if you don’t want to.
Now, if you press the Account link on the upper left corner, you should see a screen like this.
Note down the items in the Red and Blue circle. You’ll need your Client ID to log in Clickatell’s web interface (You should have gotten a mail about that as well) and you’ll need the API_ID in order to send your SMS through the script.
Now we have something to test with. Let’s do so.
Login to your zabbix server as root
$smssend clickatell -install # This will install the clickatell smssend script.
$smssend clickatell.sms Zabbix "Hello World" # Replace and with your Clickatell username and password, with the number you noted down earlier and should be self explainable.
This will send a message to your cell phone with a single “Hello World” message. If this arrives, you’re doing fine. Otherwise you may have to make it pass through your proxy. Append the following at the end of the previous command
— -p # Replace with your own ip or hostname (ex 192.168.5.12:8080).
(Note: if you are behind an ISA server (like I am) and you are not able to authenticate, try NTLMaps.)
If that still doesn’t work, check out your Authentication (Username, password and API_ID).
If you got the message, you are ready to create your super-duper SMS script.
Create a new file called sms.sh in the /home/zabbix/bin/ directory (Or sms_clickatell.sh if you plan to make more sms scripts that use different services)
# Script to send SMS messages from Zabbix
# $1 is the phone number, $2 is the subject and $3 is the message
# A is a hexadecimal code that gives a CR to your cell phone message
# See --man smssend-- for more
smssend clickatell.sms Zabbix $1 "$2 A A$3" -- -p # Don't forget to replace the appropriate fields as before. The proxy is optional.
Save the script and go into the terminal again.
$chown zabbix.zabbix sms.sh
$chmod +x sms.sh
You should now be able to use this script with Zabbix
Go to your Zabbix control panel (same as the WinPopUp script)
Configuration -> -> General -> (Choose) Media types -> Create Media Type
Script name: sms.sh
Now go to your user’s Media link and create a new media. Choose SMS as the Type and fill in the Send to field with you cell phone. Add an appropriate severity and you’re all set (I used disaster for this).
The way I tested if it is indeed working was to create a new action that sent a message to my account with a trigger on my zabbix_agentd status. So I just stopped and started the service to trigger the action to send me a message.If all goes well, you should be receiving an SMS from Zabbix with the subject and the Message separated by one empty line.
If for some reason you don’t receive the SMS, try to see if there is a problem with the script. Copy the script to a different name (ex sms_test.sh) and fill in the variable spaces $1, $2 and $3, For example:
smssend clickatell.sms Zabbix 123456789 "Test"
Then run the script from the terminal
If you receive an error message, then try to see what is causing it, if not, but you still don’t receive the SMS, try once again to run the smssend command from the terminal to see if there is any error there.
PS: If you have an idea for a better service than clickatell, then by all means use it and don’t forget to share the knowledge.