| 1 |
--- LimitsOld.pm 2010-01-11 09:16:41.000000000 -0500 |
|---|
| 2 |
+++ LimitsOld.pm.new 2010-01-11 10:15:25.000000000 -0500 |
|---|
| 3 |
@@ -330,23 +330,74 @@ |
|---|
| 4 |
if ($value eq "unknown") { |
|---|
| 5 |
$crit->[0] ||= ""; |
|---|
| 6 |
$crit->[1] ||= ""; |
|---|
| 7 |
- $hash->{'worst'} = "UNKNOWN" if $hash->{"worst"} eq "OK"; |
|---|
| 8 |
- $hash->{'worstid'} = 3 if $hash->{"worstid"} == 0; |
|---|
| 9 |
- munin_set_var_loc(\%notes, [@$fpath, "state"], "unknown"); |
|---|
| 10 |
- munin_set_var_loc( |
|---|
| 11 |
- \%notes, |
|---|
| 12 |
- [@$fpath, "unknown"], ( |
|---|
| 13 |
- defined $field->{"extinfo"} |
|---|
| 14 |
+ |
|---|
| 15 |
+ my $state = "unknown"; |
|---|
| 16 |
+ my $extinfo = defined $field->{"extinfo"} |
|---|
| 17 |
? "unknown: " . $field->{"extinfo"} |
|---|
| 18 |
- : "Value is unknown." |
|---|
| 19 |
- )); |
|---|
| 20 |
+ : "Value is unknown."; |
|---|
| 21 |
+ my $num_unknowns; |
|---|
| 22 |
|
|---|
| 23 |
if ( !defined $onfield |
|---|
| 24 |
or !defined $onfield->{"state"} |
|---|
| 25 |
or $onfield->{"state"} ne "unknown") { |
|---|
| 26 |
$hash->{'state_changed'} = 1; |
|---|
| 27 |
} |
|---|
| 28 |
+ else { |
|---|
| 29 |
+ $hash->{'state_changed'} = 0; |
|---|
| 30 |
+ } |
|---|
| 31 |
+ |
|---|
| 32 |
+ # First we'll need to check whether the user wants to ignore |
|---|
| 33 |
+ # a few UNKNOWN values before actually changing the state to |
|---|
| 34 |
+ # UNKNOWN. |
|---|
| 35 |
+ if ($unknown_limit > 1) { |
|---|
| 36 |
+ if (defined $onfield and defined $onfield->{"state"}) { |
|---|
| 37 |
+ if ($onfield->{"state"} ne "unknown") { |
|---|
| 38 |
+ if (defined $onfield->{"num_unknowns"}) { |
|---|
| 39 |
+ if ($onfield->{"num_unknowns"} < $unknown_limit) { |
|---|
| 40 |
+ # Don't change the state to UNKNOWN yet. |
|---|
| 41 |
+ $hash->{'state_changed'} = 0; |
|---|
| 42 |
+ $state = $onfield->{"state"}; |
|---|
| 43 |
+ $extinfo = $onfield->{$state}; |
|---|
| 44 |
+ |
|---|
| 45 |
+ # Increment the number of UNKNOWN values seen. |
|---|
| 46 |
+ $num_unknowns = $onfield->{"num_unknowns"} + 1; |
|---|
| 47 |
+ } |
|---|
| 48 |
+ } |
|---|
| 49 |
+ else { |
|---|
| 50 |
+ # Don't change the state to UNKNOWN yet. |
|---|
| 51 |
+ $hash->{'state_changed'} = 0; |
|---|
| 52 |
+ $state = $onfield->{"state"}; |
|---|
| 53 |
+ $extinfo = $onfield->{$state}; |
|---|
| 54 |
+ |
|---|
| 55 |
+ # Start counting the number of consecutive UNKNOWN |
|---|
| 56 |
+ # values seen. |
|---|
| 57 |
+ $num_unknowns = 1; |
|---|
| 58 |
+ } |
|---|
| 59 |
+ } |
|---|
| 60 |
+ } |
|---|
| 61 |
+ } |
|---|
| 62 |
+ |
|---|
| 63 |
+ if ($state eq "unknown") { |
|---|
| 64 |
+ $hash->{'worst'} = "UNKNOWN" if $hash->{"worst"} eq "OK"; |
|---|
| 65 |
+ $hash->{'worstid'} = 3 if $hash->{"worstid"} == 0; |
|---|
| 66 |
+ } |
|---|
| 67 |
+ elsif ($state eq "critical") { |
|---|
| 68 |
+ $hash->{'worst'} = "CRITICAL"; |
|---|
| 69 |
+ $hash->{'worstid'} = 2; |
|---|
| 70 |
+ } |
|---|
| 71 |
+ elsif ($state eq "warning") { |
|---|
| 72 |
+ $hash->{'worst'} = "WARNING" if $hash->{"worst"} ne "CRITICAL"; |
|---|
| 73 |
+ $hash->{'worstid'} = 1 if $hash->{"worstid"} != 2; |
|---|
| 74 |
+ } |
|---|
| 75 |
+ |
|---|
| 76 |
+ munin_set_var_loc(\%notes, [@$fpath, "state"], $state); |
|---|
| 77 |
+ munin_set_var_loc(\%notes, [@$fpath, $state], $extinfo); |
|---|
| 78 |
+ if (defined $num_unknowns) { |
|---|
| 79 |
+ munin_set_var_loc(\%notes, [@$fpath, "num_unknowns"], |
|---|
| 80 |
+ $num_unknowns); |
|---|
| 81 |
+ } |
|---|
| 82 |
} |
|---|
| 83 |
+ |
|---|
| 84 |
elsif ((defined($crit->[0]) and $value < $crit->[0]) |
|---|
| 85 |
or (defined($crit->[1]) and $value > $crit->[1])) { |
|---|
| 86 |
$crit->[0] ||= ""; |
|---|
| 87 |
@@ -454,10 +505,15 @@ |
|---|
| 88 |
DEBUG "[DEBUG] processing warning: $name -> $warning[0] : $warning[1]"; |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
- # The merge of the unknown_limit implementation was somewhat botched. Not tested. - janl |
|---|
| 92 |
if ($unknown_limit =~ /^\s*(\d+)\s*$/) { |
|---|
| 93 |
- $unknown_limit = $1 if defined $1; |
|---|
| 94 |
- DEBUG "[DEBUG] processing unknown_limit: $name -> $unknown_limit"; |
|---|
| 95 |
+ $unknown_limit = $1 if defined $1; |
|---|
| 96 |
+ if (defined $unknown_limit) { |
|---|
| 97 |
+ if ($unknown_limit < 1) { |
|---|
| 98 |
+ # Zero and negative numbers are not valid. |
|---|
| 99 |
+ $unknown_limit = 1; |
|---|
| 100 |
+ } |
|---|
| 101 |
+ } |
|---|
| 102 |
+ DEBUG "[DEBUG] processing unknown_limit: $name -> $unknown_limit"; |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|
| 105 |
return (\@warning, \@critical, $unknown_limit); |
|---|