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 <[email protected]>
#
# 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!

Bookmark the permalink.

Comments are closed