Skip to content


Introducing Traptweet: An SNMP to Twitter Gateway

I had this idea a little while ago: an SNMP to Twitter gateway. It seemed like an obvious fit: Twitter is all about status updates, and that’s basically all an SNMP Trap is.

So this afternoon I hacked up a little Python script to do it:

#!/usr/bin/python
# $Id: traptweet.py 5 2009-06-16 07:32:37Z daedalus $
# Copyright (c) 2009 Justin Warren <justin@eigenmagic.com>
#
# A silly proof of concept SNMP Trap to Twitter gateway
# This scripts listens for SNMP Traps and tweets
# some of the information.
#
# Needs the following Python libraries:
#
# easy_install libsnmp
# easy_install twitter
#
# License: Attribution-Noncommercial-Share Alike 2.5 Australia
# http://creativecommons.org/licenses/by-nc-sa/2.5/au/
#
from libsnmp import v2
from twitter import Twitter

LOGIN = "traptweet-user"
PASSWORD = "MYPASSWORD"

tw = Twitter(LOGIN, PASSWORD)

def sendTweet(trapListener, msg):
    """
    Called when the trapListener recieves an SNMP trap.
    We extract the trap information and send it as a tweet.
    """
    pdu = msg.data

    for varbind in pdu.varBindList:
        tweet = "Trap from %s: %s[%s]: %s %s" % ( str(pdu.agentAddr),
                                                pdu.genericTrap.enum(),
                                                str(pdu.specificTrap),
                                                varbind.objectID,
                                                varbind.objectValue)
        #print "tweet [%d]: %s" % (len(tweet), tweet)
        tw.statuses.update(status=tweet)
        pass

trapListener = v2.SNMP(('0.0.0.0', 162), trapCallback=sendTweet)
trapListener.run()

Which looks like this:

A traptweet example

A traptweet example

Now your servers, switches, routers and coffee machines can Twitter!

Share and Enjoy:
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Reddit
  • StumbleUpon
  • Technorati
  • Live
  • Slashdot

No related articles.

Posted in Software, Ubergeek. Tagged with , , .

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.