Pdsh

I’ve been using dsh for years and never realized how much I’ve been missing by not using Pdsh. Its really just awesome. Most of the syntax will be very familiar if you’ve used dsh before. Some of the new bells and whistles I like are:

Specifying ranges of hosts and exclude at the same time

pdsh -w host-[1-5,7] -x host-2,host-4 uptime

My favorite feature is being able to pipe to dshbak. It converts the output into a readable format. You can also pass dshbak -c to hide output that is the same but append the hostnames together in the header. Just awesome.

Posted in DevOps, Linux | Leave a comment

SNMPwalk a hosts location on an HP switch

A co-worker today helped me figure out how to snnpwalk an HP switch to determine what MAC addresses the switch knows about and specifically what port a MAC address is plugged into. We’re using the HP Procure model 2810 in this example.

First I had to add this to my .snmp/snmp.conf

mibs +BRIDGE-MIB

We’re running SNMPv3 so this command may look a bit different depending on the version you’re using.

snmpwalk -v 3 -u USER -l authNoPriv -a MD5 -A PASSWORD $HOST BRIDGE-MIB::dot1dTpFdbAddress

You’ll get back a list of ALL mac addresses (in decimal) the switch knows about. Next I just wrote some python to convert a list of mac address to decimal:

def mac_to_decimal(mac):
    s = mac.split(":")
    oid_in_decimal = []
    for octet in s:
        dec = int(octet, 16)
        oid_in_decimal.append(str(dec))

    return '.'.join(oid_in_decimal)

Then run an snmpwalk using BRIDGE-MIB::dot1dTpFdbPort by appending your mac address converted to decimal:

snmpwalk -v 3 -u USER -l authNoPriv -a MD5 -A PASSWORD $HOST BRIDGE-MIB::dot1dTpFdbPort.0.48.72.215.11.68

Pretty neat stuff for programmatically keeping track of your gear…

Posted in DevOps, Linux, snmp | Leave a comment

SNMP Tutorial – APC PDUs

I’ve been meaning to re-write an internal tool we I use at work to manage our APC PDU’s. Much to my surprise, there seemed to be lack of good SNMP resources including how to install MIBs and determine the OID’s I needed.

First we must install the necessary packages. I’ll be using debian squeeze so this may or may not work for you! This tutorial assumes you’ve got a APC pdu setup and SNMP configured to public community set to read and private community set to write+.

Install snmp

sudo apt-get install snmp

Install MIBs – Due to licensing reasons in Squeeze, the MIBs need to be installed separately.

sudo apt-get install libsnmp-base

sudo apt-get install snmp-mibs-downloader

Edit /etc/snmp/snmp.conf and comment out the line starting with 'mibs :'

Next ensure the MIBs installed properly. You should be able to run the following SNMPwalk.

snmpwalk -v 1 -c public 10.1.0.100

With the MIB’s installed the beginning of each line should be pre-fixed with SNMPv2-MIB.


SNMPv2-MIB::sysDescr.0 = STRING: APC Web/SNMP Management Card (MB:v3.8.6 PF:v3.5.8 PN:apc_hw02_aos_358.bin AF1:v3.5.7 AN1:apc_hw02_rpdu_357.bin MN:AP7930 HR:B2 SN: ZA0822009513 MD:05/30/2008)
SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.318.1.3.4.5
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (254515010) 29 days, 10:59:10.10
SNMPv2-MIB::sysContact.0 = STRING: ISI
SNMPv2-MIB::sysName.0 = STRING: pdu1.domain.com
SNMPv2-MIB::sysLocation.0 = STRING: My Fancy PDU

Much like IP space, OID’s are registered via IANA as a private “Enterprise” number. These numbers are used, among other things, for defining private SNMP MIBs. These OID’s will always begin with 1.3.6.1.4.1. Memorize this or all your friends will make fun of you!

To determine a devices OID run the following:

snmpwalk -v 1 -c public 10.1.0.100

Within the output you will see a line containing text such as “SNMPv2-SMI::enterprises”

SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.318.1.3.4.5

With the MIBs installed, 1.3.6.1.4.1 is translated into “enterprises”, followed by your Vendors assigned number. In this case, “318” is registered to APC.

If you can’t remember the number you can also run the following to get the same output.

snmpwalk -v 1 -c public 10.1.0.100 enterprises

