Hello Dave,

Thanks for your response, I think perhaps there is an issue with the way in
which I am registering my plugin modules.  After looking over you response
and comparing my original version vs my new version, I don't think I am even
getting that far in my program execution.

When I execute:
    snmpget -v 1 -c debug localhost .1.3.6.1.4.1.38007.0.0.0

I receive the error:
    Error in packet
    Reason: (noSuchName) There is no such variable name in this MIB.
    Failed object: SNMPv2-SMI::enterprises.38007.0.0.0

Even though it is creating the new OID object:

    RegOID: enterprises.38007.0.0.0

    Dumper: $VAR1 = bless( {
                 'plugin_oid' => '0.0.0,
                 'reg_oid' => bless( {
                                     'oidptr' => bless( do{\(my $o =
'47058369330256')}, 'netsnmp_oidPtr' )
                                   }, 'NetSNMP::OID' ),
                 'name' => 'Plugin',
                 'root_oid' => '.1.3.6.1.4.1.38007.',
                 'full_name' => 'Plugin',
                 'full_oid' => '.1.3.6.1.4.1.38007.0.0.0'
               }, 'Plugin' );

Here I've written a stripped down version that skips loading the plugins,
but instead creates the monitor as an object:

#!/usr/bin/perl

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

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


package Plugin;
use NetSNMP::ASN     (':all');

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

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

    my $self = {
        name        => 'Plugin',
        full_name   => $class,
        root_oid    => '.1.3.6.1.4.1.38007.',
        plugin_oid  => '',
        full_oid    => '',
        reg_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;
}

sub set_plugin_oid {'0.0.0'};

# 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);
}

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

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

    for($request = $requests; $request; $request = $request->next()) {
        print STDERR "In the handler";
        $request->setValue(ASN_OCTET_STR, "Test Successful");
    }

}

package main;

my $plugin = Plugin->new();

my $reg_oid = new NetSNMP::OID($plugin->full_oid);
$plugin->reg_oid($reg_oid);
print STDERR "reg_oid: " . $plugin->reg_oid . " Root: " . $plugin->full_oid
. "\n";

$agent->register($plugin->name, $plugin->reg_oid, $plugin->monitor);
1;
__END__

Am I just totally barking up the wrong tree here?

On Thu, Sep 15, 2011 at 2:16 AM, Dave Shield <d.t.shi...@liverpool.ac.uk>wrote:

> On 14 September 2011 18:30, Jon Jon <mailing.list.vie...@gmail.com> wrote:
> >     my ($handler, $registration_info, $request_info, $requests) = @_;
> >
> >     my $this_request = $request->next();
>
>
>
> > 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.
>
> That sounds right.
> The handler routine is passed a variable that you have called
> 'requests'   (plural)
> but you are trying to dereference a variable called 'request'  (singular)
> This second variable has not been initialised, so will indeed be undefined.
>
> The normal code framework would look something like
>
>     my ($handler, $registration_info, $request_info, $requests) = @_;
>
>      for ( $this_request = $requests;   $this_request;
> $this_request=$this_request->next()) {
>         # do something with $this_request
>     }
>
> to handle the possibility of being passed several varbinds to process in
> one go.
>
> Your example code looks to be trying to set a value for the *second*
> varbind
> in the request list,  which will obviously fail if there is only one
> (the most common case)
>
> Dave
>
------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
_______________________________________________
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