Thanks for the additional information. Happy to see someone using my
module. Sorry it doesn't seem to be working as you wish.
I think the issue may be in the SNMP module. I don't have that installed,
I use Net::SNMP instead. Making slight modification to the code you
provided:
----
use strict;
use warnings;
use Net::SNMPTrapd;
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
#use SNMP;
my $snmptrapd = Net::SNMPTrapd->new();
request_loop();
sub request_loop {
while (1) {
my $trap = $snmptrapd->get_trap();
my %varbinds = ();
if (!defined($trap)) {
printf "$0: %s\n", Net::SNMPTrapd->error;
exit 1
} elsif ($trap == 0) {
next
}
my %SNMP_MIB;
if (!defined($trap->process_trap())) {
printf "$0: %s\n", Net::SNMPTrapd->error
} else {
foreach my $element (@{$trap->varbinds}) {
while ( my ($key, $value) = each(%$element) ) {
#$varbinds{$SNMP_MIB{$key}} = $value;
print "$value\n";
}
}
}
print Dumper($trap->varbinds);
}
}
----
Instead of assigning to the %varbinds hash in your foreach loop, I'm just
printing the value returned from Net::SNMPTrapd parsing. when called with:
Show quoted text> snmptrapd-sendtest.pl -t 3460354946
The program above outputs:
1
String
☺☻♥♦♣♠
1.2.3.4.5.6.7.8.9
10.10.10.1
32323232
42424242
3460354946
opaque data
(NULL)
$VAR1 = [
{
'1.3.6.1.4.1.50000.1.3' => 1
},
{
'1.3.6.1.4.1.50000.1.4' => 'String'
},
{
'1.3.6.1.4.1.50000.1.5' => '☺☻♥♦'♠
},
{
'1.3.6.1.4.1.50000.1.6' => '1.2.3.4.5.6.7.8.9'
},
{
'1.3.6.1.4.1.50000.1.7' => '10.10.10.1'
},
{
'1.3.6.1.4.1.50000.1.8' => 32323232
},
{
'1.3.6.1.4.1.50000.1.9' => 42424242
},
{
'1.3.6.1.4.1.50000.1.10' => bless( {
'sign' => '+',
'value' => [
460354946,
3
]
}, 'Math::BigInt' )
},
{
'1.3.6.1.4.1.50000.1.11' => 'opaque data'
},
{
'1.3.6.1.4.1.50000.1.12' => '(NULL)'
}
];
You'll see printing the value results in the correct output (3460354946)
seen above the string "opaque data" before the Data::Dumper output. The
Data::Dumper output is recursing through each item and the timeticks
appears to be a Math::BigInt so you see that as Data::Dumper output.
Simply printing the varbinds values works fine and you should see that by
using your input against the provided 'snmptrapd-simple.pl' script supplied
with the Net::SNMPTrapd module.
If you're getting an error in the script you're using with the SNMP module,
I suggest running the input against the provided 'snmptrapd-simple.pl'
script supplied with the Net::SNMPTrapd module and seeing if it produces
the correct output. If it does, (which it does for me), it may be in the
way the SNMP module is handling the %SNMP::MIB feature and the input
(Math::BigInt) to that call / hash variable.
Cheers.
On Fri, Jun 24, 2016 at 4:54 PM, Diger via RT <bug-Net-SNMPTrapd@rt.cpan.org
Show quoted text> wrote:
Show quoted text> Queue: Net-SNMPTrapd
> Ticket <URL:
https://rt.cpan.org/Ticket/Display.html?id=115574 >
>
> Michael Vincent via RT писал 2016-06-24 17:07:
> > <URL:
https://rt.cpan.org/Ticket/Display.html?id=115574 >
> >
> > As I can't duplicate this, I will need much more information:
> > - Net::SNMPTrapd version
> > - Perl version and type (32-bit / 64-bit)
> > - The code you're running that produces the error
> > - The actual received trap (either PCAP dump file or hexstring
> > equivalent of the trap data will do
> >
> > I cannot reproduce using the included scripts:
> >
> >> snmptrapd-sendtest -t 3460354946
> >
> > And output from snmptrapd-simple
> >
> >> snmptrapd-simple
> > Listening on 0.0.0.0:162
> > 1466768506 127.0.0.1 56997 1 public Trap
> > 1.3.6.1.4.1.5000
> > 0 127.0.0.1 ENTERPRISESPECIFIC 1 1466768506
> > 1.3.6.1.
> > 4.1.50000.1.3: 1; 1.3.6.1.4.1.50000.1.4: String; 1.3.6.1.4.1.50000.1.5:
> > 0x010203
> > 0405060708; 1.3.6.1.4.1.50000.1.6: 1.2.3.4.5.6.7.8.9;
> > 1.3.6.1.4.1.50000.1.7: 10.
> > 10.10.1; 1.3.6.1.4.1.50000.1.8: 32323232; 1.3.6.1.4.1.50000.1.9:
> > 42424242; 1.3.6
> > .1.4.1.50000.1.10: 3460354946; 1.3.6.1.4.1.50000.1.11: opaque data;
> > 1.3.6.1.4.1.
> > 50000.1.12: (NULL);
> >
> > Notice the timetick OID appears correct above "1.3.6.1.4.1.50000.1.10:
> > 3460354946"
> >
> > Likewise, using the -Dump option which does not use any of
> > Net::SNMPTrapd logic; rather, uses the dump routines from
> > Convert::ASN1 produces correct result:
> >
> >> snmptrapd-simple -D
> > Listening on 0.0.0.0:162
> > 0000 256: SEQUENCE {
> > 0004 1: INTEGER = 0
> > 0007 6: STRING = 'public'
> > 000F 242: [CONTEXT 4] {
> > 0012 8: OBJECT ID = 1.3.6.1.4.1.50000
> > 001C 4: [APPLICATION 0]
> > 001E : 7F 00 00 01 __ __ __ __ __ __ __ __ __ __ __ __ ....
> > 0022 1: INTEGER = 6
> > 0025 1: INTEGER = 1
> > 0028 4: [APPLICATION 3]
> > 002A : 57 6D 1D 2A __ __ __ __ __ __ __ __ __ __ __ __ Wm.*
> > 002E 211: SEQUENCE {
> > 0031 15: SEQUENCE {
> > 0033 10: OBJECT ID = 1.3.6.1.4.1.50000.1.3
> > 003F 1: INTEGER = 1
> > 0042 : }
> > 0042 20: SEQUENCE {
> > 0044 10: OBJECT ID = 1.3.6.1.4.1.50000.1.4
> > 0050 6: STRING = 'String'
> > 0058 : }
> > 0058 22: SEQUENCE {
> > 005A 10: OBJECT ID = 1.3.6.1.4.1.50000.1.5
> > 0066 8: STRING
> > 0068 : 01 02 03 04 05 06 07 08 __ __ __ __ __ __ __ __
> > ........
> > 0070 : }
> > 0070 22: SEQUENCE {
> > 0072 10: OBJECT ID = 1.3.6.1.4.1.50000.1.6
> > 007E 8: OBJECT ID = 1.2.3.4.5.6.7.8.9
> > 0088 : }
> > 0088 18: SEQUENCE {
> > 008A 10: OBJECT ID = 1.3.6.1.4.1.50000.1.7
> > 0096 4: [APPLICATION 0]
> > 0098 : 0A 0A 0A 01 __ __ __ __ __ __ __ __ __ __ __ __
> > ....
> > 009C : }
> > 009C 18: SEQUENCE {
> > 009E 10: OBJECT ID = 1.3.6.1.4.1.50000.1.8
> > 00AA 4: [APPLICATION 1]
> > 00AC : 01 ED 36 A0 __ __ __ __ __ __ __ __ __ __ __ __
> > ..6.
> > 00B0 : }
> > 00B0 18: SEQUENCE {
> > 00B2 10: OBJECT ID = 1.3.6.1.4.1.50000.1.9
> > 00BE 4: [APPLICATION 2]
> > 00C0 : 02 87 57 B2 __ __ __ __ __ __ __ __ __ __ __ __
> > ..W.
> > 00C4 : }
> > 00C4 19: SEQUENCE {
> > 00C6 10: OBJECT ID = 1.3.6.1.4.1.50000.1.10
> > 00D2 5: [APPLICATION 3]
> > 00D4 : 00 CE 40 D3 82 __ __ __ __ __ __ __ __ __ __ __
> > ..@..
> > 00D9 : }
> > 00D9 25: SEQUENCE {
> > 00DB 10: OBJECT ID = 1.3.6.1.4.1.50000.1.11
> > 00E7 11: [APPLICATION 4]
> > 00E9 : 6F 70 61 71 75 65 20 64 61 74 61 __ __ __ __ __
> > opaque data
> >
> > 00F4 : }
> > 00F4 14: SEQUENCE {
> > 00F6 10: OBJECT ID = 1.3.6.1.4.1.50000.1.12
> > 0102 0: NULL
> > 0104 : }
> > 0104 : }
> > 0104 : }
> > 0104 : }
> >
> > 30 82 01 00 02 01 00 04 06 70 75 62 6C 69 63 A4 0........public.
> > 81 F2 06 08 2B 06 01 04 01 83 86 50 40 04 7F 00 ....+......P@...
> > 00 01 02 01 06 02 01 01 43 04 57 6D 1D 2A 30 81 ........C.Wm.*0.
> > D3 30 0F 06 0A 2B 06 01 04 01 83 86 50 01 03 02 .0...+......P...
> > 01 01 30 14 06 0A 2B 06 01 04 01 83 86 50 01 04 ..0...+......P..
> > 04 06 53 74 72 69 6E 67 30 16 06 0A 2B 06 01 04 ..String0...+...
> > 01 83 86 50 01 05 04 08 01 02 03 04 05 06 07 08 ...P............
> > 30 16 06 0A 2B 06 01 04 01 83 86 50 01 06 06 08 0...+......P....
> > 2A 03 04 05 06 07 08 09 30 12 06 0A 2B 06 01 04 *.......0...+...
> > 01 83 86 50 01 07 40 04 0A 0A 0A 01 30 12 06 0A ...P..@.....0...
> > 2B 06 01 04 01 83 86 50 01 08 41 04 01 ED 36 A0 +......P..A...6.
> > 30 12 06 0A 2B 06 01 04 01 83 86 50 01 09 42 04 0...+......P..B.
> > 02 87 57 B2 30 13 06 0A 2B 06 01 04 01 83 86 50 ..W.0...+......P
> > 01 0A 43 05 00 CE 40 D3 82 30 19 06 0A 2B 06 01 ..C...@..0...+..
> > 04 01 83 86 50 01 0B 44 0B 6F 70 61 71 75 65 20 ....P..D.opaque
> > 64 61 74 61 30 0E 06 0A 2B 06 01 04 01 83 86 50 data0...+......P
> > 01 0C 05 00 __ __ __ __ __ __ __ __ __ __ __ __ ....
> >
> >
> > Again, from above:
> >
> > OBJECT ID = 1.3.6.1.4.1.50000.1.10
> > [APPLICATION 3]
> > 00 CE 40 D3 82
> >
> > Hex 00CE40D382 = 3460354946
> >
> > It may be that your Math::BigInt is not working properly or you aren't
> > using it correctly.
> >
> > The numbers you provided in the ticket don't match:
> >
> > ----
> > use Math::BigInt;
> > my $x = Math::BigInt->new('3460354946');
> > use Data::Dumper; $Data::Dumper::Sortkeys=1; print Dumper \$x;
> > print $x->bstr;
> > ----
> >
> > Output:
> >
> > $VAR1 = \bless( {
> > 'sign' => '+',
> > 'value' => [
> > '460354946',
> > '3'
> > ]
> > }, 'Math::BigInt' );
> > 3460354946
> >
> >
> > Notice my "value" in the dump from Math::BigInt does not match yours.
> > And if I correct the "value", my input / output number is not the
> > timeticks you provided:
> >
> > ----
> > use Math::BigInt;
> > my $y = bless( {
> > 'sign' => '+',
> > 'value' => [
> > '460196709',
> > '3'
> > ]
> > }, 'Math::BigInt' );
> > print $y->bstr;
> > ----
> >
> > Output:
> >
> > 3460196709
> perl -v
>
> This is perl 5, version 20, subversion 3 (v5.20.3) built for
> amd64-freebsd-thread-multi
> Net-SNMPTrapd-0.16
>
> use Net::SNMPTrapd;
> use Data::Dumper;
> $Data::Dumper::Sortkeys = 1;
> use SNMP;
> ====
> ====
> sub request_loop {
> while (1) {
> my $trap = $snmptrapd->get_trap();
> my %varbinds = ();
>
> if (!defined($trap)) {
> printf "$0: %s\n", Net::SNMPTrapd->error;
> exit 1
> } elsif ($trap == 0) {
> next
> }
>
> if (!defined($trap->process_trap())) {
> printf "$0: %s\n", Net::SNMPTrapd->error
> } else {
> foreach my $element (@{$trap->varbinds}) {
> while ( my ($key, $value) =
> each(%$element) ) {
> $varbinds{$SNMP::MIB{$key}{label}} =
> $value;
>
> }
> }
> }
> print Dumper($trap->varbinds);
>
> }
> ====
> ====
>
> I think this because Convert::ASN1 don't use bigint for decode default
>
> Jabber ID: admin@freenet59.ru
> --
>
>
>