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:

# $Id: 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
from libsnmp import v2
from twitter import Twitter

LOGIN = "traptweet-user"

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 =

    for varbind in pdu.varBindList:
        tweet = "Trap from %s: %s[%s]: %s %s" % ( str(pdu.agentAddr),
        #print "tweet [%d]: %s" % (len(tweet), tweet)

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

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.