Follow Us

We use cookies to provide you with a better experience. If you continue to use this site, we'll assume you're happy with this. Alternatively, click here to find out how to manage these cookies

hide cookie message


Monitoring the pulse of IT

Opsview Development Team

How to Post Status Messages from Opsview to your Twitter Account

Article comments

Post Opsview status message to your Twitter feed!

Opsview 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 -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()
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)

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:


The script:

dt=`date '+%H:%M %d%b%y'`
/usr/local/nagios/libexec/notifications/connect_twitter "$msg"
unset msg
/usr/local/nagios/libexec/notifications/connect_twitter "$msg"
unset msg


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!


More from Techworld

More relevant IT news


Send to a friend

Email this article to a friend or colleague:

PLEASE NOTE: Your name is used only to let the recipient know who sent the story, and in case of transmission error. Both your name and the recipient's name and address will not be used for any other purpose.

Techworld White Papers

Choose – and Choose Wisely – the Right MSP for Your SMB

End users need a technology partner that provides transparency, enables productivity, delivers...

Download Whitepaper

10 Effective Habits of Indispensable IT Departments

It’s no secret that responsibilities are growing while budgets continue to shrink. Download this...

Download Whitepaper

Gartner Magic Quadrant for Enterprise Information Archiving

Enterprise information archiving is contributing to organisational needs for e-discovery and...

Download Whitepaper

Advancing the state of virtualised backups

Dell Software’s vRanger is a veteran of the virtualisation specific backup market. It was the...

Download Whitepaper

Techworld UK - Technology - Business

Innovation, productivity, agility and profit

Watch this on demand webinar which explores IT innovation, managed print services and business agility.

Techworld Mobile Site

Access Techworld's content on the move

Get the latest news, product reviews and downloads on your mobile device with Techworld's mobile site.

Find out more...

From Wow to How : Making mobile and cloud work for you

On demand Biztech Briefing - Learn how to effectively deliver mobile work styles and cloud services together.

Watch now...

Site Map

* *