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 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 . 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 and use the Create an App link, to create an application to start using the Twitter API. I named my App "OpsCenterTweet" and set it to Read and Write. After that it was a matter of 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 an 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 files in the classes\ext directory and the app I wrote 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-0DjmfdBtWOWdq1HuXoX1ALnmpT2fKUy80sFPXVd3" );
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.
Use at your own risk, some assembly required, batteries not included, your results may vary. LOL
Micro Focus Community Management
If you find this post useful, give it a 'Like' or use 'Verify Answer'.