scotty SNMP-Based Management Tools

144 This should give you an adequate idea of what is going on for most troubleshooting needs. See the manpage for other options. NET SNMP also includes two applications for dealing with traps. snmptrapd starts a daemon to receive and respond to traps. It uses the configuration file snmptrapd.conf. The snmptrap is an application used to generate traps. While these can be useful in troubleshooting, their use is arcane to say the least. You will need to edit the appropriate MIB files before using these. There are simpler ways to test traps.

7.2.2 scotty

scotty was introduced in Chapter 6 . Now that weve talked a little about SNMP, here are a few more examples of using scotty. These are based on examples given in one of the README files that comes with scotty. Since you will have to install scotty to get tkined, it is helpful to know a few scotty commands to test your setup. These scotty commands also provide a quick-and-dirty way of getting a few pieces of information. To use SNMP with scotty, you must first establish an SNMP session: lnx1 scotty set s [snmp session -address 172.16.1.5 -community private] snmp0 Once you have a session, you can retrieve a single object, multiple objects, the successor of an object, or subtrees. Here are some examples: s get sysDescr.0 {1.3.6.1.2.1.1.1.0 {OCTET STRING} {APC Embedded PowerNet SNMP Agent SW v2.2, HW vB2, Mod: AP9605, Mfg 081096, SN: WA9632270847, Agent Loader v1.0}} s get sysDescr.0 sysContact.0 {1.3.6.1.2.1.1.1.0 {OCTET STRING} {APC Embedded PowerNet SNMP Agent SW v2.2, HW vB2, Mod: AP9605, Mfg 081096, SN: WA9632270847, Agent Loader v1.0}} {1.3.6.1 .2.1.1.4.0 {OCTET STRING} {Sloan jsloanlander.edu}} s getnext sysUpTime.0 {1.3.6.1.2.1.1.4.0 {OCTET STRING} {Sloan jsloanlander.edu}} s getnext [mib successor system] {1.3.6.1.2.1.1.1.0 {OCTET STRING} {APC Embedded PowerNet SNMP Agent SW v2.2, HW vB2, Mod: AP9605, Mfg 081096, SN: WA9632270847, Agent Loader v1.0}} {1.3.6.1 .2.1.1.2.0 {OBJECT IDENTIFIER} PowerNet-MIBsmartUPS700} {1.3.6.1.2.1.1.3.0 Time Ticks {4d 22:27:07.42}} {1.3.6.1.2.1.1.4.0 {OCTET STRING} {Joe Sloan}} {1.3.6.1. 2.1.1.5.0 {OCTET STRING} {APC UPS}} {1.3.6.1.2.1.1.6.0 {OCTET STRING} {214 Laura Lander Hall, Equipment Rack}} {1.3.6.1.2.1.1.7.0 INTEGER 72} {1.3.6.1.2.1.2.1.0 INTEGER 1} {1.3.6.1.2.1.2.1.0 INTEGER 1} Once you know the syntax, it is straightforward to change the value of objects as can be seen here: s set [list [list sysContact.0 OCTET STRING Joe Sloan] ] {1.3.6.1.2.1.1.4.0 {OCTET STRING} {Joe Sloan}} 145 s get sysContact.0 {1.3.6.1.2.1.1.4.0 {OCTET STRING} {Joe Sloan}} Notice that after the object is set, I have retrieved it to verify the operation. I strongly recommend doing this each time you change something. If you arent familiar with Tcl, then defining a trap handler will seem arcane. Here is an example: proc traphandler {ip list} { set msg SNMP trap from ip: foreach vb list { append msg [mib name [lindex vb 0]]=\[lindex vb 2]\ } puts stderr msg } set t [snmp session -port 162] snmp1 t bind trap {traphandler A V} Once the trap handler is defined, we can test it by interrupting the power to the UPS by unplugging the UPS. [3] This test generated the following trap messages: [3] This is OK with this particular UPS. In fact, its suggested in the documentation. However, you dont want to do this with just any UPS. While UPSs are designed to deal with power interruptions, some are not necessarily designed to deal with the ground being removed, as happens when you unplug a UPS. SNMP trap from 172.16.1.5: sysUpTime.0=2d 21:15:50.44 snmpTrapOID.0=PowerNe t-MIBupsOnBattery smartUPS700=57:41:52:4E:49:4E:47:3A:20:54:68:65:20:55:50:53 :20:6F:6E:20:73:65:72:69:61:6C:20:70:6F:72:74:20:31:20:69:73:20:6F:6E:20:62:61: 7 4:74:65:72:79:20:62:61:63:6B:75:70:20:70:6F:77:65:72:2E snmpTrapEnterprise.0=a pc SNMP trap from 172.16.1.5: sysUpTime.0=2d 21:15:50.55 snmpTrapOID.0=1.3.6.1.2 .1.33.2.0.1 upsEstimatedMinutesRemaining=31 upsSecondsOnBattery=0 upsConfig LowBattTime=2 snmpTrapEnterprise.0=upsTraps SNMP trap from 172.16.1.5: sysUpTime.0=2d 21:15:50.66 snmpTrapOID.0=1.3.6.1.2 .1.33.2.0.3 upsAlarmId=12 upsAlarmDescr=UPS-MIBupsAlarmInputBad snmpTrapEn terprise.0=upsTraps SNMP trap from 172.16.1.5: sysUpTime.0=2d 21:15:55.27 snmpTrapOID.0=1.3.6.1.2 .1.33.2.0.4 upsAlarmId=11 upsAlarmDescr=UPS-MIBupsAlarmOnBattery snmpTrapE nterprise.0=upsTraps SNMP trap from 172.16.1.5: sysUpTime.0=2d 21:15:55.38 snmpTrapOID.0=1.3.6.1.2 .1.33.2.0.4 upsAlarmId=12 upsAlarmDescr=UPS-MIBupsAlarmInputBad snmpTrapEn terprise.0=upsTraps SNMP trap from 172.16.1.5: sysUpTime.0=2d 21:15:55.50 snmpTrapOID.0=PowerNet- MIBpowerRestored smartUPS700=49:4E:46:4F:52:4D:41:54:49:4F:4E:3A:20:4E:6F:72: 6D:61:6C:20:70:6F:77:65:72:20:68:61:73:20:62:65:65:6E:20:72:65:73:74:6F:72:65:6 4 146 :20:74:6F:20:74:68:65:20:55:50:53:20:6F:6E:20:73:65:72:69:61:6C:20:70:6F:72:74: 2 0:31:2E snmpTrapEnterprise.0=apc From this example, you can see a sequence of traps as the power is lost and restored. Most messages should be self-explanatory, and all are explained in the UPS documentation. Generating traps is much simpler. In this example, a session is started and a trap is sent to that session: set u [snmp session -port 162 -address 172.16.2.234] snmp2 u trap coldStart You can terminate a session without exiting scotty with the destroy command: u destroy If you are thinking about writing Tcl scripts, this should give you an idea of the power of the tnm extensions supplied by scotty. If you arent familiar with the syntax of Tcl, these examples will seem fairly opaque but should give you an idea of what is possible. You could try these on your system as presented here, but if you are really interested is doing this sort of thing, youll probably want to learn some Tcl first. Several sources of information are given in Appendix B .

7.2.3 tkined