Hello All,

I am not sure if this is really the right place to ask, if it isn't could
you please point me to the right place to ask?

Anyway, I am working on building a Perl based pluggable architecture for my
custom SNMP monitors.
The problem I am having is registering my OIDs and their related sub
routines.

Here are the vitals:
OS:  Centos 5.X
Perl: 5.8.8
SNMP: 5.3.2.2
NetSNMP:  v5.0301002
SNMP Modules:  v5.0301

(I have been unable to get recent versions of NetSNMP to compile on CentOS,
using 5.3.1 was the easiest solution to be able to use this script cross
platform)

Here is how I have my application setup.  Each package is an independent
file.

Listing:  ./snmp_monitor.pl
#!/usr/bin/perl

use common::sense;
use NetSNMP::OID     (':all');
use NetSNMP::agent     (':all');
use NetSNMP::ASN     (':all');

use lib '/root/snmp_monitor/trunk';

use SNMPMonitor;
use SNMPMonitor::Plugin;

our $agent = new NetSNMP::agent(
                'dont_init_agent' => 1,
                'dont_init_lib' => 1
      );

# Private vars
my $root_oid = '.1.3.6.1.4.1.99999.';
my $running;

# since we're embedded, set this to 0
my $subagent = 0;

my $reg_oid = new NetSNMP::OID($root_oid);

my $monitor = SNMPMonitor->new;

my @plugins = $monitor->plugins();

print STDERR "\nFound Plugins: \n";
print STDERR "Plugin: $_ \n" foreach @plugins;
print STDERR "\n";

$_->new($root_oid) foreach @plugins;

foreach my $obj (@plugins) {
    print STDERR "Full Name: " . $obj->full_name . "\n";
    print STDERR "Name: " . $obj->name . "\n";
    print STDERR "OID: " . $obj->plugin_oid . "\n";
    print STDERR "Root OID: " . $obj->root_oid . "\n";
    print STDERR "Full OID: " . $obj->full_oid . "\n\n";
}

foreach my $plugin (@plugins)
    $agent->register($plugin->name, $plugin->full_oid, \$plugin->monitor(),
);
}
__END__

Listing: ./SNMPMonitor.pm
package SNMPMonitor;

use Module::Pluggable require => 1;

sub new {
    my $class = shift;
    my $self = {};
    bless $self, $class;
}
1;
__END__


Listing: ./SNMPMonitor/Plugin.pm
package SNMPMonitor::Plugin;

sub new {
    my $obj_class      = shift;
    my $root_oid        = shift;

    my $class = ref $obj_class || $obj_class;
    my ($name) = $class =~ /::Plugin::(.*)/;

    my $self = {
        name        => $name,
        full_name   => $class,
        root_oid    => $root_oid,
        plugin_oid  => '',
        full_oid    => '',
    };

    bless $self, $class;

    # create accessor methods for defined parameters
    for my $datum (keys %{$self}) {
        no strict "refs";
        *$datum = sub {
            shift; # XXX: ignore calling class/object
            $self->{$datum} = shift if @_;
            return $self->{$datum};
        };
    }


    $self->set_oid();

    return $self;
}

# Set the OID using plugin defined OID.
sub set_oid {
    my $self = shift;
    $self->plugin_oid($self->set_plugin_oid);
    $self->full_oid($self->root_oid . $self->plugin_oid);
}

1;
__END__

Listing: ./SNMPMonitor/Plugin/Atest.pm
package SNMPMonitor::Plugin::Atest;

use common::sense;
use NetSNMP::ASN     (':all');
# use Smart::Comments;

our @ISA = qw(SNMPMonitor::Plugin);

sub set_plugin_oid {'0.0.0'};

sub monitor {
    use Data::Dumper;
    print STDERR Dumper @_;

    my $class = shift;
    my ($handler, $registration_info, $request_info, $requests) = @_;

    my $this_request = $request->next();

    $this_request->setValue(ASN_OCTET_STR, "Test Successful");

}

1;
__END__

When run I get the following error:
Can't call method "next" on an undefined value at
/root/snmp_monitor/trunk/SNMPMonitor/Plugin/Atest.pm line 24.

This is because, the call to $plugin->monitor() is not passing anything but
the object name as evidenced by dump of @_ when it is called:

     $VAR1 = 'SNMPMonitor::Plugin::Atest';


Originally, when I wrote (this application)[http://pastebin.com/uiHVQthf], I
wrote it to monitor one OID and followed the NetSNMP tutorial.
A couple of additions later however, and I am ready to redesign how plugins
are built.

Essentially, I would like to follow (this)[http://i.imgur.com/oQXav.png]
layout.

I think my issue is how I am registering my OIDs.  In the original I
registered every thing to the agent, then entered a for loop.

   my $reg_oid = new NetSNMP::OID($root_oid);
  print STDERR "registering at ",$reg_oid,"\n" if $debugging;
  # we register ourselves with the master agent we're embedded in.
  $agent->register('exim_queue_monitor', $reg_oid, \&exim_queue_monitor, );
  Sub exim_queue_monitor {
    for($request = $requests; $request; $request = $request->next()) {

       }
    }

But in the new version I am not entering any type of 'event' loop.  Could
this be my issue?  How would I correctly implement this?  I would like to
snmpwalk these new OIDs, is this something that can be done pragmatically
and should it be part of this step (I'd prefer not to confuse the issue,
however, if it is easier to implement now then when I have 100K

Any other thoughts about implementation or design are greatly appreciated
also.  Someone else recommended I use Moose, but I am not sure that adding
another completely new concept to the mix would be productive at this point.

Thanks in advance for any help.
------------------------------------------------------------------------------
BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
Learn about the latest advances in developing for the 
BlackBerry® mobile platform with sessions, labs & more.
See new tools and technologies. Register for BlackBerry® DevCon today!
http://p.sf.net/sfu/rim-devcon-copy1 
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users

Reply via email to