Ticket #828: LimitsOld.pm.2.patch

File LimitsOld.pm.2.patch, 4.9 kB (added by stevew, 2 years ago)

Replacement patch for LimitsOld?.pm

  • LimitsOld.pm

    old new  
    327327              . $field->{'wrange'} 
    328328              . ")"); 
    329329 
     330 
    330331        if ($value eq "unknown") { 
    331332            $crit->[0] ||= ""; 
    332333            $crit->[1] ||= ""; 
    333             $hash->{'worst'} = "UNKNOWN" if $hash->{"worst"} eq "OK"; 
    334             $hash->{'worstid'} = 3 if $hash->{"worstid"} == 0; 
    335             munin_set_var_loc(\%notes, [@$fpath, "state"], "unknown"); 
    336             munin_set_var_loc( 
    337                 \%notes, 
    338                 [@$fpath, "unknown"], ( 
    339                     defined $field->{"extinfo"} 
     334 
     335            my $state = "unknown"; 
     336            my $extinfo = defined $field->{"extinfo"} 
    340337                    ? "unknown: " . $field->{"extinfo"} 
    341                     : "Value is unknown." 
    342                 ))
     338                    : "Value is unknown."; 
     339            my $num_unknowns
    343340 
    344341            if (   !defined $onfield 
    345342                or !defined $onfield->{"state"} 
    346343                or $onfield->{"state"} ne "unknown") { 
    347344                $hash->{'state_changed'} = 1; 
    348345            } 
     346            else { 
     347                $hash->{'state_changed'} = 0; 
     348            } 
     349 
     350            # First we'll need to check whether the user wants to ignore 
     351            # a few UNKNOWN values before actually changing the state to 
     352            # UNKNOWN. 
     353            if ($unknown_limit > 1) { 
     354                if (defined $onfield and defined $onfield->{"state"}) { 
     355                    if ($onfield->{"state"} ne "unknown") { 
     356                        if (defined $onfield->{"num_unknowns"}) { 
     357                            if ($onfield->{"num_unknowns"} < $unknown_limit) { 
     358                                # Don't change the state to UNKNOWN yet. 
     359                                $hash->{'state_changed'} = 0; 
     360                                $state = $onfield->{"state"}; 
     361                                $extinfo = $onfield->{$state}; 
     362 
     363                                # Increment the number of UNKNOWN values seen. 
     364                                $num_unknowns = $onfield->{"num_unknowns"} + 1; 
     365                            } 
     366                        } 
     367                        else { 
     368                            # Don't change the state to UNKNOWN yet. 
     369                            $hash->{'state_changed'} = 0; 
     370                            $state = $onfield->{"state"}; 
     371                            $extinfo = $onfield->{$state}; 
     372 
     373                            # Start counting the number of consecutive UNKNOWN 
     374                            # values seen. 
     375                            $num_unknowns = 1; 
     376                        } 
     377                    } 
     378                } 
     379            } 
     380           
     381            if ($state == "unknown") { 
     382                $hash->{'worst'} = "UNKNOWN" if $hash->{"worst"} eq "OK"; 
     383                $hash->{'worstid'} = 3 if $hash->{"worstid"} == 0; 
     384            } 
     385            elsif ($state == "critical") { 
     386                $hash->{'worst'} = "CRITICAL"; 
     387                $hash->{'worstid'} = 2; 
     388            } 
     389            elsif ($state == "warning") { 
     390                $hash->{'worst'} = "WARNING" if $hash->{"worst"} ne "CRITICAL"; 
     391                $hash->{'worstid'} = 1 if $hash->{"worstid"} != 2; 
     392            } 
     393 
     394            munin_set_var_loc(\%notes, [@$fpath, "state"], $state); 
     395            munin_set_var_loc(\%notes, [@$fpath, $state], $extinfo); 
     396            if (defined $num_unknowns) { 
     397                munin_set_var_loc(\%notes, [@$fpath, "num_unknowns"], 
     398                        $num_unknowns); 
     399            } 
    349400        } 
    350401        elsif ((defined($crit->[0]) and $value < $crit->[0]) 
    351402            or (defined($crit->[1]) and $value > $crit->[1])) { 
     
    401452 
    402453            } 
    403454        } 
    404         elsif (defined $onfield and defined $onfield->{"state"} or $force)
     455        else
    405456            munin_set_var_loc(\%notes, [@$fpath, "state"], "ok"); 
    406457            munin_set_var_loc(\%notes, [@$fpath, "ok"],    "OK"); 
    407             $hash->{'state_changed'} = 1; 
     458            if (not defined $onfield or not defined $onfield->{"state"} or 
     459                   $onfield->{"state"} ne "ok" or $force) { 
     460               $hash->{'state_changed'} = 1; 
     461           } 
    408462        } 
    409463    } 
    410464    generate_service_message($hash); 
     
    451505        DEBUG "[DEBUG] processing warning: $name -> $warning[0] : $warning[1]"; 
    452506    } 
    453507 
    454     # The merge of the unknown_limit implementation was somewhat botched.  Not tested. - janl 
    455508    if ($unknown_limit =~ /^\s*(\d+)\s*$/) { 
    456         $unknown_limit = $1 if defined $1; 
    457         DEBUG "[DEBUG] processing unknown_limit: $name -> $unknown_limit"; 
     509        $unknown_limit = $1 if defined $1; 
     510        if (defined $unknown_limit) { 
     511            if ($unknown_limit < 1) { 
     512                # Zero and negative numbers are not valid.       
     513                $unknown_limit = 1; 
     514            } 
     515        } 
     516        DEBUG "[DEBUG] processing unknown_limit: $name -> $unknown_limit"; 
    458517    } 
    459518 
    460519    return (\@warning, \@critical, $unknown_limit);