Skip to Main Content
Essential SNMP, 2nd Edition
book

Essential SNMP, 2nd Edition

by Douglas Mauro, Kevin Schmidt
September 2005
Beginner content levelBeginner
462 pages
12h 56m
English
O'Reilly Media, Inc.
Content preview from Essential SNMP, 2nd Edition

Simple SNMP Agent

Traditional SNMP agents typically give you all the monitoring and management features you could want. Sometimes you may wish you could write your own SNMP agent. Anyone who has looked at the Net-SNMP agent code knows how complex it is. Well, have no fear! The Net-SNMP package now comes with Perl bindings that allow you to create a Perl SNMP agent in a number of ways:

  • Standalone SNMP agent

  • AgentX subagent

  • Embedded agent within the normal Net-SNMP agent

For this section, we thought it would be interesting to present a fully working Perl agent. This isn't so much to write yet another SNMP agent but rather to show how an SNMP agent operates.

The basic flow through the agent is as follows:

  1. Create a new agent object

  2. Register the top of the agent's OID tree

  3. Register a callback subroutine

  4. Sit and wait for requests

It's pretty straightforward, and so is the code itself. First things first, though. You need to get a copy of the Net-SNMP package from http://www.net-snmp.org. Follow the instructions for building and installing the package and Perl modules.

The complete agent source follows:

205 #!/usr/bin/perl 206 207 # 208 # File: agent.pl 209 # 210 211 use NetSNMP::agent (':all'); 212 use NetSNMP::default_store (':all'); 213 use NetSNMP::ASN (':all'); 214 use NetSNMP::OID; 215 use SNMP; 216 217 my $port = "9161"; 218 my $host = ".1.3.6.1.4.1.8072.25"; 219 my $hrMemorySize = $host.".2.2"; 220 221 sub myHandler{ 222 my ($handler, $registration_info, $request_info, $requests) = @_; 223 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Essential SNMP

Essential SNMP

Douglas Mauro, Kevin Schmidt
UNIX and Linux System Administration Handbook, 5th Edition

UNIX and Linux System Administration Handbook, 5th Edition

Trent R. Hein, Evi Nemeth, Garth Snyder, Ben Whaley, Dan Mackin

Publisher Resources

ISBN: 0596008406Supplemental ContentErrata Page