Posts Tagged twitter

SOCIALIZING YOUR INFORMIX DATABASE SERVER

With the explosion of ‘social networking’ you would be hard pressed to find someone who has not heard of Facebook and Twitter. The purpose of this article is too provide an example of how you could potentially utilize these technologies and socialize your Informix Database Server.

For simplicities sake we are going to take a look at how we can use Twitter and its public api to give the Informix Database Server its own ‘social interaction’.

Twitter , if you are not aware , is a simple messaging service , allowing the user to type a short , limit of 140 characters, message , called a tweet , that just gets appended to a list of other messages the user has posted. Users can subscribe to each others messages in a concept termed ‘following’. A user publishing messages can choose to make their account public or private and has options available as to what ‘followers’ they have.

The example we are going to put together is to integrate the Informix Database Server alarm program withTwitter. Twitter has a public api that is very easy to use and provides the functionality necessary to create and post ‘tweets’. The example will utilize this API and create ‘tweets’ for events and alarms that the Informix Database Server creates.

GETTING STARTED

We have some specific requirements for the example , they are :

• A Twitter account – http://www.twitter.com

• An installation of ‘curl’ – http://curl.haxx.se

• Access to the internet on your machine where the Informix server is installed.

In this example we will be using the twitter account : idstweet, it has been configured to be ‘private’ so that only requested followers may see the posts.

Curl is often pre-installed on Linux distributions , but is also available on most platforms either in binary or source editions. Check the above curl website for more details.

We will be modifying the alarmprogram.sh found in the $INFORMIXDIR/etc directory , the example uses the 11.50 default alarmprogram.sh which maybe slightly different to yours depending upon your version of the Informix server.

MODIFYING ALARMPROGRAM.SH

In your favorite editor load the $INFORMIXDIR/etc/alarmprogram.sh . Locate the line starting with PAGEREMAIL.Below that line add the following :

TWITTERID=
TWITTERPASS=

TWITTERID is the user id of the twitter account you want to post alarms too and TWITTERPASS is the password for that account.

Example:

ADMINEMAIL=
PAGEREMAIL=
TWITTERID=idstweet
TWITTERPASS=informix

Now goto the end of the file and locate the line :

printf “$DATE_INT : $EVENT_SEVERITY_NAME : $EVENT_MSG\n” >>$LASTALARMFILE

Above that line add the following :

if ( `test x${TWITTERID} != x` ) then
    if ( `test x${TWITTERPASS} != x` ) then
          curl --basic --user $TWITTERID:$TWITTERPASS \
          --data status="`cat $MAILBODY`"\

http://twitter.com/statuses/update.xml

   else
         echo "TWITTER PASSWORD not set"
    fi
else
         echo "TWITTER ID not set"
fi

Save and quit your editor.

Now , depending upon the ONCONFIG parameters ALARMPROGRAM and ALRM_ALL_EVENTS , you should see some ‘tweets’ to your twitter.com account.

Twitter Screenshot for idstweet account

With just the above code you will see all events. This is really too much information so lets modify the script just to ‘tweet’ when the event severity is more than just information.

By changing the previous block of code to :

if ( `test x${TWITTERID} != x` ) then</span>
   if ( `test x${TWITTERPASS} != x` ) then
       if ( `test $EVENT_SEVERITY -ge 3`) then
                  curl --basic --user $TWITTERID:$TWITTERPASS \
                  --data status="`cat $MAILBODY`"\

http://twitter.com/statuses/update.xml

        fi
   else
      echo "TWITTER PASSWORD not set"
   fi
else
   echo "TWITTER ID not set"
fi

only events that have a severity of 3 or greater will be ‘tweeted’ .

SUMMARY

With just a few lines of shell script we have created a new outlet for consuming Informix Database Server events and alarms. There are lots of possibilities in taking this further including notification of tweets from 3rd party Twitter applications on mobile devices , server administration utilizing the SQL Admin API’s via tweets , the list could go on and on.

January 5, 2011


Pages

Categories

Archives