By pmonday on Dec 17, 2009
Twitter, Instant Messages, Mobile Alerts have always fascinated me. I truly believe that a Storage Administrator should not have to leave the comfort of their iPhone, Droid or Palm Pre to do 90% of their day to day management tasks. As I was scanning the headlines of blogs.sun.com I saw this great article on Tweeting from Command Line using Python.
So, leading into how to manage a Sun Storage 7000 Appliance using Alerts (the next article in my series) I thought I would take some time and adapt this script to tweet my received Sun Storage 7000 Appliance Traps. I am going to use the AK MIB traps (to be explained in more detail in the next article) to achieve this.
Writing the Python Trap Handler
First, create the trap handler (this is based on the Python Script presented in the Blog Article: Tweeting from Command Line using Python).
Here is the Python Script:
from os import popen
print 'Hold on there %s....Your message %s is getting posted....' % (message, user)
url = 'http://twitter.com/statuses/update.xml'
curl = '/usr/dist/local/sei/tools/SunOS-sparc/curl -s -u %s:%s -d status="%s" %s' % (user,password,message,url)
pipe = popen(curl, 'r')
if __name__ == '__main__':
host = sys.stdin.readline()
ip = sys.stdin.readline()
uptime = sys.stdin.readline()
uuid = sys.stdin.readline()
alertclass = sys.stdin.readline()
alertcount = sys.stdin.readline()
alerttype = sys.stdin.readline()
alertseverity = sys.stdin.readline()
alertsresponse = sys.stdin.readline()
messageArray = [host,ip,alerttype]
message = t.join(messageArray)
message = message[0:140]
user = "yourtwitter" #put your username inside these quotes
password = "yourpassword" #put your password inside these quotes
You will have to make the following changes at a minimum
- Re-insert the missing tabs based on Python formatting
- Ensure the path to CURL is appropriate
- Change the user and password variables to your Twitter account
Once that is done you should be set.
Adding the Trap Handler to SNMP
Next, set up your snmptrapd.conf to handle traps from the AK MIB by invoking the Python Script above. My /etc/sma/snmp/snmptrapd.conf looks something like this:
traphandle .220.127.116.11.18.104.22.168.22.214.171.124.1 /export/home/oracle/ak-tweet.py
The OID .126.96.36.199.188.8.131.52.184.108.40.206.1 identifies the sunAkTraps portion of the AK-MIB delivered with the Sun Storage 7000 Appliance.
Now, invoke snmptrapd using the above configuration file (there are many ways to do this but I am doing the way I know will pick up my config file
/usr/sfw/sbin/snmptrapd -c /etc/sma/snmp/snmptrapd.conf -P
Sending Alerts from the Sun Storage 7000
Using the article I posted yesterday, ensure SNMP is enabled with a trapsink identifying the system where your trap receiver is running. Now we have to enable an alert to be sent via SNMP from your Sun Storage 7000 Appliance (this is different from the default Fault Management Traps I discussed yesterday).
For now, trust me on this, I will explain more in my next article, let's enable a simple ARC size threshold to be violated. Go into the Browser User Interface for your system (or the simulator) and go into the Configuration -> Alerts screen. Click through to the "Thresholds" and add one that you know will be violated, like this one:
Each alert that is sent gets posted to the twitter account identified within the Python Script! And as my friends quickly noted, from there it can go to your Facebook account where you can quickly declare "King of the Lab"!
Thanks Sandip for your inspiring post this morning