Now while this is all ponies and sunshine, snmpwalk’n still spits out a bunch of stuff that really isn’t helpful. We still need to install the APC vendor specific MIB. You can grab a copy of the MIB’s on APC’s download site or on my github page.
git://github.com/joshuatobin/dotfiles.git

In order to active the mib, grep for DEFINITION:

# grep DEFINITION .snmp/mibs/powernet403.mib
PowerNet-MIB DEFINITIONS ::= BEGIN

We’re almost done, next activate the Definition “PowerNet-MIB” by adding the following line to .snmp/snmp.conf

mibs PowerNet-MIB

Now when we run the the SNMPwalk command the output looks a bit different, with verbose descriptions of the properties available. (Note that I’m tacking on .318, the APC’s assigned OID.)

# snmpwalk -v 1 -c public 10.1.9.104 enterprises.318
PowerNet-MIB::sPDUIdentHardwareRev.0 = STRING: "B2"
PowerNet-MIB::sPDUIdentFirmwareRev.0 = STRING: "v3.5.7"
PowerNet-MIB::sPDUIdentDateOfManufacture.0 = STRING: "05/30/2008"
PowerNet-MIB::sPDUIdentModelNumber.0 = STRING: "AP7930"
...
...
...
PowerNet-MIB::sPDUOutletCtl.1 = INTEGER: outletOn(1)
PowerNet-MIB::sPDUOutletCtl.2 = INTEGER: outletOn(1)
PowerNet-MIB::sPDUOutletCtl.3 = INTEGER: outletOn(1)
PowerNet-MIB::sPDUOutletCtl.4 = INTEGER: outletOn(1)
PowerNet-MIB::sPDUOutletCtl.5 = INTEGER: outletOn(1)
....
....

Once all the MIBs are in place, walking the device you should be able to determine which each of the OIDs do. If you’re unsure you can use snmptranslate (see below) to describe what each OID is cabable of.

A quick walk of the device shows a property called sPDUOutletCtl followed by a port number.
PowerNet-MIB::sPDUOutletCtl.1

Next get a confirmation and descriptions= of the options that can be passed to the object:
snmptranslate -Td PowerNet-MIB::sPDUOutletCtl.1

A quick glance shows that passing a value of (1) will turn the port on, (2) turn the port off, and (3) reboot.

Lets power off port 22 using the snmpset command:

# snmpset -v 1 -c private 10.1.0.100 PowerNet-MIB::sPDUOutletCtl.22 i 2

The command above is quite simple. Its using the “community group” set to private. Basically an auth group that has write privileges. The MIB DEFINITION and the property and lastly the “i” to specify an integer type of “2”.

And turning the port back on, passing it the value of “1”.

# snmpset -v 1 -c private 10.1.0.100 PowerNet-MIB::sPDUOutletCtl.22 i 1

Lastly there is one more tool that is super helpful, snmptranslate.

Sometimes the MIB descriptions can be a bit vague. Use snmptranslate to get a man page:
# snmptranslate -Td PowerNet-MIB::sPDUOutletCtl.1

PowerNet-MIB::sPDUOutletCtl.1
sPDUOutletCtl OBJECT-TYPE
— FROM PowerNet-MIB
SYNTAX INTEGER {outletOn(1), outletOff(2), outletReboot(3), outletUnknown(4), outletOnWithDelay(5), outletOffWithDelay(6), outletRebootWithDelay(7)}
MAX-ACCESS read-write
STATUS mandatory
DESCRIPTION “Getting this variable will return the outlet state. If
the outlet is on, the outletOn (1) value will be returned.
If the outlet is off, the outletOff (2) value will be
returned.



Its also sometimes helpful to translate a MIB to an OID:
$ snmptranslate -On PowerNet-MIB::sPDUOutletCtl.1
.1.3.6.1.4.1.318.1.1.4.4.2.1.3.1

Posted in Linux, Python | Tagged , , | 12 Comments

Homemade Panang Curry Paste

Ever since returning from Thailand in May of 2009 I’ve been experimenting with various store bought curry paste’s. Red, Green, Yellow, you name it. Each one came out awful, excessive coconut overtones, unpleasant aromas and strangely enough, the meat was always cooked to perfection. Tender and juicy almost like it had been braised and simmering for hours. Sigh.

After months of indecision and failed attempts I finally broke down and took a Thai cooking class with Jirayu at Mama Thai Cooking Club, and I’m so glad I did. Jirayu did an amazing job of showing us how to make curry paste from scratch, including even bringing us to Sunset Super to buy the ingredients. I highly recommend taking a class. Here is the recipe that I learned for Panang Curry Paste.

