I have a Perl program that does not seem to be calculating numbers right. It parses a log file with lines in this format:
#ErrorLevel,Computer,IDO,Description,MinValue,MinTime,MaxValue,MaxTim
+e,CurrentValue,CurrentTime
0,localhost,1.3.6.1.4.1.314.50.1.20.3.1.3,CFG persistent MEM,18720,11:
+29,18760,12:30,17176,14:26
The code is supposed to see how the current values (from the %CONFIG hash) compare to the min and max values from the log, then make it the min_value or max_value if it is less than or greater than them (respectively). Here's a snippet of the code:
if (! /^\s*(\d),(\w+),([\d\.]+),([^,]+),([^,]+),(\d+:\d+),([^,]+),(\d+
+:\d+),.*$/ ) { exit_error("Cannot parce log file") }
$level=$1; $computer=$2; $iod=$3; $comment=$4;
$min_value=$5; $min_time=$6;
$max_value=$7; $max_time=$8;
if ( $CONFIG{$computer}{iod}{$iod}{value} =~ /\w+/ ) {}
elsif ( $CONFIG{$computer}{iod}{$iod}{value} < $min_value ) {
$min_value = $CONFIG{$computer}{iod}{$iod}{value};
$min_time = "$hour:$min";
} elsif ( $CONFIG{$computer}{iod}{$iod}{value} > $max_value ) {
$max_value = $CONFIG{$computer}{iod}{$iod}{value};
$max_time = "$hour:$min";
}
print LOG "$level,$computer,$iod,$comment,$min_value,$min_time,$max_va
+lue,
$max_time,$CONFIG{$computer}{iod}{$iod}{value},$hour:$min\n";
The problem is that at least sometimes have a current value that is less than the min_value, but doesn't get passed on to it (as in the log file line above).