Skip to content

Commit

Permalink
Add new mute settings #187
Browse files Browse the repository at this point in the history
  • Loading branch information
bwalkerl committed Aug 5, 2024
1 parent 21ca8b9 commit 24ff951
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 12 deletions.
19 changes: 9 additions & 10 deletions classes/form/override_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

namespace tool_heartbeat\form;

use core\check\result;
use core\form\persistent;
use tool_heartbeat\object\override;

/**
* Override form
Expand All @@ -50,15 +50,7 @@ public function definition() {
$mform->setConstant('ref', $this->_customdata['ref']);

// Override.
$mform->addElement('select', 'override', get_string('override', 'tool_heartbeat'), [
result::NA => get_string('statusna'),
result::OK => get_string('statusok'),
result::INFO => get_string('statusinfo'),
result::UNKNOWN => get_string('statusunknown'),
result::WARNING => get_string('statuswarning'),
result::CRITICAL => get_string('statuscritical'),
result::ERROR => get_string('statuserror'),
]);
$mform->addElement('select', 'override', get_string('override', 'tool_heartbeat'), override::get_status_list());

// Note.
$mform->addElement('textarea', 'note', get_string('notes', 'core_notes'), ['rows' => 3]);
Expand All @@ -67,6 +59,13 @@ public function definition() {
// URL.
$mform->addElement('text', 'url', get_string('url'), ['size' => 80]);
$mform->setType('url', PARAM_URL);
$urlregex = get_config('tool_heartbeat', 'muteurlregex');
if (!empty($urlregex)) {
$urlregex = stripslashes($urlregex);
$mform->addRule('url', get_string('required'), 'required', null, 'client');
$mform->addRule('url', get_string('muteurlregex', 'tool_heartbeat', $urlregex), 'regex', $urlregex, 'client');
$mform->addElement('static', 'url_help', '', get_string('muteurlregex', 'tool_heartbeat', $urlregex));
}

// Override until.
$mform->addElement('date_selector', 'expires_at', get_string('expiresat', 'tool_heartbeat'));
Expand Down
34 changes: 34 additions & 0 deletions classes/object/override.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

namespace tool_heartbeat\object;

use core\check\result;
use core\persistent;

/**
Expand All @@ -45,6 +46,7 @@ class override extends Persistent {
*/

public function __construct(int $id = 0, \stdClass $record = null) {
$this->set_default_status();
$this->set_default_expiry();
parent::__construct($id, $record);
}
Expand Down Expand Up @@ -99,6 +101,18 @@ private function set_default_expiry() {
$this->set('expires_at', strtotime($expiredate));
}

/**
* Sets the default override status
*
* @return void
*/
private function set_default_status() {
$defaultstatus = get_config('tool_heartbeat', 'mutedefaultstatus');
if (!empty($defaultstatus)) {
$this->set('override', $defaultstatus);
}
}

/**
* Resolves and unmutes a check.
*
Expand Down Expand Up @@ -204,4 +218,24 @@ public function get_time_until_mute_ends(): string {
$remainingtime = format_time($this->get('expires_at') - time());
return "$enddate ($remainingtime)";
}

/**
* Returns an array of statuses that can be used as an override
*
* @return array of status
*/
public static function get_status_list(): array {
// Moodle 3.9-3.11 sites that haven't backported MDL-71627 will be missing 'statusunknown'.
$unknown = (moodle_major_version() < '4.0') ? get_string('statusunknown', 'tool_heartbeat') : get_string('statusunknown');

return [
result::NA => get_string('statusna'),
result::OK => get_string('statusok'),
result::INFO => get_string('statusinfo'),
result::UNKNOWN => $unknown,
result::WARNING => get_string('statuswarning'),
result::CRITICAL => get_string('statuscritical'),
result::ERROR => get_string('statuserror'),
];
}
}
6 changes: 6 additions & 0 deletions lang/en/tool_heartbeat.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,14 @@
$string['editmute'] = 'Edit mute';
$string['overriderestore'] = 'Fields have been pre-filled with information from a previous override.';
$string['noterequired'] = 'Please add some notes';
$string['muteurlregex'] = 'The URL must match the regex defined in settings: {$a}';
$string['statusunknown'] = 'Unknown';
$string['settings:mutedefault'] = 'Default mute duration';
$string['settings:mutedefault:desc'] = 'Adjust the default duration of a check mute.';
$string['settings:mutedefaultstatus'] = 'Default mute status';
$string['settings:mutedefaultstatus:desc'] = 'Adjust the default status of a check mute.';
$string['settings:muteurlregex'] = 'Mute URL regex rule';
$string['settings:muteurlregex:desc'] = 'Adds a regex matching rule for check mute URLs and makes it a required field. The provided regex should include delimiters.';

$string['settings:cachecheckheading'] = 'Cache consistency check';
$string['settings:shouldlogcacheping:heading'] = 'Log cache ping';
Expand Down
10 changes: 10 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@
get_string('settings:mutedefault', 'tool_heartbeat'),
get_string('settings:mutedefault:desc', 'tool_heartbeat'), 12 * WEEKSECS, WEEKSECS));

$statuslist = tool_heartbeat\object\override::get_status_list();
reset($statuslist);
$settings->add(new admin_setting_configselect('tool_heartbeat/mutedefaultstatus',
get_string('settings:mutedefaultstatus', 'tool_heartbeat'),
get_string('settings:mutedefaultstatus:desc', 'tool_heartbeat'), key($statuslist), $statuslist));

$settings->add(new admin_setting_configtext('tool_heartbeat/muteurlregex',
get_string('settings:muteurlregex', 'tool_heartbeat'),
get_string('settings:muteurlregex:desc', 'tool_heartbeat'), '', PARAM_TEXT));

$example = '\logstore_standard\task\cleanup_task, 5, 5, 5';
$settings->add(new admin_setting_configtextarea('tool_heartbeat/tasklatencymonitoring',
get_string('tasklatencymonitoring', 'tool_heartbeat'),
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2024073000;
$plugin->release = 2024073000; // Match release exactly to version.
$plugin->version = 2024080200;
$plugin->release = 2024080200; // Match release exactly to version.
$plugin->requires = 2020061500; // Support for 3.9 and above, due to the Check API.
$plugin->supported = [39, 404];
$plugin->component = 'tool_heartbeat';
Expand Down

0 comments on commit 24ff951

Please sign in to comment.