PyrexKidd has asked for the wisdom of the Perl Monks concerning the following question:
Hello All,
I am having difficulty registering OIDs to method calls of objects. (See the example Below).
I am able to register method calls to methods in the same package (Test 1 and 2). However, when I attempt to register the method directly (test 3), SNMP is not passing the parameters to the method.
Here are the commands I am using and the errors I see. I have SNMP configured to respond to the 'debug' community on localhost only, YMMV (or YConfigurationMV).
Here is my script I am working on (this is a stripped down test version I am using while I work out this issue):[root@elara trunk]# snmpget -v 1 -c debug localhost .1.3.6.1.4.1.99999 +9.1 SNMPv2-SMI::enterprises.999999.1 = STRING: "Package OID Test Successfu +l" [root@elara trunk]# snmpget -v 1 -c debug localhost .1.3.6.1.4.1.99999 +9.2 SNMPv2-SMI::enterprises.999999.2 = STRING: "Object Method Test Success +ful" [root@elara trunk]# snmpget -v 1 -c debug localhost .1.3.6.1.4.1.99999 +9.3 Error in packet Reason: (noSuchName) There is no such variable name in this MIB. Failed object: SNMPv2-SMI::enterprises.999999.3
#!/usr/bin/perl # use common::sense; package Test; use NetSNMP::ASN (':all'); sub new { my $obj_class = shift; my $root_oid = shift; my $class = ref $obj_class || $obj_class; my $self = {}; bless $self, $class; return $self; } sub monitor { use Data::Dumper; print STDOUT Dumper @_; my ($self, $handler, $registration_info, $request_info, $requests) + = @_; my $request; for($request = $requests; $request; $request = $request->next()) { $request->setValue(ASN_OCTET_STR, "Object Method Test Successf +ul"); } } package main; # Global Vars: our $agent; # Private vars my $root_oid = '.1.3.6.1.4.1.999999'; my $running; # set to 1 to get debugging information my $debugging = 0; # since we're embedded, set this to 0 my $subagent = 0; use NetSNMP::OID (':all'); use NetSNMP::agent (':all'); use NetSNMP::ASN (':all'); #Test 1 my $reg_oid1 = new NetSNMP::OID($root_oid . ".1"); $agent->register('test1', $reg_oid1, \&test1); sub test1 { use Data::Dumper; print STDOUT Dumper @_; my ($handler, $registration_info, $request_info, $requests) = @_; my $request; for($request = $requests; $request; $request = $request->next()) { $request->setValue(ASN_OCTET_STR, "Package OID Test Successful +"); } } # Test 2 my $test = new Test; my $reg_oid2 = new NetSNMP::OID($root_oid . ".2"); # this works $agent->register('test2', $reg_oid2, \&test2); sub test2 { use Data::Dumper; print STDOUT @_; $test->monitor(@_); } #Test 3: #this does not work my $reg_oid3 = new NetSNMP::OID($root_oid . ".3"); $agent->register('test3', $reg_oid3, $test->monitor);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SNMP OID Registration Error
by zengargoyle (Deacon) on Sep 19, 2011 at 11:58 UTC | |
by PyrexKidd (Monk) on Sep 19, 2011 at 15:29 UTC |