Jun 152015

I recently found out that Telstra has a SMS API, and for now, it’s free to use for up to 1000 SMSes a month for Australians (sorry rest of the world).

As I’ve been building up Zabbix for our work environment where SMSes are used regularly to alert techs to critical alerts, this piqued my interest as this means that for now, I could have SMS alerts for my homelab, and potentially implement the same solution at work.

To use the Telstra SMS API, you will first need to sign up for API keys to use it. Once you have the API keys, simple HTTP requests are used to send and check on SMSes.
The Quick start documentation contains all the scripts you need to get started, so I’ll skip over all of the basic stuff and move straight onto the Zabbix integration.

Building the scripts

Since the Telstra API uses OAuth2 Authentication tokens, We’ll need to take this into account when trying to send SMSes.
I’ve decided to write this script in python like the rest of my Zabbix scripts, and I’m also using flat files for key storage for this initial test implementation.

The full script is on GitHub, but I’ll do a quick explanation here.

First thing the script needs is to check for a token, and if one doesn’t exist or is expired, retrieve the an authentication token.
I’ve stored the authentication token in /tmp/telstraauth for now.

f = open('/tmp/telstraauth','r+')
filetoken = f.read()
dicttoken = json.loads(filetoken)
authtoken = dicttoken["access_token"]
dtobj = datetime.datetime.strptime(dicttoken["datetime"], '%Y-%m-%d %H:%M:%S.%f')
expires = dtobj + datetime.timedelta(0,int(dicttoken["expires_in"]))
if expires < now: print "expired" response = urllib2.urlopen(url) newtokendict = json.loads(response.read()) newtokendict["datetime"] = str(now) authtoken = newtokendict["access_token"] newjsontoken = json.JSONEncoder().encode(newtokendict) f = open('/tmp/telstraauth','w') print "new token : "+newjsontoken f.write(newjsontoken) f.close() else: print "not expired"

Once there is a token, the script will then send the message.

smsdata = { 'to':smsrcpt, 'body':subject+" "+body }
headers = { 'Content-type':'application/json','Authorization':'Bearer '+str(authtoken) }
url = "https://api.telstra.com/v1/sms/messages"

req = urllib2.Request(url,headers=headers,data=json.dumps(smsdata))
msg = urllib2.urlopen(req)

Configuring Zabbix

Creating a new Media Type

Like the other notification methods, this requires a new Media Type. Under Administration -> Media Types, create a new media type and give it a name. I've used Telstra SMS. Then choose the type Script and enter in the script name.
I've named the script telstrasms.py

Configuring User Media Type

Once the Media type is created, you'll need to define the media type on the user to set a number to send messages to. Under the User -> Media tab, create a new media type, and define a number to send to.

Configuring Alert

Once the user has been configured, you'll need to set up the actions to use the new SMS media type.
Under the Operations tab of the Action, make sure the Send Only to is set to Telstra SMS, and the user that is set up there has the correct media type set up.

Once that is done, you should get alerts via SMS from Telstra.


  10 Responses to “Using The Telstra SMS API With Zabbix”

  1. […] Using The Telstra SMS API With Zabbix […]

  2. Hi – Is it possible for this to be used still?

    • They’ve updated the SMS API since I wrote this post, so I doubt that it still works 🙁
      I haven’t looked at the updated SMS API yet, but if you’re interested in using Zabbix with it, let me know and I’ll see if I can fit some time in to check it out.

      • Hey – Damn, i wish i read over this wasn’t aware you responded.

        Definitely interested still, i actually just installed all of this to realize it didn’t work haha.

      • Hey! – Did you ever get around to this?

        • Sorry mate, not yet. Flat out at the moment!

          • Happy new year mate, hope all has been well so far.
            Would be great when you do get around to this if you could shoot me an email.


          • Sorry mate, I’ve been flat out with other things, haven’t even looked at my blog for months (obviously!). I’ll definitely let you know when I’ve had a chance to take a look

  3. Hey – Damn, i wish i read over this wasn’t aware you responded.

    Definitely interested still, i actually just installed all of this to realize it didn’t work haha.!

  4. Hey – TelstraDev has updated the Messaging API, to include not just new features but adding new platforms (MMS for now, watch this space for more!). It’s not as backwards compatible with the 2015 version, but our github repo has some handy SDKs to get started with.

    Docs and examples:

    I’m the Developer Advocate at TelstraDev and would love to hear how you were consuming the Messaging API and if you were after any more demos or guides for making the most of it? Reach out telstradev@team.telstra.com

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>



This site uses Akismet to reduce spam. Learn how your comment data is processed.