If tweeting is good enough for the Pope, then Stingray can certainly get in on the game! If you use tools to monitor Twitter accounts, this article will explain how you can direct Stingray's event log messages to a nominated twitter account so that you can be alerted immediately a key event occurs:
You might also like to check out the companion article - TrafficScript can Tweet Too.
Posting to Twitter is now a little involved. You need to create an application with the correct access (Read + Write), and then create the appropriate oauth parameters so that clients can authenticate themselves to this application.
To start off, log on to https://dev.twitter.com/apps and create an application as follows:
Follow the steps in https://dev.twitter.com/docs/auth/tokens-devtwitte
The OAuth authentication for your application requires two public/secret key pairs that you can generate from the management website:
Download and edit the following event handling script, updating the oauth tokens to match your own application and access tokens:
#!/usr/bin/python import sys import socket import oauth2 as oauth def oauth_req(url, http_method="GET", post_body=None, http_headers=None): consumer = oauth.Consumer(key="Pplp3z4ogRW4wKP3YOlAA", secret="jbWlWYOSgzC9XXXXXXXXXXXXXXXX") token = oauth.Token(key="1267105740-xhMWKdsNqoKAof7wptTZ5P
mNrodBJcQm1tQ5ssR", secret="p8GCJUZLXk1AeXXXXXXXXXXXX") client = oauth.Client(consumer, token) resp, content = client.request( url, method=http_method, body=post_body, headers=http_headers ) return content msg = sys.argv[-1] words = msg.split( '\t' ) host = socket.gethostname().split( '.' ) update = oauth_req( "https://api.twitter.com/1.1/statuses/update.json" , "POST", "status=" + words + ": " + words[-1] + " (" + words[-2] + " " + words.split('/')[-1] + ") #" + host )
From your Stingray Admin Server, create a new External Program Action named 'Tweet', and upload the edited event handling script.
Note that the script won't work on the Stingray Virtual Appliance (because it does not have a python interpreter), and on a Linux or Solaris host, you will need to install the python oauth2 module (pip install oauth2).
Test the event out with the: 'Update and Test' button in the edit page for the Tweet action, and review the event log to confirm that there are no errors:
You should see the test tweet in your twitter feed:
Wire up an event handler to trigger the Tweet action when the appropriate events are raised:
... and then site back and follow your twitter stream to see what's up with your Stingrays.