Follow Us

Monitoring the pulse of IT

How to Post Status Messages from Opsview to your Twitter Account



Twitter-Logo-300x293-150x150.jpgOpsview gives you lots of standard options for receiving status notifications, but with a bit of custom scripting you can also get status messages from Opsview and post them to a Twitter account. This could be useful if you want to keep all your status messages in one place with a timeline. Plus you can also set up an account for other members of your team to follow so they can also see the updates. However it's probably best that the Twitter account is kept within your organisation unless you want the world to see the status of your servers!

This article tells you how to configure Opsview to send messages to Twitter. For configuring this you need to have access to the shell of your Opsview server.

To access Twitter from Opsview, you'll need to install Tweepy. Tweepy is a Python library for accessing the Twitter API. It requires Python 2.5 or later. If you need to install Python 2.6 you can follow the instructions on this blog.

# wget http://dagobah.ftphosting.net/yum/smartfile.repo -O /etc/yum.repos.d/smartfile.repo

Then you can use YUM to install python26 package:

# yum install python26 python26-distribute

To get a list of installed packages, do:

# yum list *python26* | grep -i installed
Installed Packages
python26.x86_64             2.6.5-6.el5   installed
python26-distribute.noarch  0.6.10-4.el5  installed
python26-libs.x86_64        2.6.5-6.el5   installed

Install Tweepy

/usr/bin/easy_install-2.6 tweepy

Next you'll need to authenticate Twitter from the command line. This blog tells you how.

At this point you'll need to create a new Twitter account which will be used to post the notifications.

Make sure you enable Tweet Privacy under Settings, in the Twitter account, so that posts are not made public (unless you want them to be!).

After creating the Twitter account, you'll need to register a new client app with Twitter.

Select "Connect the app to your Twitter account" with a minor change in the first line.. write python26 instead of python:

#!/usr/bin/env python26

Import tweepy

CONSUMER_KEY = 'paste your Consumer Key here'
CONSUMER_SECRET = 'paste your Consumer Secret here'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth_url = auth.get_authorization_url()
print 'Please authorize: ' + auth_url
verifier = raw_input('PIN: ').strip()
auth.get_access_token(verifier)
print "ACCESS_KEY = '%s'" % auth.access_token.key
print "ACCESS_SECRET = '%s'" % auth.access_token.secret

Again, in "Create the command line script", change to python26. Don't forget to add your own keys.

#!/usr/bin/env python26

import sys
import tweepy

CONSUMER_KEY = 'paste your Consumer Key here'
CONSUMER_SECRET = 'paste your Consumer Secret here'
ACCESS_KEY = 'paste your Access Key here'
ACCESS_SECRET = 'paste your Access Secret here'

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
api.update_status(sys.argv[1])

Then "Send a test tweet from the command line" and if the test is successful, do the following:

1.	Move the script to /usr/local/nagios/libexec/notifications/
(call the script 'connect_twitter', hence script is at /usr/local/nagios/libexec/notifications/connect_twitter)
2.	chown nagios:nagios /usr/local/nagios/libexec/notifications/connect_twitter
3.	chmod +x /usr/local/nagios/libexec/notifications/connect_twitter

Create another script to be used by Opsview:

/usr/local/nagios/libexec/notifications/notify-by-twitter

The script:

dt=`date '+%H:%M %d%b%y'`
if [ -n "$NAGIOS_SERVICEDESC" ]
then
msg=`echo @$NAGIOS__CONTACTTWITTERID Time:$dt. $NAGIOS_SERVICEDESC @ $NAGIOS_HOSTNAME,$NAGIOS_HOSTADDRESS is $NAGIOS_SERVICESTATE. $NAGIOS_SERVICEOUTPUT | cut -c 0-140`
/usr/local/nagios/libexec/notifications/connect_twitter "$msg"
unset msg
else
msg=`echo @$NAGIOS__CONTACTTWITTERID Time:$dt. $NAGIOS_HOSTNAME,$NAGIOS_HOSTADDRESS is $NAGIOS_HOSTSTATE. $NAGIOS_HOSTOUTPUT| cut -c 0-140`
/usr/local/nagios/libexec/notifications/connect_twitter "$msg"
unset msg
fi

Again,

chown nagios:nagios /usr/local/nagios/libexec/notifications/notify-by-twitter
chmod +x /usr/local/nagios/libexec/notifications/notify-by-twitter

Log in to Opsview as a user with admin privileges. Go to Advanced then Notification Methods from the drop down menu. On the top right, click Actions and then Create new Notification Method as following:

Display Opsview Status in Twitter


Next, go to Configuration on the Opsview Menu bar, then Contacts. Click on the contact you want to set Twitter alerts for. Click the Notifications button. Add your Twitter ID (this ID will receive the Tweets).

Display Opsview Status on Twitter


Click on Submit and edit Notification Profiles. Click Actions, and create new Notification Profile for user.

Display Opsview Status on Twitter

Create the profile and submit changes. Reload your configuration (click on Configuration Status, top right, then Reload Configuration).

Reboot one of your servers or stop a service which is added in Opsview. Note that Twitter allows 250 direct messages per day, do not cross this limit as tweets won't come in after you exceed this number.

The Tweets should now start coming in!

About the Author

Shibashish Satpathy is an Opsview Community user based in Mumbai, India. Shib works in IT Operations and enjoys photography, travelling and working with Linux!

Legal Disclaimer

This blog post is contributed by a member of the Opsview community. The Opsview project and Opsera Ltd accept no responsibility for the accuracy of its content and are not liable for any direct or indirect damages caused by its use.

Try this out for yourself by downloading Opsview Community edition and get our latest tips and updates by following us on Twitter!

Tags: opsview community, opsview status alerts, python, tweepy, twitter notifications

RSSSubscribe to this blog

More from Techworld

More relevant IT news

Contact Us

For editorial queries:
Mike Simons Mike_Simons@idg.co.uk

For website issues:
Email webmaster@techworld.com

For commercial queries
Russell Kearney russell_kearney@idg.co.uk


For more contact details click here.


Email this to a friend

* indicates mandatory field





Techworld White Papers

Optimising data protection for virtual environments

VM environments require the same level of data protection as does the physical server environment. Companies may use data protection tools built for the physical environment in the virtual world, but this has serious disadvantages.

Download Whitepaper

PCI Compliance: Are UK businesses ready?

Exploring the results of a recent survey, including: ? Levels of understanding of the standard ? Current perceptions of actual compliance status ? Attitudes toward addressing compliance

Download Whitepaper

Mobility Management for Dummies

Your complete guide to managing and securing mobile devices such as laptops and smartphones.

Download Whitepaper

Magic Quadrant for midrange and high-end NAS solutions

It is difficult to find one midrange or high-end NAS product that can cater to all needs. File systems embedded in NAS are often designed to solve one major pain point, with additional features being added later to broaden use cases and benefits.

Download Whitepaper

Techworld UK - Technology - Business

Oracle Video

Enabling agile and intelligent businesses

 Changing markets, competitive pressures and evolving customer needs are placing increasing pressure on IT to deliver greater flexibility and speed. Explore truly flexible SOA foundations with this Oracle video.

Watch
COLT White Paper

IT Misuse Survey

Complete this survey and you could win a Nexus One

Techworld are running a short survey to discover how UK businesses are managing Internet and email misuse in the Enterprise.

Complete Survey

Complete our survey and you could win a Sony E-book Reader.
Techworld have teamed up with HP to compile a survey relating to server virtualisation. Complete the short survey and you could be the lucky winner of a Sony E-book reader.

Complete the survey here

Site Map

Test