NAME
SNMP::Agent - A simple SNMP AgentX subagent
VERSION
Version 0.01
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.
Example Code
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 BP::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.
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.