Skip to content

Commit

Permalink
Mutes should only lower level #196
Browse files Browse the repository at this point in the history
  • Loading branch information
bwalkerl committed Oct 14, 2024
1 parent 99eaf75 commit 95e3b59
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion classes/check/failingtaskcheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function get_ref(): string {
* @return array of failing tasks
*/
public static function get_failing_tasks(): array {
GLOBAL $DB;
global $DB;
$tasks = [];

// Instead of using task API here, we read directly from the database.
Expand Down
36 changes: 24 additions & 12 deletions classes/checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ class checker {
3 => "UNKNOWN",
];

/** @var array Map check result to nagios level **/
public const RESULT_MAPPING = [
result::OK => resultmessage::LEVEL_OK,
result::INFO => resultmessage::LEVEL_OK,
result::NA => resultmessage::LEVEL_OK,
result::WARNING => resultmessage::LEVEL_WARN,
result::CRITICAL => resultmessage::LEVEL_CRITICAL,
result::ERROR => resultmessage::LEVEL_CRITICAL,
result::UNKNOWN => resultmessage::LEVEL_UNKNOWN,
];

/**
* Returns an array of check API messages.
* If exceptions are thrown, they are caught and returned as result messages as well.
Expand Down Expand Up @@ -133,15 +144,7 @@ private static function process_check_and_get_result(check $check): resultmessag
$checkresult = self::get_overridden_result($check);

// Map check result to nagios level.
$map = [
result::OK => resultmessage::LEVEL_OK,
result::INFO => resultmessage::LEVEL_OK,
result::NA => resultmessage::LEVEL_OK,
result::WARNING => resultmessage::LEVEL_WARN,
result::CRITICAL => resultmessage::LEVEL_CRITICAL,
result::ERROR => resultmessage::LEVEL_CRITICAL,
result::UNKNOWN => resultmessage::LEVEL_UNKNOWN,
];
$map = self::RESULT_MAPPING;

// Get the level, or default to unknown.
$status = $checkresult->get_status();
Expand Down Expand Up @@ -318,9 +321,18 @@ public static function get_overridden_result(check $check): result {
$result = $check->get_result();

$override = \tool_heartbeat\object\override::get_active_override($ref);
if (isset($override)) {
return new result($override->get('override'), $result->get_summary(), $result->get_details());
if (!isset($override)) {
return $result;
}
return $result;

// Mutes should only be able to lower the level.
$map = self::RESULT_MAPPING;
$status = $override->get('override');
if ($map[$status] >= $map[$result->get_status()]) {
// Don't automatically resolve the override as some checks may fail sporadically.
return $result;
}

return new result($status, $result->get_summary(), $result->get_details());
}
}

0 comments on commit 95e3b59

Please sign in to comment.