I don't think your problem is Perl related. Somehow harder to figure out - may be something up with your systems?
I changed your code block slightly - just to use strict - and it works perfectly sending to a remote FreeBSD machine receiving traps on 162.
#!/usr/bin/perl -w
use strict;
use Net::SNMP qw(:asn1);
my $message="hi_there";
my $manager='1.2.3.4';
my $host='1.2.3.5';
my $sysedgemgmt='1.3.6.1.4.1.546.9.6';
my $sysedgemule='1.3.6.1.4.1.546.9.6.0.2724';
my @oid=($sysedgemule, OCTET_STRING, $message);
my ($session, $error)=Net::SNMP->session(
-hostname => shift || $host,
-version => 'snmpv1',
-community => 'ellengirl',
-port => shift || 162,
);
if (!defined($session)) {
printf("SESSIONERROR: %s.\n", $error);
}
my $procdown = $session->trap(
-enterprise => $sysedgemgmt,
-agentaddr => $manager,
-generictrap => 6,
-specifictrap => 2724,
-varbindlist => \@oid,
);
if (!defined($procdown)) {
printf("ERROR: %s.\n", $session->error);
}
$session->close;
exit 0;
and here's the data we received at UDP 162
Jun 9 14:45:14 remotehost snmptrapd[13197]: 1.2.3.5: Enterprise Speci
+fic Trap (2724) Uptime: 0:00:00.00, SNMPv2-SMI::enterprises.546.9.6.0
+.2724 = STRING: "hi_there"
Jun 9 14:45:14 remotehost hsinclai: The default snmptrapd traphandler
+ has just made a mark.
Note: I've got snmptrapd creating a log event after receiving a trap
Also note, hm specified v1, but logged in as snmpv2 !!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.