Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!jarthur!usc!zaphod.mps.ohio-state.edu!math.lsa.umich.edu!emv From: emv@math.lsa.umich.edu (Edward Vielmetti) Newsgroups: comp.lang.perl Subject: gnu awk extended to speak SNMP Message-ID: Date: 6 Mar 90 20:23:51 GMT Sender: news@math.lsa.umich.edu Organization: University of Michigan Math Dept., Ann Arbor MI. Lines: 107 In article <16053.636724600@cheetah.nyser.net> in comp.protocols.iso.dev-environ, Marshall Rose describes modifications to GNU Awk that speak to the ISODE 6.0 SNMP agent. I enclose a snippet and refer you to the actual article for more info. You'll have to ask Marshall about availability of these modifications -- I wouldn't be altogether opposed to seeing them put into my favorite rapid prototyping language for Unix.... From the article: >> GNU Awk A month back, I saw an announcement of the CMU SNMP package, which had a really neat idea. They took the popular netstat program and modified it to use SNMP iteractions to read information rather than just groking the kernel. I liked this idea so much that I decided to steal it! But, the CMU people did a lot more work than I thought they needed: they actually modified the netstat source. Instead, I thought, what one needed was a rapid-prototyping language for SNMP. Well, the rapid-prototyping language for UNIX is called awk, and the version of awk which is easiest for the most people to get the source to is GNU Awk. So, I modified my copy of GNU Awk (2.11 beta) to know about SNMP. The idea is that I now write awk scripts that read, process, and display SNMP variables from whatever agents I am interested in. For example, here is how I produce the output of "netstat -i": /////// BEGIN { printf "%-4s %-5s %-14s %-14s %-7s %-5s %-7s %-5s %-4s %-5s\n", "Name", "Mtu", "Net/Dest", "Address", "Ipkts", "Ierrs", "Opkts", "Oerrs", "Drop", "Queue"; didone = 0; for (i in ifIndex) { didone = 1; dest = ""; addr = ""; for (j in ipAdEntAddr) { if (ipAdEntIfIndex == ifIndex) { split(addr = ipAdEntAddr, a, "."); split(ipAdEntNetMask, b, "."); dest = bit_and(a[1],b[1]) "." \ bit_and(a[2],b[2]) "." \ bit_and(a[3],b[3]) "." \ bit_and(a[4],b[4]); break; } } printf (length(ifDescr) <= 4 ? "%-4s " : "%s\n "), ifDescr; printf "%-5d %-14s %-14s %-7d %-5d %-7d %-5d %-4d %-5d\n", ifMtu, dest, addr, ifInUcastPkts+ifInNUcastPkts, ifInErrors, ifOutUcastPkts+ifOutNUcastPkts, ifOutErrors, ifOutDiscards, ifOutQLen; if (oflag) for (j in clnpAdEntAddr) { if (clnpAdEntIfIndex == ifIndex) { printf "%-4s %-5s %-14s NS+%s\n", "", "", "", clnpAdEntAddr; break; } } } if (!didone && DIAGNOSTIC) printf "ifTable: %s\n", DIAGNOSTIC; } /////// So, I wrote a shell script which parses a command line to netstat, and invokes gawk on the write awk script. I then modified the SNMP agent to know about UNIX-specific MIB variables that are useful in making the netstat output appear more UNIX-like. So, when I run gawk and talk to a UNIX box, I get all the columns of output I want. When I talk to some other box, I get the subset of the information provided by MIB-I/II. The output of the shell script above looks like this: /////// % s-netstat -i Name Mtu Net/Dest Address Ipkts Ierrs Opkts Oerrs Drop Queue le0 1500 192.52.180.0 192.52.180.1 357417 35 327444 0 0 0 lo0 1536 127.0.0.0 127.0.0.1 35709 0 35709 0 0 0 /////// (me again) --Ed Edward Vielmetti, U of Michigan perl dept.