@@ -346,7 +346,6 @@ sub process_service {
346
346
my $field = munin_get_node($hash , [$fname ]);
347
347
next if (!defined $field or ref ($field ) ne " HASH" );
348
348
my $fpath = munin_get_node_loc($field );
349
- my $oldstate = ' ok' ;
350
349
351
350
my ($warn , $crit , $unknown_limit ) = get_limits($field );
352
351
@@ -358,11 +357,14 @@ sub process_service {
358
357
my ($ds_id ) = $sth_ds -> fetchrow_array;
359
358
360
359
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;
366
368
367
369
my $heartbeat = 600; # XXX - $heartbeat is a fixed 10 min (2 runs of 5 min).
368
370
if (! defined $current_updated_value || $current_updated_value eq " U" ) {
@@ -391,7 +393,6 @@ sub process_service {
391
393
# compute the value per timeunit
392
394
$value = ($current_updated_value - $previous_updated_value ) / ($current_updated_timestamp - $previous_updated_timestamp );
393
395
}
394
- }
395
396
396
397
# De-taint.
397
398
if ( !defined $value || $value eq " U" ) {
@@ -438,43 +439,27 @@ sub process_service {
438
439
: " Value is unknown." ;
439
440
my $num_unknowns ;
440
441
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 {
445
460
$hash -> {' state_changed' } = 0;
446
461
}
447
462
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
- }
478
463
479
464
if ($state eq " unknown" ) {
480
465
$hash -> {' worst' } = " UNKNOWN" if $hash -> {" worst" } eq " OK" ;
@@ -521,7 +506,7 @@ sub process_service {
521
506
. " ) exceeded"
522
507
));
523
508
524
- if ( $oldstate ne " critical" ) {
509
+ if ($old_state ne " critical" ) {
525
510
$hash -> {' state_changed' } = 1;
526
511
}
527
512
}
@@ -544,16 +529,16 @@ sub process_service {
544
529
. " ) exceeded"
545
530
));
546
531
547
- if ( $oldstate ne " warning" ) {
532
+ if ($old_state ne " warning" ) {
548
533
$hash -> {' state_changed' } = 1;
549
534
}
550
535
}
551
536
else {
552
537
munin_set_var_loc(\%notes , [@$fpath , " state" ], " ok" );
553
538
munin_set_var_loc(\%notes , [@$fpath , " ok" ], " OK" );
554
539
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' )) {
557
542
DEBUG(" [DEBUG] ignoring transition from UNKNOWN to OK" );
558
543
} else {
559
544
$hash -> {' state_changed' } = 1;
@@ -563,7 +548,7 @@ sub process_service {
563
548
}
564
549
565
550
# Replicate the state into the SQL DB
566
- my $new_state = $onfield -> { " state " } ;
551
+ my $new_state = $old_state ;
567
552
$sth_state_upt -> execute($new_state , $ds_id , " ds" );
568
553
}
569
554
generate_service_message($hash );
0 commit comments