Merge branch '152-handle-incomplete-SNMPtraps' into 'develop'

Improved SNMP trap handling against incomplete traps or partially delayed ones.

Closes #152

See merge request !593
This commit is contained in:
vgilc 2017-09-25 13:14:35 +02:00
commit 07b8e178d3
1 changed files with 27 additions and 11 deletions

View File

@ -211,6 +211,11 @@ sub pandora_snmptrapd {
# Try to save as much information as possible if the trap could not be parsed # Try to save as much information as possible if the trap could not be parsed
$oid = $type_desc if ($oid eq '' || $oid eq '.'); $oid = $type_desc if ($oid eq '' || $oid eq '.');
if (!defined($oid)) {
logger($pa_config, "[W] snmpTrapOID not found (Illegal SNMPv1 trap?)", 5);
return;
}
} elsif ($trap_ver eq "SNMPv2") { } elsif ($trap_ver eq "SNMPv2") {
($date, $time, $source, $data) = split(/\[\*\*\]/, $line, 4); ($date, $time, $source, $data) = split(/\[\*\*\]/, $line, 4);
my @data = split(/\t/, $data); my @data = split(/\t/, $data);
@ -219,7 +224,7 @@ sub pandora_snmptrapd {
$oid = shift @data; $oid = shift @data;
if (!defined($oid)) { 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; return;
} }
$oid =~ s/.* = OID: //; $oid =~ s/.* = OID: //;
@ -441,7 +446,10 @@ sub read_snmplogfile()
return undef if (! defined($line)); return undef if (! defined($line));
my $retry_count = 0;
# More lines ? # More lines ?
while(1) {
while($read_ahead_line = <SNMPLOGFILE>) { while($read_ahead_line = <SNMPLOGFILE>) {
# Get current file position # Get current file position
@ -458,6 +466,14 @@ sub read_snmplogfile()
$pos = $read_ahead_pos; $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. # return fetched line with file position to be saved.
return [$pos, $line]; return [$pos, $line];
} }