Skip to content

Commit

Permalink
Merge branch 'limits-merge-cleanup'
Browse files Browse the repository at this point in the history
  • Loading branch information
sumpfralle committed Aug 26, 2018
2 parents d3052d2 + d084276 commit 2728c5b
Showing 1 changed file with 31 additions and 46 deletions.
77 changes: 31 additions & 46 deletions lib/Munin/Master/LimitsOld.pm
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ sub process_service {
my $field = munin_get_node($hash, [$fname]);
next if (!defined $field or ref($field) ne "HASH");
my $fpath = munin_get_node_loc($field);
my $oldstate = 'ok';

my ($warn, $crit, $unknown_limit) = get_limits($field);

Expand All @@ -358,11 +357,14 @@ sub process_service {
my ($ds_id) = $sth_ds->fetchrow_array;

DEBUG "[DEBUG] processing field: " . join('::', @$fpath);
my $value;
{
my $rrd_filename = munin_get_rrd_filename($field, $path);
my ($current_updated_timestamp, $current_updated_value) = @{ $state->{value}{"$rrd_filename:42"}{current} || [ ] };
my ($previous_updated_timestamp, $previous_updated_value) = @{ $state->{value}{"$rrd_filename:42"}{previous} || [ ] };
my $value;
$sth_state->execute($ds_id, "ds");
my ($current_updated_timestamp, $current_updated_value,
$previous_updated_timestamp, $previous_updated_value,
$old_state, $old_num_unknowns) = $sth_state->fetchrow_array;

$old_state ||= 'ok';
$old_num_unknowns ||= 0;

my $heartbeat = 600; # XXX - $heartbeat is a fixed 10 min (2 runs of 5 min).
if (! defined $current_updated_value || $current_updated_value eq "U") {
Expand Down Expand Up @@ -391,7 +393,6 @@ sub process_service {
# compute the value per timeunit
$value = ($current_updated_value - $previous_updated_value) / ($current_updated_timestamp - $previous_updated_timestamp);
}
}

# De-taint.
if ( !defined $value || $value eq "U" ) {
Expand Down Expand Up @@ -438,43 +439,27 @@ sub process_service {
: "Value is unknown.";
my $num_unknowns;

if ( $oldstate ne "unknown") {
$hash->{'state_changed'} = 1;
}
else {
if ($old_state ne "unknown") {
# The user may want to ignore a few unknown values before
# they should be reported. Thus we need to track the number
# of recently received unknown values before we admit that
# the value is really "unknown". Thus we may want to postpone
# a "change" notification until we reach the limit.
if ($old_num_unknowns >= $unknown_limit) {
# The limit is reached - we should report "unknown".
$hash->{'state_changed'} = 1;
} else {
# Don't change the state to UNKNOWN yet.
$hash->{'state_changed'} = 0;
$state = $old_state;
$extinfo = $field->{"extinfo"} || "";
# Increment the number of UNKNOWN values seen.
$num_unknowns = $old_num_unknowns + 1;
}
} else {
$hash->{'state_changed'} = 0;
}

# First we'll need to check whether the user wants to ignore
# a few UNKNOWN values before actually changing the state to
# UNKNOWN.
if ($unknown_limit > 1) {
if (defined $onfield and defined $onfield->{"state"}) {
if ($onfield->{"state"} ne "unknown") {
if (defined $onfield->{"num_unknowns"}) {
if ($onfield->{"num_unknowns"} < $unknown_limit) {
# Don't change the state to UNKNOWN yet.
$hash->{'state_changed'} = 0;
$state = $onfield->{"state"};
$extinfo = $onfield->{$state};

# Increment the number of UNKNOWN values seen.
$num_unknowns = $onfield->{"num_unknowns"} + 1;
}
}
else {
# Don't change the state to UNKNOWN yet.
$hash->{'state_changed'} = 0;
$state = $onfield->{"state"};
$extinfo = $onfield->{$state};

# Start counting the number of consecutive UNKNOWN
# values seen.
$num_unknowns = 1;
}
}
}
}

if ($state eq "unknown") {
$hash->{'worst'} = "UNKNOWN" if $hash->{"worst"} eq "OK";
Expand Down Expand Up @@ -521,7 +506,7 @@ sub process_service {
. ") exceeded"
));

if ( $oldstate ne "critical") {
if ($old_state ne "critical") {
$hash->{'state_changed'} = 1;
}
}
Expand All @@ -544,16 +529,16 @@ sub process_service {
. ") exceeded"
));

if ( $oldstate ne "warning") {
if ($old_state ne "warning") {
$hash->{'state_changed'} = 1;
}
}
else {
munin_set_var_loc(\%notes, [@$fpath, "state"], "ok");
munin_set_var_loc(\%notes, [@$fpath, "ok"], "OK");

if ($oldstate ne 'ok') {
if ($oldstate eq 'unknown' && munin_get_bool($hobj, 'ignore_unknown', 'false')) {
if ($old_state ne 'ok') {
if ($old_state eq 'unknown' && munin_get_bool($hobj, 'ignore_unknown', 'false')) {
DEBUG("[DEBUG] ignoring transition from UNKNOWN to OK");
} else {
$hash->{'state_changed'} = 1;
Expand All @@ -563,7 +548,7 @@ sub process_service {
}

# Replicate the state into the SQL DB
my $new_state = $onfield->{"state"};
my $new_state = $old_state;
$sth_state_upt->execute($new_state, $ds_id, "ds");
}
generate_service_message($hash);
Expand Down

0 comments on commit 2728c5b

Please sign in to comment.