The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

POE::Component::NetSNMP::agent - AgentX clients with NetSNMP::agent and POE

VERSION

Version 0.100

SYNOPSIS

    use NetSNMP::agent;
    use POE qw< Component::NetSNMP::agent >;


    my $agent = POE::Component::NetSNMP::agent->spawn(
        Alias   => "snmp_agent",
        AgentX  => 1,
    );

    $agent->register("1.3.6.1.4.1.32272", \&agent_handler);

    POE::Kernel->run;
    exit;

    sub agent_handler {
        my ($kernel, $heap, $args) = @_[ KERNEL, HEAP, ARG1 ];
        my ($handler, $reg_info, $request_info, $requests) = @$args;

        # the rest of the code works like a classic NetSNMP::agent callback
        my $mode = $request_info->getMode;

        for (my $request = $requests; $request; $request = $request->next) {
            if ($mode == MODE_GET) {
                # ...
            }
            elsif ($mode == MODE_GETNEXT) {
                # ...
            }
            else {
                # ...
            }
        }
    }

See also in eg/ for more ready-to-use examples.

DESCRIPTION

This module is a thin wrapper around NetSNMP::agent to use it within a POE-based program. Its usage is mostly the same:

  • spwan a session object

  • register one or more OIDs with associated callbacks (either via the object method or via the POE event, as you see fit)

METHODS

spawn

Create and return a POE session for handling NetSNMP requests.

NetSNMP::agent options

  • Name - (optional) sets the agent name, defaulting to "perl". The underlying library will try to read a $name.conf Net-SNMP configuration file.

  • AgentX - (optional) be a sub-agent (0 = false, 1 = true). The Net-SNMP master agent must be running first.

  • Ports - (optional) sets the ports this agent will listen on (e.g.: "udp:161,tcp:161").

POE options

  • Alias - (optional) sets the session alias

  • Errback - (optional) sets the error callback.

Example:

    my $agent = POE::Component::NetSNMP::agent->spawn(
        Alias   => "snmp_agent",
        AgentX  => 1,
    );

register

Register a callback handler for a given OID.

Arguments:

1. (mandatory) OID to register
2. (mandatory) request handler callback; must be a coderef

Example:

    $agent->register("1.3.6.1.4.1.32272.1", \&tree_1_handler);
    $agent->register("1.3.6.1.4.1.32272.2", \&tree_2_handler);

POE EVENTS

register

Register a callback handler for a given OID.

Arguments:

ARG0: (mandatory) OID to register
ARG1: (mandatory) request handler callback; must be an event name or a coderef

Example:

    POE::Kernel->post($agent, register => "1.3.6.1.4.1.32272.1", "tree_1_handler");
    POE::Kernel->post($agent, register => "1.3.6.1.4.1.32272.2", "tree_2_handler");

SEE ALSO

POE, http://poe.perl.org/

NetSNMP::agent, NetSNMP::ASN, NetSNMP::OID

Net-SNMP web site: http://www.net-snmp.org/

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc POE::Component::NetSNMP::agent

You can also look for information at:

BUGS

Please report any bugs or feature requests to bug-poe-component-netsnmp-agent at rt.cpan.org, or through the web interface at https://rt.cpan.org/Public/Dist/Display.html?Name=POE-Component-NetSNMP-agent. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

ACKNOWLEDGEMENTS

Thanks to Rocco Caputo and Rob Bloodgood for their help on #poe.

AUTHOR

Sébastien Aperghis-Tramoni <sebastien at aperghis.net>

LICENSE AND COPYRIGHT

Copyright 2011 Sébastien Aperghis-Tramoni.

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.