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).

[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
Here is my script I am working on (this is a stripped down test version I am using while I work out this issue):
#!/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);

In reply to SNMP OID Registration Error by PyrexKidd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.