Cisco Blogs


Cisco Blog > Data Center and Cloud

Automate Getting the UCS SNMP MIBs

March 9, 2012
at 5:22 pm PST

I like the command line, I’ll admit it, it’s old-school but l am old-school. Clicking around a graphical interface is all well and good but if you want to get something done the command line is the way to do it. My high school years, college years and early career were a variety of Unix flavors, VMS, DOS, CP/M with an assortment of editors, programming languages and shells.

What I love is when a graphical interface can be managed via a command line.  This way I know that I can use all my favorite tools (old and new) to get done what needs to be done. What needs to get done sometimes is taking the point and click out of a task. That’s my focus today.

Here’s the scenario, download SNMP MIBs for UCS. Go to that web page and you need to get very clicky, perhaps even right-clicky and select the “save as” option. More clicks, with potentially over 100 MIBs to download that’s 200 plus clicks, and the repetition is as mind numbing as a top 40 radio station.

The command line comes to the rescue and saves your index finger and your mind. These are the *nix utilities that I use, cURL , awk, and grep. I’m sure there are other utilities that work. Leave me a comment with your solution I’d love to see it. I’m also running these utilities in Cygwin, in a Windows 7 VM, running on my MAC.  Sounds like subterfuge, you may just be on a *nix box directly, whatever works is good. The command below will retrieve the web page, extract the ftp links for each UCS version and separate by UCS version number.

curl -s http://ftp.cisco.com/pub/mibs/supportlists/ucs/ucs-manager-supportlist.html |
grep -i -E '.my\"|Release [1-9]\.[0-9]</span></a>' |
awk '{if (index($0,"ftp")) {print substr($0,index($0,"ftp://"),index($0,".my\"")-index($0, "ftp://")+3)} else {print substr($0,index($0,"Release"),index($0,"</span></a>")-index($0,"Release"))}}' > mib-link-curl.txt

Once I have a list of ftp links separated by version number I can use that as input to a script that will download and package the MIBs by UCS version number. I can then give that package to a customer, a co-worker, or just post it somewhere.

I used curl to get the webpage, pretty easy it’s just curl and then the webpage, the -s tells curl to be silent about what it is doing.

curl -s http://ftp.cisco.com/pub/mibs/supportlists/ucs/ucs-manager-supportlist.html

I then use grep to extract the lines of the webpage source that I am interested in. If I examine the page source for the UCS MIB listing I see a whole bunch of links for the Cisco FTP site, ftp.cisco.com. I can also see that the MIBs are divided into a few sections. 1.0 MIBs are for all versions of UCS Manager, and then there are 1.3, 1.4 and 2.0.  Turns out that 1.4 and 2.0 MIBs are exactly the same, 2.0 just has a couple more MIBs to support the added 2.0 functionality. I needed to identify something in the page source that indicated the beginning of each section and found these strings to work nicely.

Release 1.0</span></a>
Release 1.3</span></a>
Release 1.4</span></a>
Release 2.0</span></a>

Make that into a regular expression and it looks like this

Release [1-9]\.[0-9]</span></a>

I also needed to identify the ftp links that would be used to retrieve the MIBs, those were just as easy;

.my”

Every MIB file ftp link ended with .my”. Based on this my final regular expression and command to extract what I needed with grep looks like this;

grep -i -E '.my\"|Release [1-9]\.[0-9]</span></a>'

grep without case sensitivity  in enhanced mode, lines that have .my” in them or ones that match the Release 1.0, 1.3, 1.4 or 2.0 pattern. The regular expression will actually match “Release 1.0” through “Release 9.9”

I’ve got the webpage, extracted the lines I want and now awk will do the slicing and dicing to pull out the most interesting parts. The awk command is in one line but I’ll throw in some formatting here to make it easier to read.

awk '{
if (index($0,"ftp")) {
print substr($0,index($0,"ftp://"),index($0,".my\"")-index($0, "ftp://")+3)
} else {
print substr($0,index($0,"Release"),index($0,"</span></a>")-index($0,"Release"))
}
}'

There will be two types of lines coming to awk either a line that has an ftp link to a MIB file or a line that has the “Release #.#” string in it. A simple if statement that decides what to do, if the string “ftp” is found in the line then it is an ftp line, otherwise it has to be a Release line.

If the line is an ftp line the substring and index functions of awk will extract the link and print it out. If the line is a Release line the substring and index functions will extract the Release line and print it out. All the printed output is captured in the file mib-link.txt

