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 !! |