This is weird.  Probably best if I just show you what I did, what I saw, and 
what I expected to see…

I’m running an Ubuntu 14.04 LTS server with Net-SNMP version 5.7.2.  I’ve also 
installed Lubuntu desktop to give me a lightweight GUI environment.

My /etc/snmp/snmptrapd.conf file contains this:-
—————————————————————————————————————————— 
authCommunity log,execute,net public
perl do "/usr/share/snmp/traphandlers/default_handler.pl";
—————————————————————————————————————————— 

and the default_handler.pl file contains this:-
—————————————————————————————————————————— 
#!/usr/bin/perl

use strict;
use warnings;
use SNMP;

sub trap_receiver {
    my ($pdu, $vars) = @_;

    print "VARBINDS:\n";

    foreach (@{$vars}) {
        my ($oid, $value, $type) = @$_;
        print "$oid = $value ($type)\n";
    }

    print "\nSNMP::MIB info for VARBINDS:\n";

    foreach (@{$vars}) {
        my ($oid, $value, $type) = @$_;

        if ($oid =~ /^(.*)\.[0-9]+$/) {
            print "$oid parent label = $SNMP::MIB{$1}->{label}\n";
        } else {
            print "$oid has no instance index\n";
        }
    }

    return NETSNMPTRAPD_HANDLER_OK;
}

unless (NetSNMP::TrapReceiver::register("all", \&trap_receiver)) {
    warn "Failed to register default Perl traphandler\n";
} else {
    warn "Registered default Perl traphandler\n";
}
—————————————————————————————————————————— 

now I run “sudo snmptrapd -Le -f -m ALL” to get the trap daemon running in test 
mode (it isn’t running from init) and then inject a test trap with “snmptrap -v 
2c -c public localhost '' SNMPv2-MIB::coldStart SNMPv2-MIB::sysLocation.0 s 
'Just here’” from a separate terminal window.

Here’s the output I get:-
—————————————————————————————————————————— 
2014-12-03 22:57:32 localhost [UDP: [127.0.0.1]:44173->[127.0.0.1]:162]:
DISMAN-EXPRESSION-MIB::sysUpTimeInstance = Timeticks: (2677185) 7:26:11.85      
SNMPv2-MIB::snmpTrapOID.0 = OID: SNMPv2-MIB::coldStart  
SNMPv2-MIB::sysLocation.0 = STRING: Just here
VARBINDS:
DISMAN-EXPRESSION-MIB::sysUpTimeInstance = Timeticks: (2677185) 7:26:11.85 (67)
SNMPv2-MIB::snmpTrapOID.0 = OID: SNMPv2-MIB::coldStart (6)
SNMPv2-MIB::sysLocation.0 = STRING: "Just here" (4)

SNMP::MIB info for VARBINDS:
DISMAN-EXPRESSION-MIB::sysUpTimeInstance has no instance index
SNMPv2-MIB::snmpTrapOID.0 parent label = snmpTrapOID
sysLocation.0 parent label = sysLocation
 perl callback function 0x882ee04 returns 1
—————————————————————————————————————————— 

Everything looks okay, with the stuff from my Perl script matching what’s come 
from SNMP’s built-in logging, except that "sysLocation.0” is missing its 
"SNMPv2-MIB::” module id on the line before last.  This is the weird thing.  
What caused the stringification of the blessed OID object to change?

Leaving snmptrapd running, run the snmptrap command again to inject exactly the 
same trap message.  This time the output is:-
—————————————————————————————————————————— 
2014-12-03 23:06:35 localhost [UDP: [127.0.0.1]:37609->[127.0.0.1]:162]:
sysUpTimeInstance 0:7:35:14.59  snmpTrapOID.0 coldStart sysLocation.0 Just here
VARBINDS:
sysUpTimeInstance = 0:7:35:14.59 (67)
snmpTrapOID.0 = coldStart (6)
sysLocation.0 = "Just here" (4)

SNMP::MIB info for VARBINDS:
sysUpTimeInstance has no instance index
snmpTrapOID.0 parent label = snmpTrapOID
sysLocation.0 parent label = sysLocation
 perl callback function 0x882ee04 returns 1

—————————————————————————————————————————— 

This time around the module name is missing from the snmptrapd standard logging 
as well as from ALL the Perl script output, so the problem is deeper than the 
Perl layer.  Somehow, accessing %SNMP::MIB has affected the underlying Net-SNMP 
C library.

The line that causes the damage is 'print "$oid parent label = 
$SNMP::MIB{$1}->{label}\n”;’ when called for SNMPv2-MIB::snmpTrapOID.0, which 
is the very first time the tied hash is called, so something in the code from 
that point changes the setting that tells the library whether to include the 
module id in the OID name.

Can someone please give this a try and tell the list whether you can reproduce 
my observations?  Can someone tell me what to do to avoid this behaviour?  As 
you can imagine, this is seriously hampering my trap handler development as my 
callback function needs the module name and oid for each varbind in the trap 
message in order to correctly process it.

Many thanks for your help!
Kevin
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
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