Here is a condensed output that you’ll end up with

Release 1.0
ftp://ftp.cisco.com/pub/mibs/v2/CISCO-AAA-SERVER-MIB.my
ftp://ftp.cisco.com/pub/mibs/v2/CISCO-AAA-SERVER-EXT-MIB.my
.
. Several MIB ftp links not shown
.
ftp://ftp.cisco.com/pub/mibs/v2/FC-MGMT-MIB.my
ftp://ftp.cisco.com/pub/mibs/v2/FIBRE-CHANNEL-FE-MIB.my
Release 1.3
ftp://ftp.cisco.com/pub/mibs/v2/CISCO-UNIFIED-COMPUTING-MIB.my
ftp://ftp.cisco.com/pub/mibs/v2/ITU-ALARM-TC-MIB.my
Release 1.4
ftp://ftp.cisco.com/pub/mibs/ucs-mibs/CISCO-UNIFIED-COMPUTING-AAA-MIB.my
ftp://ftp.cisco.com/pub/mibs/ucs-mibs/CISCO-UNIFIED-COMPUTING-ADAPTOR-MIB.my
.
. Several MIB ftp links not shown
.
ftp://ftp.cisco.com/pub/mibs/ucs-mibs/CISCO-UNIFIED-COMPUTING-VM-MIB.my
ftp://ftp.cisco.com/pub/mibs/ucs-mibs/CISCO-UNIFIED-COMPUTING-VNIC-MIB.my
Release 2.0
ftp://ftp.cisco.com/pub/mibs/ucs-mibs/CISCO-UNIFIED-COMPUTING-AAA-MIB.my
ftp://ftp.cisco.com/pub/mibs/ucs-mibs/CISCO-UNIFIED-COMPUTING-ADAPTOR-MIB.my
.
. Several MIB ftp links not shown
.
ftp://ftp.cisco.com/pub/mibs/ucs-mibs/CISCO-UNIFIED-COMPUTING-VM-MIB.my
ftp://ftp.cisco.com/pub/mibs/ucs-mibs/CISCO-UNIFIED-COMPUTING-VNIC-MIB.my

Take this output and write a script that will read in the output download the MIBs, create directories for each version and perhaps even tar and gzip the MIBs.  Like what I have below

#!/bin/sh
#
# John McDonough Cisco Systems, Inc.
#
# This script is a proof of concept of what can be done
# using standard *nix tools to download MIBs from the
# Cisco ftp site
#

FTPMIBLIST=${1} # Arg 1 to the script a file with a list of MIB links
DEBUG=${2}      # Arg 2 put anything as arg 2 to see debug output
RELEASEVERSION="0.0"

while read CURLINE; do
LINETYPE=`echo ${CURLINE} | awk '{if (index($0,"ftp")) {print "ftp"} else {print "release"}}'`

if [ ${DEBUG} ]; then
echo "The Current line: ${CURLINE}"
echo "The Line type: ${LINETYPE}"
fi

if [ ${LINETYPE} = release ]; then
OLDRELEASEVERSION=${RELEASEVERSION}
RELEASEVERSION=`echo ${CURLINE} | awk '{print $2}'`

if [ ${OLDRELEASEVERSION} != "0.0" ]; then
tar -zcf ${OLDRELEASEVERSION}.tar.gz ${OLDRELEASEVERSION}/
fi

if [ ${DEBUG} ]; then
echo "The Release version: ${RELEASEVERSION}"
fi

else

MIBFILENAME=`echo ${CURLINE} | awk -F/ '{print $NF}'`

if [ ${DEBUG} ]; then
echo "The MIB filename: ${MIBFILENAME}"
fi

curl -s --retry 2 --retry-delay 5 --create-dirs -o ${RELEASEVERSION}/${MIBFILENAME} ${CURLINE}

fi

done < ${FTPMIBLIST}
tar -zcf ${RELEASEVERSION}.tar.gz ${RELEASEVERSION}/

How could you extend this script?

    Create timestamps

  • Verify all files expected to be downloaded are downloaded
  • ftp MIB files to location where NMS systems load them from
  • Schedule the running of the script for an appropriate interval
  • Adapt the script to get MIB files for other products

I hope this helps in your UCS system administration or for any other Cisco product.

Tags: ,

Comments Are Closed