mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Added support for sorting alerts by severity on the Alerts widget (#8895)
Added feature to sort alerts by severity on the Alerts widget. DO NOT DELETE THIS TEXT #### Please note > Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting. - [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/) #### Testers If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
This commit is contained in:
@ -44,6 +44,7 @@ if (defined('SHOW_SETTINGS')) {
|
||||
$current_state = isset($widget_settings['state']) ? $widget_settings['state'] : '';
|
||||
$current_group = isset($widget_settings['group']) ? $widget_settings['group'] : '';
|
||||
$current_proc = isset($widget_settings['proc']) ? $widget_settings['proc'] : '';
|
||||
$current_sorting = isset($widget_settings['sort']) ? $widget_settings['sort'] : '';
|
||||
|
||||
$common_output[] = '
|
||||
<form class="form" onsubmit="widget_settings(this); return false;">
|
||||
@ -140,6 +141,21 @@ if (defined('SHOW_SETTINGS')) {
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="col-sm-4">
|
||||
<label for="sort" class="control-label">Sort alerts by: </label>
|
||||
</div>
|
||||
<div class="col-sm-8">
|
||||
<select class="form-control" name="sort">';
|
||||
$common_output[] = '<option value=""' . ($current_sorting == '' ? ' selected' : '')
|
||||
. '>timestamp, descending</option>';
|
||||
$common_output[] = '<option value="severity"' . ($current_sorting == 'severity' ? ' selected' : ' ')
|
||||
. '>severity, descending</option>';
|
||||
|
||||
$common_output[] = '
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-12">
|
||||
@ -156,6 +172,7 @@ if (defined('SHOW_SETTINGS')) {
|
||||
$min_severity = $widget_settings['min_severity'];
|
||||
$group = $widget_settings['group'];
|
||||
$proc = $widget_settings['proc'];
|
||||
$sort = $widget_settings['sort'];
|
||||
|
||||
$title = "Alerts";
|
||||
|
||||
@ -194,6 +211,10 @@ if (defined('SHOW_SETTINGS')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($sort)) {
|
||||
$title = "$title " . "sorted by severity (higher first)";
|
||||
}
|
||||
|
||||
$widget_settings['title'] = $title;
|
||||
|
||||
$group = $widget_settings['group'];
|
||||
@ -254,6 +275,10 @@ var alerts_grid = $("#alerts_' . $unique_id . '").bootgrid({
|
||||
$common_output[] = "proc: '$proc',\n";
|
||||
}
|
||||
|
||||
if (isset($sort) && sort != '') {
|
||||
$common_output[] = "sort: '$sort',\n";
|
||||
}
|
||||
|
||||
$common_output[] = '
|
||||
device_id: \'' . $device['device_id'] . '\'
|
||||
}
|
||||
|
@ -100,8 +100,10 @@ if (empty($total)) {
|
||||
$total = 0;
|
||||
}
|
||||
|
||||
if (!isset($sort) || empty($sort)) {
|
||||
if (!isset($vars['sort']) || empty($vars['sort'])) {
|
||||
$sort = 'timestamp DESC';
|
||||
} else {
|
||||
$sort = '`alert_rules`.`severity` DESC';
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY $sort";
|
||||
|
Reference in New Issue
Block a user