The other day I had one of those “hmmmm I wonder” moments. My teenage daughter tends to use twitter more than facebook. When a tweet comes in, her phone chimes and she starts clicking away. I then starting thinking about Operations Center monitoring the Enterprise and having tweets come to my phone when critical Services are having an issue. My initial thought was that… sure, I bet with a few hours work building the code, an automation could be put in place on Operations Center to automatically tweet. Guess what… it wasn’t really that hard, see the screen shot below.
The first thing of importance was creating a twitter account for the IT staff, I created an account called “OpsBoard”. I made the account private so the tweets (which could be sensitive) were not available to everyone on the internet. One of the IT admins could manage the account and approve other corporate IT staff approval to follow the OpsBoard account.
I looked around at the API options to integrate with twitter. I wanted an easy solution. Since right clicks and automations in Operations Center are in java script with an ability to access pure java, I was leaning that way. Twitter has a lot of details on their API, almost to much. I was looking for the short cut to just get it working. I found a SOAP option, but wasn’t interested. I dug around a little more and ran across Twitter4J (http://www.twitter4j.org). While this is an unofficial java library for Twitter, I found it very easy to use.
One of the requirements for building an API integration with Twitter is you are required to do some additional set up on Twitter. I had to login into my OpsBoard account on http://dev.twitter.com. I had to use the Create Application link. I named my App “OpsCenterTweet” and set it to Read and Write. After that it was a matter to pressing the button (OAuth tool) to get keys created (Consumer Key, Consumer Secret, Access Token & Access Token Secret). These keys are required for the application to login and perform tweets.
So I’ve created a private twitter account, set up an Application in twitter in order to get my keys and the account is set up for read and write. The next thing to do is build the app.
I was on one of my home computers so I download NetBeans, this is an easy to use Editor/Compiler for java. Based on the googling around I did, it looks like I need about five lines of code to issue a tweet.
ConfigurationBuilder confbuilder = new ConfigurationBuilder(); confbuilder.setOAuthAccessToken( accessToken ).setOAuthAccessTokenSecret( accessTokenSecret ).setOAuthConsumerKey( consumerKey ).setOAuthConsumerSecret( consumerKeySecret ); Twitter twitter = new TwitterFactory(confbuilder.build()).getInstance(); Status status = twitter.updateStatus(message);
After downloading the Twitter4J, creating a project in NetBeans, putting the code in place, it pretty much worked right away. I adjusted the code to make it easier to call from a Operations Center right click and/or automation. The next step was to set up a right-click (serverscript) to test it. I had to place the twitter4j jar files in the classes\ext directory and the app I wrote (link below) in the classes directory. I then created the following right click. (I changed my keys/tokens)
// set up tweet message var tweetMsg = element.name + " is at " + element.condition + " condition"; // set keys/tokens var twt = new Packages.tweet.Tweet(); twt.setAccessToken( "111111111-0DjmfdXyZOWdq1HuXoX1ALnmpPDqKUy80sFPXVd3" ); twt.setAccessTokenSecret( "AbC123XyZPdQbUZ5M6uX4gewgvTNsHrbmOgnrWZto" ); twt.setConsumerKey( "AbCPDW17P3HKyjLtAg" ); twt.setConsumerKeySecret( "vASCHFXyzPDQtvOyfLdu2X0aWVJ123G2vnAY" ); // time to tweet twt.postToTwitter( tweetMsg );
The idea of the script is to grab some content from Operations center first with the “var tweetMsg” line, essentially, grab the element and the condition. Next set my Account/App specific keys/tokens and then finally, call postToTwitter() with my tweet message.
There are enough details here for you to try things out, but there are other details that need to be addressed.
1) Twitter apparently will allow the tweets, but potentially there is a limit on the amount of tweets per minute, hour, day or something like that. If you think you might run into whatever this limit is, apparently there is a way to request to be whitelisted so you are not throttled (IE: tweets ignored and not posted)
2) If you set this up as an automation to fire when critical Business Services go critical (which is what I envisioned), during start up of Operations Center, the tweeting my get a little noisey. You may need to think of a way on the java script side to wait until the Operations Center server is up and running and settled down (IE: look at the uptime of the Administration/Server element to be more than n before tweeting).
3) Other details such as alarms could be posted, make sure you triple test everything to make sure you are not creating a performance bottleneck on the server and everything works for all the different situations that might happen (IE: accessing alarms when no alarms exist).
4) There is a limit on the amount of characters per tweet. My app does not do any trimming of characters and I have no idea what will happen if you tweet something past the limit.
5) Make sure you change the Access and Consumer keys in the java script above. Just in case you don’t, I changed them enough that it won’t work with my account
6) Lastly, this is a customization that you as the customer are putting in place. Support can only help with the basics of it, Consulting may be required to assist you with the full design/requirements.
Use at your own risk, some assembly required, batteries not included, your results may vary. LOL