NAME
SNMP::Agent - A simple SNMP AgentX subagent
VERSION
Version 0.03
SYNOPSIS
Eliminates most of the hassle in developing simple SNMP subagents in perl. A list of SNMP OIDs are registered to callbacks that return the data.
FUNCTIONS
new
Get an SNMP::Agent object. See EXAMPLES for use.
run
Called on an SNMP::Agent object with no arguments to start the agent.
EXAMPLES
use SNMP::Agent;
use NetSNMP::ASN qw/ASN_GAUGE/;
sub do_one { return int(rand(10)) }
sub do_two { return "two" }
my $root_oid = '1.3.6.1.4.1.8072.9999.9999.123';
my %handlers = (
'1' => { handler => \&do_one, type => ASN_GAUGE },
'2' => { handler => \&do_two }, # default type ASN_OCTET_STR
);
my $agent = new SNMP::Agent('my_agent', $root_oid, \%handlers);
$agent->run();
Output
With the agent running,
# snmpwalk -v 2c -c public localhost 1.3.6.1.4.1.8072.9999.9999.123
iso.3.6.1.4.1.8072.9999.9999.123.1 = Gauge32: 2
iso.3.6.1.4.1.8072.9999.9999.123.2 = STRING: "two"
NOTES
Callbacks
The callback functions specified to handle OID requests are called for SNMP sets as well as get requests. The requested OID and the request type are passed as arguments to the callback. If the mode is MODE_SET_ACTION there is a third argument, the value to be set.
use NetSNMP::agent qw(MODE_SET_ACTION);
my $persistent_val = 0;
sub do_one
{
my ($oid, $mode, $value) = @_;
if ($mode == MODE_SET_ACTION)
{
$persistent_val = $value;
}
else
{
return $persistent_val;
}
}
Caching
No caching of responses is done by SNMP::Agent. Any results from expensive operations should probably be cached for some time in case of duplicate requests for the same information.
AUTHOR
Alexander Else, <aelse at else.id.au>
BUGS
Please report any bugs or feature requests to bug-snmp-agent at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SNMP-Agent. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
COUNTER64
Strange values are returned for non-zero 64 bit counters. I suspect something in either NetSNMP::agent or communication between it and the snmp daemon. From cursory investigation it does not appear to be a simple endian problem. I may be wrong.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc SNMP::Agent
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
Copyright 2011 Alexander Else.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.