From 6db2ba2c20e7f22bbddadaa16728e209eef2a38e Mon Sep 17 00:00:00 2001 From: Hirofumi Kosaka Date: Mon, 19 Jun 2017 15:54:27 +0900 Subject: [PATCH 1/2] Improved SNMP trap handling against incomplete traps or partially delayed ones. --- pandora_server/lib/PandoraFMS/SNMPServer.pm | 36 +++++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/SNMPServer.pm b/pandora_server/lib/PandoraFMS/SNMPServer.pm index 41a134f0e6..9609cbae45 100644 --- a/pandora_server/lib/PandoraFMS/SNMPServer.pm +++ b/pandora_server/lib/PandoraFMS/SNMPServer.pm @@ -210,6 +210,11 @@ sub pandora_snmptrapd { # Try to save as much information as possible if the trap could not be parsed $oid = $type_desc if ($oid eq '' || $oid eq '.'); + if (!defined($oid)) { + logger($pa_config, "[W] snmpTrapOID not found (Illegal SNMPv1 trap?)", 1); + return; + } + } elsif ($trap_ver eq "SNMPv2") { ($date, $time, $source, $data) = split(/\[\*\*\]/, $line, 4); my @data = split(/\t/, $data); @@ -440,21 +445,32 @@ sub read_snmplogfile() return undef if (! defined($line)); + my $retry_count = 0; + # More lines ? - while($read_ahead_line = ) { + while(1) { + while($read_ahead_line = ) { - # Get current file position - $read_ahead_pos = tell(SNMPLOGFILE); + # Get current file position + $read_ahead_pos = tell(SNMPLOGFILE); - # Get out of the loop if you find another Trap - last if($read_ahead_line =~ /^SNMP/ ); + # Get out of the loop if you find another Trap + last if($read_ahead_line =~ /^SNMP/ ); - # $read_ahead_line looks continued line... + # $read_ahead_line looks continued line... - # Append to the line and correct the position - chomp($line); - $line .= "$read_ahead_line"; - $pos = $read_ahead_pos; + # Append to the line and correct the position + chomp($line); + $line .= "$read_ahead_line"; + $pos = $read_ahead_pos; + } + + # if $line looks incomplete, try to get continued line + # just within 10sec. After that, giving up to complete it + # and flush $line as it is. + last if(chomp($line) > 0 || $retry_count++ >= 10); + + sleep(1); } # return fetched line with file position to be saved. From 0a845f7ee1cf1a34ad37328b1fc16797f98d06a5 Mon Sep 17 00:00:00 2001 From: Hirofumi Kosaka Date: Tue, 20 Jun 2017 16:52:06 +0900 Subject: [PATCH 2/2] Changed verbosity level of the warning "snmpTrapOID not found" to 5. --- pandora_server/lib/PandoraFMS/SNMPServer.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/SNMPServer.pm b/pandora_server/lib/PandoraFMS/SNMPServer.pm index 9609cbae45..0b54b17d07 100644 --- a/pandora_server/lib/PandoraFMS/SNMPServer.pm +++ b/pandora_server/lib/PandoraFMS/SNMPServer.pm @@ -211,7 +211,7 @@ sub pandora_snmptrapd { $oid = $type_desc if ($oid eq '' || $oid eq '.'); if (!defined($oid)) { - logger($pa_config, "[W] snmpTrapOID not found (Illegal SNMPv1 trap?)", 1); + logger($pa_config, "[W] snmpTrapOID not found (Illegal SNMPv1 trap?)", 5); return; } @@ -223,7 +223,7 @@ sub pandora_snmptrapd { $oid = shift @data; if (!defined($oid)) { - logger($pa_config, "[W] snmpTrapOID not found (Illegal SNMPv2 trap?)", 1); + logger($pa_config, "[W] snmpTrapOID not found (Illegal SNMPv2 trap?)", 5); return; } $oid =~ s/.* = OID: //;