CC: | <Ole-Bjorn.Hessen [...] telenor.com> |
Subject: | Please accept the following simple patch for Net-SNMPTrapd |
Date: | Mon, 5 Aug 2013 07:17:39 +0000 |
To: | <bug-Net-SNMPTrapd [...] rt.cpan.org> |
From: | <Roger.Soloy [...] telenor.com> |
Two minor adjustments has been done to the Net-SNMPTrapd module:
1) Performance optimization: On high-volume trap receive it is costly to do a select and recv when a simple recv is enough. It means packet loss.
The following patch only run select if Timeout is set. If not then blocking recv is called directly.
$ diff -u /local/nms/perl/prod/lib/site_perl/5.16.0/Net/SNMPTrapd.pm /tmp
--- /local/nms/perl/prod/lib/site_perl/5.16.0/Net/SNMPTrapd.pm 2013-08-02 17:30:25.000000000 +0200
+++ /tmp/SNMPTrapd.pm 2013-08-02 18:09:13.000000000 +0200
@@ -162,28 +162,27 @@
my $udpserver = $self->{'_UDPSERVER_'};
my $datagram;
- # vars for IO select
- my ($rin, $rout, $ein, $eout) = ('', '', '', '');
- vec($rin, fileno($udpserver), 1) = 1;
-
- # check if a message is waiting
- if (select($rout=$rin, undef, $eout=$ein, $Timeout)) {
- # read the message
- if ($udpserver->recv($datagram, $datagramsize)) {
-
- $trap->{'_TRAP_'}{'PeerPort'} = $udpserver->SUPER::peerport;
- $trap->{'_TRAP_'}{'PeerAddr'} = $udpserver->SUPER::peerhost;
- $trap->{'_TRAP_'}{'datagram'} = $datagram;
+ if ($Timeout != 0) {
+ # vars for IO select
+ my ($rin, $rout, $ein, $eout) = ('', '', '', '');
+ vec($rin, fileno($udpserver), 1) = 1;
+
+ # check if a message is waiting
+ if (! select($rout=$rin, undef, $eout=$ein, $Timeout)) {
+ $LASTERROR = "Timed out waiting for datagram";
+ return(0)
+ }
+ }
- return bless $trap, $class
- } else {
- $LASTERROR = sprintf "Socket RECV error: $!";
- return(undef)
- }
- } else {
- $LASTERROR = "Timed out waiting for datagram";
- return(0)
+ # read the message
+ if ($udpserver->recv($datagram, $datagramsize)) {
+ $trap->{'_TRAP_'}{'PeerPort'} = $udpserver->SUPER::peerport;
+ $trap->{'_TRAP_'}{'PeerAddr'} = $udpserver->SUPER::peerhost;
+ $trap->{'_TRAP_'}{'datagram'} = $datagram;
+ return bless $trap, $class
}
+ $LASTERROR = sprintf "Socket RECV error: $!";
+ return(undef)
}
2) We got a snmp trap with a Null value from one of our vendor hosts that Net::SNMPTrapd dropped because it didn't parse NULL. Can you please update Net/SNMPTrapd.pm with a val_Null?
### Process varbinds
my $trap2;
$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,
val_Null NULL
}
}
");
$ diff -u /local/nms/perl/prod/lib/site_perl/5.16.0/Net/SNMPTrapd.pm /tmp
--- /local/nms/perl/prod/lib/site_perl/5.16.0/Net/SNMPTrapd.pm 2012-09-26 13:19:07.000000000 +0200
+++ /tmp/SNMPTrapd.pm 2013-08-02 17:17:58.000000000 +0200
@@ -269,7 +269,8 @@
val_Guage32 [APPLICATION 2] INTEGER,
val_TimeTicks [APPLICATION 3] INTEGER,
val_Opaque [APPLICATION 4] STRING,
- val_Counter64 [APPLICATION 6] INTEGER
+ val_Counter64 [APPLICATION 6] INTEGER,
+ val_Null NULL
}
}
");
Kind regards,
Roger Soløy
Solution Architect
IP NMS/Technology/Telenor Norway
Message body is not shown because it is too large.