Skip to content

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
maddingue committed Jun 16, 2011
0 parents commit 4c2642d
Show file tree
Hide file tree
Showing 13 changed files with 537 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitignore
@@ -0,0 +1,13 @@
blib*
Makefile
Makefile.old
Build
Build.bat
_build*
pm_to_blib*
*.tar.gz
.lwpcookies
cover_db
pod2htm*.tmp
POE-Component-NetSNMP-agent-*
.*.swp
22 changes: 22 additions & 0 deletions Build.PL
@@ -0,0 +1,22 @@
#!/usr/bin/perl
use strict;
use warnings;
use Module::Build;

my $builder = Module::Build->new(
module_name => 'POE::Component::NetSNMP::agent',
license => 'perl',
dist_author => 'Sebastien Aperghis-Tramoni <sebastien@aperghis.net>',
dist_version_from => 'lib/POE/Component/NetSNMP/agent.pm',
requires => {
'NetSNMP::agent' => 0,
'POE' => 0,
'SNMP' => 0,
},
build_requires => {
'Test::More' => 0,
},
add_to_cleanup => [ 'POE-Component-NetSNMP-agent-*' ],
);

$builder->create_build_script();
5 changes: 5 additions & 0 deletions Changes
@@ -0,0 +1,5 @@
Revision history for POE-Component-NetSNMP-agent

0.100 2011.06.xx (SAPER)
First version, released on an unsuspecting world.

10 changes: 10 additions & 0 deletions MANIFEST
@@ -0,0 +1,10 @@
MANIFEST
Build.PL
Makefile.PL
README
Changes
lib/POE/Component/NetSNMP/agent.pm
t/00-load.t
t/90-pod.t
t/91-pod-coverage.t
t/95-manifest.t
24 changes: 24 additions & 0 deletions Makefile.PL
@@ -0,0 +1,24 @@
#!/usr/bin/perl
use strict;
use warnings;
use ExtUtils::MakeMaker;

WriteMakefile(
NAME => 'POE::Component::NetSNMP::agent',
LICENSE => 'perl',
AUTHOR => 'Sebastien Aperghis-Tramoni <sebastien@aperghis.net>',
VERSION_FROM => 'lib/POE/Component/NetSNMP/agent.pm',
ABSTRACT_FROM => 'lib/POE/Component/NetSNMP/agent.pm',
PREREQ_PM => {
# prereqs
'NetSNMP::agent' => 0,
'POE' => 0,
'SNMP' => 0,

# build/test prereqs
'Test::More' => 0,
},
PL_FILES => {},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'POE-Component-NetSNMP-agent-*' },
);
65 changes: 65 additions & 0 deletions README
@@ -0,0 +1,65 @@
NAME

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


DESCRIPTION

This module is a thin wrapper around "NetSNMP::agent" to use it within a
"POE"-based program.


INSTALLATION

To install this module, run the following commands:

perl Makefile.PL
make
make test
make install

Alternatively, to install with Module::Build, you can use the
following commands:

perl Build.PL
./Build
./Build test
./Build install


SUPPORT

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

perldoc POE::Component::NetSNMP::agent

You can also look for information at:

* RT: CPAN's request tracker (report bugs here)
https://rt.cpan.org/Public/Dist/Display.html?Name=POE-Component-NetSNMP-agent

* AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/POE-Component-NetSNMP-agent

* CPAN Ratings
http://cpanratings.perl.org/d/POE-Component-NetSNMP-agent

* Search CPAN
http://search.cpan.org/dist/POE-Component-NetSNMP-agent/


AUTHOR

Sebastien Aperghis-Tramoni "<sebastien at aperghis.net>"


LICENSE AND COPYRIGHT

Copyright 2011 Sebastien 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.

42 changes: 42 additions & 0 deletions eg/synopsis-coreref
@@ -0,0 +1,42 @@
#!/usr/bin/perl
use strict;
use NetSNMP::agent;
use NetSNMP::ASN;
use POE qw< Component::NetSNMP::agent >;


use constant {
AGENT_OID => "1.3.6.1.4.1.32272",
};

POE::Component::NetSNMP::agent->spawn(
Alias => "snmp_agent",
AgentOID => AGENT_OID,
AgentX => 1,
Callback => \&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 pure NetSNMP::agent callback
my $mode = $request_info->getMode;

for (my $request = $requests; $request; $request = $request->next) {
if ($mode == MODE_GET) {
$request->setValue(ASN_OCTET_STR, "hello");
}
elsif ($mode == MODE_GETNEXT) {
$request->setOID(AGENT_OID.".1");
$request->setValue(ASN_OCTET_STR, "hello");
}
else {
# ...
}
}
}

51 changes: 51 additions & 0 deletions eg/synopsis-events
@@ -0,0 +1,51 @@
#!/usr/bin/perl
use strict;
use NetSNMP::agent;
use NetSNMP::ASN;
use POE qw< Component::NetSNMP::agent >;


use constant {
AGENT_OID => "1.3.6.1.4.1.32272",
};

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

POE::Session->create(
inline_states => {
_start => sub {
$_[KERNEL]->post($agent => register => "agent_handler");
},
agent_handler => \&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 pure NetSNMP::agent callback
my $mode = $request_info->getMode;

for (my $request = $requests; $request; $request = $request->next) {
if ($mode == MODE_GET) {
$request->setValue(ASN_OCTET_STR, "hello");
}
elsif ($mode == MODE_GETNEXT) {
$request->setOID(AGENT_OID.".1");
$request->setValue(ASN_OCTET_STR, "hello");
}
else {
# ...
}
}
}

0 comments on commit 4c2642d

Please sign in to comment.