Transcription of The Net-SNMP Programming Guide - Cuddletech
1 The Net-SNMP Programming GuideBen RockwoodUpdated: Nov 17th, 2004 Contents1 Introduction to General Overview .. Three Flavors of snmp .. What we won t discuss .. 42 MIBs & OIDs .. MIBs .. OID DataTypes .. MIB-II .. Adding MIBs to Net-SNMP .. 103 The Net-SNMP Probing a device: snmp WALKs .. Polling Individual OIDs: snmp GETs .. Net-SNMP CLI Tool Options .. 134 Polling Simple Polling with PERL .. The Net-SNMP PERL Module .. 165 Trap The Trap Daemon Configuration.
2 A Simple Trap Handler .. Starting the Trap Daemon .. 216 The Net-SNMP C snmp Internals .. Watching snmp on the wire .. A simple example .. Closing Thoughts .. 291 Chapter 1 Introduction to General OverviewSimple Network Management Protocol is asimplemethod of interacting withnetworked devices. The standard was defined by IETF RFC 1157 in May of1990. snmp can often seem quite confusing and overly complicated, its availableAPIs tend to put alot of wrapping around what should be very simple.
3 Theavailable books on the topic tend to only complicate the subject, not is extremely easy for any programmer to understand. A gross oversimplification can explain the system simply. A network device runs an snmp agentas a daemon process which answers requests from the network. The agentprovides a large number ofObject Identifiers(OIDs). An OID is a unique key-value pair. The agent populates these values and makes them available. AnSNMP manager(client) can then query the agents key-value pairs for specificinformation.
4 From a Programming standpoint it s not much different than im-porting a ton of global variables. snmp OIDs can be read or written. Whilewriting information to an snmp device is fairly rare, it is a method used byseveral management applications to control devices (such as an administrativeGUI for your switches). A basic authentication scheme exists in snmp , allowingthe manager to send acommunity name(think cleartext password) to autho-rize reading or writing of OIDs. Most devices use the insecure community name public.
5 snmp communication is preformed via UDP on ports 161 and that I didn t mention MIBs yet! The importance of MIBs aregreatlyoverrated. MIBs look complicated at first, but they are extremely simple. OIDsare numerical and global. An OID looks similar to an IPv6 address and differentvendors have different prefixes and so forth. The OIDs are long enough thatit s complicated for a human to remember or make sense of them, so a methodwas devised for translating a numeric OID into a human readable form. Thistranslation mapping is kept in a portable flat text file called aManagementInformation BaseorMIB.
6 You donotneed a MIB to use snmp or query2 CHAPTER 1. INTRODUCTION TO SNMP3 snmp devices, however without a MIB you ll have to simply guess what thedata your looking at means. In some cases this is easy, such as seeing hostnames, disk usage numbers, or port status information. Other times it can bemore difficult and a MIB is more useful. It is not unusual for some applicationsto be written using strictly numeric IODs allowing the end user to avoid thehassles of properly installing a MIB. The action of installing a MIB is reallyjust putting it in a place where your snmp client application can find it toperform the can be used in 2 ways: polling and means thatyou write an application that sets an snmp GET request to an agent lookingsome value.
7 This method is useful because if the device responds you get theinformation you want and if the device does not respond you know there is aproblem. Polling is an active form of monitoring. On the other hand, snmp trapscan be used for passive monitoring by configuring an agent to contactanother snmp agent when some action at traps deeper, a network device such as a router can be configuredto send snmp traps for certain events. For instance, you can configure CiscoIOS to send traps either when an individual event occurs such as a linkDown(IOS: snmp -server enable traps snmp linkdown) or when any defined trap eventhappens (IOS: snmp -server enable traps snmp ).
8 When a trap event occurs, theagent on the device will send the trap to a pre-configured destination commonlycalled atrap host. The trap host will have it s own agent running which willaccept and process the traps as they come in. The processing of these trapsare done bytrap handlers. Trap Handlers can be written in any language andare provided with information from the sent trap via STDIN. The handler canthen do whatever is appropriate to respond to the trap, such as sending emailor doing anything else you could is most commonly used in conjunction with aNetwork ManagementSystem(NMS).
9 Popular NMS s include BMC Patrol, CA Unicenter, Sun Man-agement Console (formerly SyMon), IBM Tivoli NetView, and the world famousHP OpenView. Even an Open Source NMS is now available, the aptly namedOpenNMS. The goal of a NMS is to provide a single point of monitoring andadministration of all your snmp enabled devices. By configuring your deviceagents to allow write access you can even manipulate your environment from asingle application. When an environment is architected around a NMS solutionyou can be given unparalleled levels of control and visibility over your entire en-vironment at a glance.
10 While Net-SNMP provides all the tools you would needto build your own NMS we won t discuss the subject any further here. However,bear in mind that if you think the vendor of your snmp enabled device isn t asforthcoming about details of their agent implementation as you d like, it s mostlikely because they would like you to simply buy their NMS or a plug-in to usetheir device with one of the other popular NMS 1. INTRODUCTION TO Three Flavors of SNMPT hree different version of snmp exist: SNMPv1 (RFC s 1155, 1157, and 1212),SNMPv2c (RFC s 1901 through 1908), and SNMPv3 (RFC s 3411 though 3418).