Skip to content

Commit 2728c5b

Browse files
committed
Merge branch 'limits-merge-cleanup'
2 parents d3052d2 + d084276 commit 2728c5b

File tree

1 file changed

+31
-46
lines changed

1 file changed

+31
-46
lines changed

lib/Munin/Master/LimitsOld.pm

Lines changed: 31 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@ sub process_service {
346346
my $field = munin_get_node($hash, [$fname]);
347347
next if (!defined $field or ref($field) ne "HASH");
348348
my $fpath = munin_get_node_loc($field);
349-
my $oldstate = 'ok';
350349

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

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

360359
DEBUG "[DEBUG] processing field: " . join('::', @$fpath);
361-
my $value;
362-
{
363-
my $rrd_filename = munin_get_rrd_filename($field, $path);
364-
my ($current_updated_timestamp, $current_updated_value) = @{ $state->{value}{"$rrd_filename:42"}{current} || [ ] };
365-
my ($previous_updated_timestamp, $previous_updated_value) = @{ $state->{value}{"$rrd_filename:42"}{previous} || [ ] };
360+
my $value;
361+
$sth_state->execute($ds_id, "ds");
362+
my ($current_updated_timestamp, $current_updated_value,
363+
$previous_updated_timestamp, $previous_updated_value,
364+
$old_state, $old_num_unknowns) = $sth_state->fetchrow_array;
365+
366+
$old_state ||= 'ok';
367+
$old_num_unknowns ||= 0;
366368

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

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

441-
if ( $oldstate ne "unknown") {
442-
$hash->{'state_changed'} = 1;
443-
}
444-
else {
442+
if ($old_state ne "unknown") {
443+
# The user may want to ignore a few unknown values before
444+
# they should be reported. Thus we need to track the number
445+
# of recently received unknown values before we admit that
446+
# the value is really "unknown". Thus we may want to postpone
447+
# a "change" notification until we reach the limit.
448+
if ($old_num_unknowns >= $unknown_limit) {
449+
# The limit is reached - we should report "unknown".
450+
$hash->{'state_changed'} = 1;
451+
} else {
452+
# Don't change the state to UNKNOWN yet.
453+
$hash->{'state_changed'} = 0;
454+
$state = $old_state;
455+
$extinfo = $field->{"extinfo"} || "";
456+
# Increment the number of UNKNOWN values seen.
457+
$num_unknowns = $old_num_unknowns + 1;
458+
}
459+
} else {
445460
$hash->{'state_changed'} = 0;
446461
}
447462

448-
# First we'll need to check whether the user wants to ignore
449-
# a few UNKNOWN values before actually changing the state to
450-
# UNKNOWN.
451-
if ($unknown_limit > 1) {
452-
if (defined $onfield and defined $onfield->{"state"}) {
453-
if ($onfield->{"state"} ne "unknown") {
454-
if (defined $onfield->{"num_unknowns"}) {
455-
if ($onfield->{"num_unknowns"} < $unknown_limit) {
456-
# Don't change the state to UNKNOWN yet.
457-
$hash->{'state_changed'} = 0;
458-
$state = $onfield->{"state"};
459-
$extinfo = $onfield->{$state};
460-
461-
# Increment the number of UNKNOWN values seen.
462-
$num_unknowns = $onfield->{"num_unknowns"} + 1;
463-
}
464-
}
465-
else {
466-
# Don't change the state to UNKNOWN yet.
467-
$hash->{'state_changed'} = 0;
468-
$state = $onfield->{"state"};
469-
$extinfo = $onfield->{$state};
470-
471-
# Start counting the number of consecutive UNKNOWN
472-
# values seen.
473-
$num_unknowns = 1;
474-
}
475-
}
476-
}
477-
}
478463

479464
if ($state eq "unknown") {
480465
$hash->{'worst'} = "UNKNOWN" if $hash->{"worst"} eq "OK";
@@ -521,7 +506,7 @@ sub process_service {
521506
. ") exceeded"
522507
));
523508

524-
if ( $oldstate ne "critical") {
509+
if ($old_state ne "critical") {
525510
$hash->{'state_changed'} = 1;
526511
}
527512
}
@@ -544,16 +529,16 @@ sub process_service {
544529
. ") exceeded"
545530
));
546531

547-
if ( $oldstate ne "warning") {
532+
if ($old_state ne "warning") {
548533
$hash->{'state_changed'} = 1;
549534
}
550535
}
551536
else {
552537
munin_set_var_loc(\%notes, [@$fpath, "state"], "ok");
553538
munin_set_var_loc(\%notes, [@$fpath, "ok"], "OK");
554539

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

565550
# Replicate the state into the SQL DB
566-
my $new_state = $onfield->{"state"};
551+
my $new_state = $old_state;
567552
$sth_state_upt->execute($new_state, $ds_id, "ds");
568553
}
569554
generate_service_message($hash);

0 commit comments

Comments
 (0)