Changeset 3378

Show
Ignore:
Timestamp:
02/26/10 09:03:11 (2 years ago)
Author:
feiner.tom
Message:

Add patch from munin ticket #828, to suppress "occasional" unknown states to avoid alerts. Thanks to Steve Wilson for the patch!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/common/lib/Munin/Common/Config.pm

    r3139 r3378  
    3737        "cdef_name", "graphable", "process", "realname", 
    3838        "onlynullcdef", "group_order", "pipe", "pipe_command", 
    39         "unknown_limit", "notify_countdown", "dropdownlimit", 
     39        "unknown_limit", "num_unknowns", "dropdownlimit", 
    4040        "max_graph_jobs", "munin_cgi_graph_jobs" ); 
    4141 
  • trunk/master/lib/Munin/Master/LimitsOld.pm

    r3264 r3378  
    331331            $crit->[0] ||= ""; 
    332332            $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"} 
     333 
     334            my $state = "unknown"; 
     335            my $extinfo = defined $field->{"extinfo"} 
    340336                    ? "unknown: " . $field->{"extinfo"} 
    341                     : "Value is unknown." 
    342                 ))
     337                    : "Value is unknown."; 
     338            my $num_unknowns
    343339 
    344340            if (   !defined $onfield 
     
    347343                $hash->{'state_changed'} = 1; 
    348344            } 
    349         } 
     345            else { 
     346                $hash->{'state_changed'} = 0; 
     347            } 
     348 
     349            # First we'll need to check whether the user wants to ignore 
     350            # a few UNKNOWN values before actually changing the state to 
     351            # UNKNOWN. 
     352            if ($unknown_limit > 1) { 
     353                if (defined $onfield and defined $onfield->{"state"}) { 
     354                    if ($onfield->{"state"} ne "unknown") { 
     355                        if (defined $onfield->{"num_unknowns"}) { 
     356                            if ($onfield->{"num_unknowns"} < $unknown_limit) { 
     357                                # Don't change the state to UNKNOWN yet. 
     358                                $hash->{'state_changed'} = 0; 
     359                                $state = $onfield->{"state"}; 
     360                                $extinfo = $onfield->{$state}; 
     361 
     362                                # Increment the number of UNKNOWN values seen. 
     363                                $num_unknowns = $onfield->{"num_unknowns"} + 1; 
     364                            } 
     365                        } 
     366                        else { 
     367                            # Don't change the state to UNKNOWN yet. 
     368                            $hash->{'state_changed'} = 0; 
     369                            $state = $onfield->{"state"}; 
     370                            $extinfo = $onfield->{$state}; 
     371                             
     372                            # Start counting the number of consecutive UNKNOWN 
     373                            # values seen. 
     374                            $num_unknowns = 1; 
     375                        } 
     376                    } 
     377                } 
     378            } 
     379 
     380            if ($state eq "unknown") { 
     381                $hash->{'worst'} = "UNKNOWN" if $hash->{"worst"} eq "OK"; 
     382                $hash->{'worstid'} = 3 if $hash->{"worstid"} == 0; 
     383            } 
     384            elsif ($state eq "critical") { 
     385                $hash->{'worst'} = "CRITICAL"; 
     386                $hash->{'worstid'} = 2; 
     387            } 
     388            elsif ($state eq "warning") { 
     389                $hash->{'worst'} = "WARNING" if $hash->{"worst"} ne "CRITICAL"; 
     390                $hash->{'worstid'} = 1 if $hash->{"worstid"} != 2; 
     391            } 
     392 
     393            munin_set_var_loc(\%notes, [@$fpath, "state"], $state); 
     394            munin_set_var_loc(\%notes, [@$fpath, $state], $extinfo); 
     395            if (defined $num_unknowns) { 
     396                munin_set_var_loc(\%notes, [@$fpath, "num_unknowns"], 
     397                        $num_unknowns); 
     398            } 
     399        } 
     400 
    350401        elsif ((defined($crit->[0]) and $value < $crit->[0]) 
    351402            or (defined($crit->[1]) and $value > $crit->[1])) { 
     
    423474    my $crit          = munin_get($hash, "critical",      undef); 
    424475    my $warn          = munin_get($hash, "warning",       undef); 
    425     my $unknown_limit = munin_get($hash, "unknown_limit", 1); 
     476    my $unknown_limit = munin_get($hash, "unknown_limit", 3); 
    426477 
    427478    my $name = munin_get_node_name($hash); 
     
    455506    } 
    456507 
    457     # The merge of the unknown_limit implementation was somewhat botched.  Not tested. - janl 
    458508    if ($unknown_limit =~ /^\s*(\d+)\s*$/) { 
    459         $unknown_limit = $1 if defined $1; 
    460         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"; 
    461517    } 
    462518