NAME
POE::Component::SNMP::Session - Wrap Net-SNMP's SNMP::Session in POE
VERSION
Version 0.08
SYNOPSIS
This module wraps the SNMP module from the net-snmp project within POE's non-blocking event loop, to perform asynchronous SNMP requests.
use POE qw/Component::SNMP::Session/;
POE::Component::SNMP::Session->create();
...
NOTE: this is NOT compatible with the Net::SNMP module by David Town. See POE::Component::SNMP for an async interface to Net::SNMP.
CREATING SNMP COMPONENTS
- create - create an SNMP session
-
The constructor takes the same arguments as the SNMP::Session module, with one addition.
- Alias
-
the Alias parameter specifies the POE session alias the component will receive. If this parameter is not supplied, the default value is 'snmp'. Be careful of creating duplicate sessions! Depending on your environment, POE might throw an error, or it might not. So don't do that.
- DestHost
-
This parameter is technically optional, and defaults to 'localhost', but you really should set it. Also, this parameter name is Case Sensitive, so it must be supplied in mixed case as shown here.
All other parameters are passed through to SNMP::Session untouched.
NOTE: SNMPv3 session creation blocks until authorization completes. This means that if your DestHost doesn't respond, your program will block for Timeout microseconds (default 1s). Also, if authentication fails, the constructor will fail, so it is important to check the return value of
create()
in this case.
REQUESTS
The requests accept a list of arguments which are passed directly to a SNMP::Session
object. See "SNMP::Session" in SNMP for more information on these arguments.
Requests take the form:
$poe_kernel->post( $component_alias => $request =>
$callback_state => @snmp_args );
The arguments are the component alias, the request type, a callback state in the requesting session, and then any arguments you would pass to the SNMP::Session method of the same name.
- get
-
$poe_kernel->post( snmp => get => $state => [ '.1.3.6.1.2.1.1.3.0' ], # or [ 'sysUptime.0' ], # or [ sysUptime => 0 ], # or [ 'sysUptime' ], );
- getnext
- getbulk
- bulkwalk
- set
-
These are the request types the component knows about. Details on the correct parameters for each request type are in the "SNMP::Session" in SNMP docs.
For sending traps, you should instantiate an SNMP::TrapSession object directly.
- finish
-
Shuts down the component instance (other SNMP sessions are unaffected). Any requests that are still pending will have their respective responses/timeouts delivered, but new requests will be discarded.
CALLBACK STATES
A callback state (a POE event) is invoked when the component either receives a response or timeout. The event receives data in its $_[ARG0]
and $_[ARG1]
parameters.
$_[ARG0]
is an array reference containing: the SNMP::Session
object that the component is using, the alias of the component, and the hostname (DestHost
) the component is communicating with.
$_[ARG0]
is an array reference containing: the response value.
If the response value is defined, it will be a SNMP::VarBindList object containing the SNMP results.
If the response value is undef
, then any error message can be accessed via the SNMP::Session
object as $session->{ErrorStr}.
See "SNMP::Session" in SNMP for details.
AUTHOR
Rob Bloodgood, <rdb at cpan.org>
CAVEATS
SNMPv3 connections automatically send a synchronous (blocking) request to establish authorization. If the request times out (for example if the agent is not responding), the entire program will block for $timeout microseconds. YMMV, but for unreliable or slow connections, you may want to try a smaller timeout value, so you receive a failure more quickly.
BUGS
Please report any bugs or feature requests to bug-snmp-session-poe at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE-Component-SNMP-Session. 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 POE::Component::SNMP::Session
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Component-SNMP-Session
Search CPAN
ACKNOWLEDGEMENTS
COPYRIGHT & LICENSE
Copyright 2007 Rob Bloodgood, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.