One caveat to making curry paste is that you need a 7-9″ Mortar and Pestle. You could in theory use a blender but that would be cheating! You can pick up one for about $30.00 if you live in San Francisco at Kamei.

Ingredients:

* 4/5 Whole Cloves of Garlic. Do not chop.
* 1 Shallot (Finely Chopped).
* 4/5 Thin Slices of Galangal – If you can’t find fresh Galangal, you can use canned but not recommended.
* Skin of one Kaffir Lime – Kaffir Limes are very difficult if not impossible to find. Substitute a few Kaffir Lime Leaves if needed. [1]
* 1-Stalk of Lemon Grass –  Chopped.
* 1-TBSP of Coriander Seeds.
* 1-TBSP of White Pepper Seeds – Don’t substitute Black Pepper. You can find this at any Asian Market.
* 1-TBSP of Salt.
* 1-TSP of Cumin Seeds.
* 1-TBSP of Cinnamon.
* 25-Dry Red Chillies – Soaked in water for 30 Minutes Prior to Preparation.
* 1-TBSP of Shrimp Paste.
* 1-Dried Star Anise
* 1-Dried Cardamom Pod

[1] Battambang Market carries these if you’re lucky enough to live close enough to the ‘loin. Oh and yeah… I’m not liable in anyway for your safety if you’re up for the adventure! Its right next to the SF police station so it can’t be that dangerous.. right?

Pre-Preparation:

About 30 Minutes before you begin soak the Red Chillies in some water. This makes them pliable and easier to work with.

Preparation:

1. Add everything to the Mortar except the Chillies and Shrimp Paste.

2. Pound the ingredients into a mushy paste for about 15-20 Minutes. You will get tired! Trust me its worth it.

3. Once you get a lush, tan colored paste with all of the ingredients mixed, add the red chillies.

4. Pound for another 5-10 Minutes, add Shrimp Paste.

Now that your paste is made lets make some curry. Freeze icecube size pieces of the curry paste if you’re not going to use it all.

Chicken Panang Kai:
Servings: 2
Ingredients:

* 1/2 pound of chicken. Sliced extremely thin! If the pieces are too big they’ll be flavorless.
* 1-TBSP Curry Paste.
* 1-Cup of Coconut Milk.
* 1-Dried Cardamom.
* 1-Dried Cinnamon.
* 1-Dried Star Anise.
* 1-TBSP of Coconut Oil.
* 1-TBSP of Palm Sugar. Don’t substitute brown or white sugar. This ingredient is key to having the dish come out right.
* 2-Kaffir Lime Leaves minced.
* 1-TBSP of Fish Sauce.
* 1-Can of Mushrooms or Sliced Red Pepper (Optional)

A wok or non-stick pan works best. If you don’t have a non-stick pan be sure to keep the heat on low until the coconut milk is added so the paste does not burn.

1. Heat the pan on low heat.
2. Once up to temperature add the coconut oil.
3. Add the Curry paste, Cardamon seed, Star Anise.

4. Continually stir for 2-3 minutes ensuring the that paste does not burn or stick to the bottom of the pan.
5. Slowly begin adding in the coconut milk, 1/4 cup at a time. Make sure the coconut milk is throughly mixed and at a full simmer before adding more.
6. Once all the coconut milk has been added, stir in the Fish sauce and Palm sugar.
7. Press your spoon on top of the Palm sugar and begin stirring in a rapid motion until the sugar has dissipated.
8. Once the sugar has melted, add the chicken, mushrooms or any vegetable of choice.
9. Turn the heat to high and rapidly stir.
10. Continue stirring until the chicken turns a pale white. Assuming you’ve cut it thin enough, it should only take about 1-2 minutes to cook.
11. At this point the curry will be a thick, and most likely look not like enough for two people.
12. Using your best judgement, add 1/4 of a cup of water at a time until the curry thins out. Continue tasting the curry making sure the coconut flavor is not overwhelming. I’ve ended up adding almost a cup of water to get the curry to a desired consistency.
13. Once the curry is to your liking, turn the heat off and add in the minced Kaffir lime leaves.
14. Serve with Sticky Rice and Enjoy.

Note: Never double the recipe if you’re making this for more than two people. It just doesn’t work.

This slideshow requires JavaScript.

Posted in Thai Food | Tagged , , | 5 Comments