Ticket #828: LimitsOld.pm.patch

File LimitsOld.pm.patch, 2.5 kB (added by janl, 2 years ago)
  • LimitsOld.pm

    old new  
    341341                    : "Value is unknown." 
    342342                )); 
    343343 
    344             if (   !defined $onfield 
    345                 or !defined $onfield->{"state"} 
    346                 or $onfield->{"state"} ne "unknown") { 
     344            # Maintain a countdown of consecutive UNKNOWN values starting 
     345            # at the value of "unknown_limit". 
     346            my $notify_countdown = $unknown_limit; 
     347            if (defined $onfield and defined $onfield->{"state"} and 
     348                    $onfield->{"state"} eq "unknown" and 
     349                    defined $onfield->{"notify_countdown"}) { 
     350                $notify_countdown = $onfield->{"notify_countdown"}; 
     351            } 
     352                 
     353            # Check if we've seen at least $unknown_limit 
     354            # consecutive UNKNOWN values before creating a state 
     355            # change. 
     356            if ($notify_countdown == 1) { 
    347357                $hash->{'state_changed'} = 1; 
    348358            } 
     359                 
     360            $notify_countdown = ($notify_countdown > 0 
     361                ? $notify_countdown - 1 
     362                : 0); 
     363            munin_set_var_loc( 
     364                \%notes, 
     365                [@$fpath, "notify_countdown"], 
     366                $notify_countdown); 
    349367        } 
    350368        elsif ((defined($crit->[0]) and $value < $crit->[0]) 
    351369            or (defined($crit->[1]) and $value > $crit->[1])) { 
     
    404422        elsif (defined $onfield and defined $onfield->{"state"} or $force) { 
    405423            munin_set_var_loc(\%notes, [@$fpath, "state"], "ok"); 
    406424            munin_set_var_loc(\%notes, [@$fpath, "ok"],    "OK"); 
    407             $hash->{'state_changed'} = 1; 
     425               $hash->{'state_changed'} = 1; 
    408426        } 
    409427    } 
    410428    generate_service_message($hash); 
     
    451469        DEBUG "[DEBUG] processing warning: $name -> $warning[0] : $warning[1]"; 
    452470    } 
    453471 
    454     # The merge of the unknown_limit implementation was somewhat botched.  Not tested. - janl 
    455472    if ($unknown_limit =~ /^\s*(\d+)\s*$/) { 
    456         $unknown_limit = $1 if defined $1; 
    457         DEBUG "[DEBUG] processing unknown_limit: $name -> $unknown_limit"; 
     473        $unknown_limit = $1 if defined $1; 
     474        if (defined $unknown_limit) { 
     475            if ($unknown_limit < 1) { 
     476                # Zero and negative numbers are not valid.       
     477                $unknown_limit = 1; 
     478            } 
     479        } 
     480        DEBUG "[DEBUG] processing unknown_limit: $name -> $unknown_limit"; 
    458481    } 
    459482 
    460483    return (\@warning, \@critical, $unknown_limit);