SMS

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.
Clickatell
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

$cd /home/zabbix/bin
$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)

#!/bin/bash
# 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 "$2AA$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

Description: SMS
Type: Script
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
./sms_test.sh
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.

Congragulations!
SMS Results


4 Comments
Comments are closed | comments rss [?] | trackback uri [?]
  • http://rubenortiz.es Ruben

    Hi

    Im trying to do this in CentoOS, I know there are differents. I have compiled smssend from source. I don't know where you find the clickatell.sms in your guide : /
    I found this script of clickatell.sms, do you think its ok? Its pretty weird…I don't know I have to fill the script or give params through smssend like smssend clickatell.sms <Username> <Password> <API_ID> <API NAME> <Your Cell Phone Number> "Hello World"

    ## SkySMS provider file – http://www.clickatell.com
    ## # Version 0.1
    # by Steve Herrell
    # Error codes :
    # 1 -> General failure

    NbParams 6
    %Login : Your Login
    %Password Hidden : Your Password
    %ApiID Hidden : Your API ID
    %Sender : The API Name
    %Tel : Where it's going to
    %Message Size=160 Convert : Your message

    GetURL https://api.clickatell.com/http/sendmsg
    Params from=%Sender%&user=%Login%&password=%Password%&api_id=%ApiID%&to=%Tel%&text=%Message%
    Search ID:
    PrintMsg message sent
    Else
    ErrorMsg 1 error sending message
    GO

    Any help will be great :)

  • http://rubenortiz.es Ruben

    Well, if anyone find this thing, you have to pass values from CLI to clickatell.sms, o also called "provider" as:

    smssend clickatell.sms user password API_ID NAME_API NUMBER_TELF "hello"

    The next question for newbies will be, where we setup user, pass? are the user and pass to login in Clickatell?

    Thanks anyway

  • http://rubenortiz.es Ruben

    Well, I apologies my level of english and then, this three post but I get it! The problem was that I didn't know how Clickatell worked, first time I logged in, I did something and I had a SMTP API Connection. I have added a new API but with HTTP API and no pass, no user, anything. And then works.

    Now server of Zabbix can send messages to a cell phone, tomorrow Im going to test with zabbix :)

    Bye!

  • Speedyexe

    I CANT FIND SMS SEND WHAT TO DO NOW?