Ticket #828: LimitsOld.pm.2.patch
| File LimitsOld.pm.2.patch, 4.9 kB (added by stevew, 2 years ago) |
|---|
-
LimitsOld.pm
old new 327 327 . $field->{'wrange'} 328 328 . ")"); 329 329 330 330 331 if ($value eq "unknown") { 331 332 $crit->[0] ||= ""; 332 333 $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"} 334 335 my $state = "unknown"; 336 my $extinfo = defined $field->{"extinfo"} 340 337 ? "unknown: " . $field->{"extinfo"} 341 : "Value is unknown." 342 ));338 : "Value is unknown."; 339 my $num_unknowns; 343 340 344 341 if ( !defined $onfield 345 342 or !defined $onfield->{"state"} 346 343 or $onfield->{"state"} ne "unknown") { 347 344 $hash->{'state_changed'} = 1; 348 345 } 346 else { 347 $hash->{'state_changed'} = 0; 348 } 349 350 # First we'll need to check whether the user wants to ignore 351 # a few UNKNOWN values before actually changing the state to 352 # UNKNOWN. 353 if ($unknown_limit > 1) { 354 if (defined $onfield and defined $onfield->{"state"}) { 355 if ($onfield->{"state"} ne "unknown") { 356 if (defined $onfield->{"num_unknowns"}) { 357 if ($onfield->{"num_unknowns"} < $unknown_limit) { 358 # Don't change the state to UNKNOWN yet. 359 $hash->{'state_changed'} = 0; 360 $state = $onfield->{"state"}; 361 $extinfo = $onfield->{$state}; 362 363 # Increment the number of UNKNOWN values seen. 364 $num_unknowns = $onfield->{"num_unknowns"} + 1; 365 } 366 } 367 else { 368 # Don't change the state to UNKNOWN yet. 369 $hash->{'state_changed'} = 0; 370 $state = $onfield->{"state"}; 371 $extinfo = $onfield->{$state}; 372 373 # Start counting the number of consecutive UNKNOWN 374 # values seen. 375 $num_unknowns = 1; 376 } 377 } 378 } 379 } 380 381 if ($state == "unknown") { 382 $hash->{'worst'} = "UNKNOWN" if $hash->{"worst"} eq "OK"; 383 $hash->{'worstid'} = 3 if $hash->{"worstid"} == 0; 384 } 385 elsif ($state == "critical") { 386 $hash->{'worst'} = "CRITICAL"; 387 $hash->{'worstid'} = 2; 388 } 389 elsif ($state == "warning") { 390 $hash->{'worst'} = "WARNING" if $hash->{"worst"} ne "CRITICAL"; 391 $hash->{'worstid'} = 1 if $hash->{"worstid"} != 2; 392 } 393 394 munin_set_var_loc(\%notes, [@$fpath, "state"], $state); 395 munin_set_var_loc(\%notes, [@$fpath, $state], $extinfo); 396 if (defined $num_unknowns) { 397 munin_set_var_loc(\%notes, [@$fpath, "num_unknowns"], 398 $num_unknowns); 399 } 349 400 } 350 401 elsif ((defined($crit->[0]) and $value < $crit->[0]) 351 402 or (defined($crit->[1]) and $value > $crit->[1])) { … … 401 452 402 453 } 403 454 } 404 els if (defined $onfield and defined $onfield->{"state"} or $force){455 else { 405 456 munin_set_var_loc(\%notes, [@$fpath, "state"], "ok"); 406 457 munin_set_var_loc(\%notes, [@$fpath, "ok"], "OK"); 407 $hash->{'state_changed'} = 1; 458 if (not defined $onfield or not defined $onfield->{"state"} or 459 $onfield->{"state"} ne "ok" or $force) { 460 $hash->{'state_changed'} = 1; 461 } 408 462 } 409 463 } 410 464 generate_service_message($hash); … … 451 505 DEBUG "[DEBUG] processing warning: $name -> $warning[0] : $warning[1]"; 452 506 } 453 507 454 # The merge of the unknown_limit implementation was somewhat botched. Not tested. - janl455 508 if ($unknown_limit =~ /^\s*(\d+)\s*$/) { 456 $unknown_limit = $1 if defined $1; 457 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"; 458 517 } 459 518 460 519 return (\@warning, \@critical, $unknown_limit);
