Are you trying to send SNMP (v2) traps? The Net::SNMP module does this for you without you needing to worry about the encoding yourself.
I've done some decoding work with Net::SNMPTrapd, but for that I used Convert::ASN1.
I would use Convert::ASN1 also for your task instead of the module you're currently trying with. The following works:
use strict;
use warnings;
use Convert::ASN1;
my $asn = Convert::ASN1->new;
$asn->prepare("
varbind SEQUENCE OF SEQUENCE {
oid OBJECT IDENTIFIER,
choice CHOICE {
val_integer INTEGER,
val_string STRING,
val_OID OBJECT IDENTIFIER,
val_IpAddr [APPLICATION 0] STRING,
val_Counter32 [APPLICATION 1] INTEGER,
val_Guage32 [APPLICATION 2] INTEGER,
val_TimeTicks [APPLICATION 3] INTEGER,
val_Opaque [APPLICATION 4] STRING,
val_Counter64 [APPLICATION 6] INTEGER
}
}
");
my $pdu = $asn->encode(
varbind => [
{
oid => '1.3.6.1.2.1.1.3.0',
choice => {
val_TimeTicks => 600
}
},
{
oid => '1.3.6.1.6.3.1.1.4.1.0',
choice => {
val_OID => '1.3.6.1.4.1.42767.64.1.1.5.1.40.1'
}
},
{
oid => '1.3.6.1.4.1.42767.64.1.1.3.1.9',
choice => {
val_integer => 11,
}
},
{
oid => '1.3.6.1.4.1.42767.64.1.1.3.1.10',
choice => {
val_OID => '1.3.6.1.2.1.26.2.1.1.3.1.9',
}
},
{
oid => '1.3.6.1.4.1.42767.64.1.1.3.1.11',
choice => {
val_Counter32 => 10,
}
},
{
oid => '1.3.6.1.4.1.42767.64.1.1.3.1.12',
choice => {
val_TimeTicks => time()
}
},
{
oid => '1.3.6.1.4.1.42767.64.1.1.3.1.13',
choice => {
val_integer => 2,
}
},
{
oid => '1.3.6.1.4.1.42767.64.1.1.3.1.14',
choice => {
val_string => ''
}
}
]
);
Convert::ASN1::asn_dump($pdu);
And the output:
VinsWorldcom@C:\Users\VinsWorldcom\tmp> perl test.pl
0000 186: SEQUENCE {
0003 14: SEQUENCE {
0005 8: OBJECT ID = 1.3.6.1.2.1.1.3.0
000F 2: [APPLICATION 3]
0011 : 02 58 __ __ __ __ __ __ __ __ __ __ __ __ __ __ .X
0013 : }
0013 29: SEQUENCE {
0015 10: OBJECT ID = 1.3.6.1.6.3.1.1.4.1.0
0021 15: OBJECT ID = 1.3.6.1.4.1.42767.64.1.1.5.1.40.1
0032 : }
0032 19: SEQUENCE {
0034 14: OBJECT ID = 1.3.6.1.4.1.42767.64.1.1.3.1.9
0044 1: INTEGER = 11
0047 : }
0047 30: SEQUENCE {
0049 14: OBJECT ID = 1.3.6.1.4.1.42767.64.1.1.3.1.10
0059 12: OBJECT ID = 1.3.6.1.2.1.26.2.1.1.3.1.9
0067 : }
0067 19: SEQUENCE {
0069 14: OBJECT ID = 1.3.6.1.4.1.42767.64.1.1.3.1.11
0079 1: [APPLICATION 1]
007B : 0A __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ .
007C : }
007C 22: SEQUENCE {
007E 14: OBJECT ID = 1.3.6.1.4.1.42767.64.1.1.3.1.12
008E 4: [APPLICATION 3]
0090 : 51 2A C7 73 __ __ __ __ __ __ __ __ __ __ __ __ Q*.s
0094 : }
0094 19: SEQUENCE {
0096 14: OBJECT ID = 1.3.6.1.4.1.42767.64.1.1.3.1.13
00A6 1: INTEGER = 2
00A9 : }
00A9 18: SEQUENCE {
00AB 14: OBJECT ID = 1.3.6.1.4.1.42767.64.1.1.3.1.14
00BB 0: STRING = ''
00BD : }
00BD : }
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.