Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: sort alerts by severity on the Alerts widget #8895

Merged
merged 6 commits into from Jul 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions html/includes/common/alerts.inc.php
Expand Up @@ -44,6 +44,7 @@
$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;">
Expand Down Expand Up @@ -140,6 +141,21 @@
</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">
Expand All @@ -156,6 +172,7 @@
$min_severity = $widget_settings['min_severity'];
$group = $widget_settings['group'];
$proc = $widget_settings['proc'];
$sort = $widget_settings['sort'];

$title = "Alerts";

Expand Down Expand Up @@ -194,6 +211,10 @@
}
}

if (!empty($sort)) {
$title = "$title " . "sorted by severity (higher first)";
}

$widget_settings['title'] = $title;

$group = $widget_settings['group'];
Expand Down Expand Up @@ -254,6 +275,10 @@
$common_output[] = "proc: '$proc',\n";
}

if (isset($sort) && sort != '') {
$common_output[] = "sort: '$sort',\n";
}

$common_output[] = '
device_id: \'' . $device['device_id'] . '\'
}
Expand Down
4 changes: 3 additions & 1 deletion html/includes/table/alerts.inc.php
Expand Up @@ -100,8 +100,10 @@
$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";
Expand Down