mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Add group filtering to alerts widget
* Add filtering by device_group to alerts widget * Allow searching by state == recovered
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
require_once $config['install_dir'].'/includes/device-groups.inc.php';
|
||||
|
||||
/* FIXME: is there a central place we can put this? */
|
||||
|
||||
$alert_states = array(
|
||||
@@ -23,6 +25,7 @@ if(defined('show_settings')) {
|
||||
$current_acknowledged = isset($widget_settings['acknowledged']) ? $widget_settings['acknowledged'] : '';
|
||||
$current_severity = isset($widget_settings['severity']) ? $widget_settings['severity'] : '';
|
||||
$current_state = isset($widget_settings['state']) ? $widget_settings['state'] : '';
|
||||
$current_group = isset($widget_settings['group']) ? $widget_settings['group'] : '';
|
||||
|
||||
$common_output[] = '
|
||||
<form class="form" onsubmit="widget_settings(this); return false;">
|
||||
@@ -73,6 +76,25 @@ if(defined('show_settings')) {
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="col-sm-4">
|
||||
<label for="group" class="control-label">Device Group:</label>
|
||||
</div>
|
||||
<div class="col-sm-8">
|
||||
<select class="form-control" name="group">';
|
||||
$common_output[] = '<option value=""'.($current_group == '' ? ' selected' : '').'>any group</option>';
|
||||
|
||||
$device_groups = GetDeviceGroups();
|
||||
$common_output[] = "<!-- ".print_r($device_groups, true)." -->";
|
||||
foreach ($device_groups as $group) {
|
||||
$group_id = $group['id'];
|
||||
$common_output[] = "<option value=\"$group_id\"".(is_numeric($current_group) && $current_group == $group_id ? ' selected' : '').">".$group['name']." - ".$group['description']."</option>";
|
||||
}
|
||||
$common_output[] = '
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-12">
|
||||
<button type="submit" class="btn btn-default">Set</button>
|
||||
@@ -86,6 +108,7 @@ else {
|
||||
$acknowledged = $widget_settings['acknowledged'];
|
||||
$state = $widget_settings['state'];
|
||||
$min_severity = $widget_settings['min_severity'];
|
||||
$group = $widget_settings['group'];
|
||||
|
||||
$common_output[] = "<!-- ".print_r($widget_settings, TRUE)." -->";
|
||||
$common_output[] = "<!-- ".print_r($acknowledged, TRUE)." -->";
|
||||
@@ -131,6 +154,10 @@ var alerts_grid = $("#alerts").bootgrid({
|
||||
$common_output[]="min_severity: '$min_severity',\n";
|
||||
}
|
||||
|
||||
if (is_numeric($group)) {
|
||||
$common_output[]="group: '$group',\n";
|
||||
}
|
||||
|
||||
$common_output[]='
|
||||
device_id: \'' . $device['device_id'] .'\'
|
||||
}
|
||||
|
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
require_once $config['install_dir'].'/includes/device-groups.inc.php';
|
||||
|
||||
$where = 1;
|
||||
|
||||
$alert_states = array(
|
||||
@@ -18,6 +20,8 @@ $alert_severities = array(
|
||||
'critical' => 3
|
||||
);
|
||||
|
||||
$show_recovered = FALSE;
|
||||
|
||||
if (is_numeric($_POST['device_id']) && $_POST['device_id'] > 0) {
|
||||
$where .= ' AND `alerts`.`device_id`='.$_POST['device_id'];
|
||||
}
|
||||
@@ -29,6 +33,9 @@ if (is_numeric($_POST['acknowledged'])) {
|
||||
|
||||
if (is_numeric($_POST['state'])) {
|
||||
$where .= " AND `alerts`.`state`=".$_POST['state'];
|
||||
if ($_POST['state'] == $alert_states['recovered']) {
|
||||
$show_recovered = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['min_severity'])) {
|
||||
@@ -43,8 +50,23 @@ if (isset($_POST['min_severity'])) {
|
||||
}
|
||||
}
|
||||
|
||||
if (is_numeric($_POST['group'])) {
|
||||
$group_pattern = dbFetchCell('SELECT `pattern` FROM `device_groups` WHERE id = '.$_POST['group']);
|
||||
$group_pattern = rtrim($group_pattern, '&&');
|
||||
$group_pattern = rtrim($group_pattern, '||');
|
||||
|
||||
$device_id_sql = GenGroupSQL($group_pattern);
|
||||
if ($device_id_sql) {
|
||||
$where .= " AND devices.device_id IN ($device_id_sql)";
|
||||
}
|
||||
}
|
||||
|
||||
if (!$show_recovered) {
|
||||
$where .= " AND `alerts`.`state`!=".$alert_states['recovered'];
|
||||
}
|
||||
|
||||
if (isset($searchPhrase) && !empty($searchPhrase)) {
|
||||
$sql_search .= " AND (`timestamp` LIKE '%$searchPhrase%' OR `rule` LIKE '%$searchPhrase%' OR `name` LIKE '%$searchPhrase%' OR `hostname` LIKE '%$searchPhrase%')";
|
||||
$where .= " AND (`timestamp` LIKE '%$searchPhrase%' OR `rule` LIKE '%$searchPhrase%' OR `name` LIKE '%$searchPhrase%' OR `hostname` LIKE '%$searchPhrase%')";
|
||||
}
|
||||
|
||||
$sql = ' FROM `alerts` LEFT JOIN `devices` ON `alerts`.`device_id`=`devices`.`device_id`';
|
||||
@@ -55,7 +77,7 @@ if (is_admin() === false && is_read() === false) {
|
||||
$param[] = $_SESSION['user_id'];
|
||||
}
|
||||
|
||||
$sql .= " RIGHT JOIN `alert_rules` ON `alerts`.`rule_id`=`alert_rules`.`id` WHERE $where AND `alerts`.`state`!=".$alert_states['recovered']." $sql_search";
|
||||
$sql .= " RIGHT JOIN `alert_rules` ON `alerts`.`rule_id`=`alert_rules`.`id` WHERE $where";
|
||||
|
||||
$count_sql = "SELECT COUNT(`alerts`.`id`) $sql";
|
||||
$total = dbFetchCell($count_sql, $param);
|
||||
|
Reference in New Issue
Block a user