@@ -86,10 +108,46 @@ else {
$acknowledged = $widget_settings['acknowledged'];
$state = $widget_settings['state'];
$min_severity = $widget_settings['min_severity'];
+ $group = $widget_settings['group'];
- $common_output[] = "";
- $common_output[] = "";
+ $title = "Alerts";
+ // state can be 0 or '', be sure they are treated differently
+ if (is_numeric($state)) {
+ $state_name = array_search($state, $alert_states);
+ $title = "$title ($state_name)";
+ }
+ elseif ($state) {
+ $title = "$title ($state)";
+ }
+
+ if (is_numeric($acknowledged)) {
+ if ($acknowledged == '0') {
+ $title = "Unacknowledged $title";
+ }
+ elseif ($acknowledged == '1') {
+ $title = "Acknowledged $title";
+ }
+ }
+
+ if (is_numeric($group)) {
+ $group_row = dbFetchRow("SELECT * FROM device_groups WHERE id = ?", array($group));
+ if ($group_row) {
+ $title = "$title for ".$group_row['name'];
+ }
+ }
+
+ if ($min_severity) {
+ $sev_name = $min_severity;
+ if (is_numeric($min_severity)) {
+ $sev_name = array_search($min_severity, $alert_severities);
+ $title = "$title >=$sev_name";
+ }
+ }
+
+ $widget_settings['title'] = $title;
+
+ $group = $widget_settings['group'];
$common_output[] = '
@@ -131,6 +189,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'] .'\'
}
diff --git a/html/includes/table/alerts.inc.php b/html/includes/table/alerts.inc.php
index b0fbe62cc4..fdcf5cf05f 100644
--- a/html/includes/table/alerts.inc.php
+++ b/html/includes/table/alerts.inc.php
@@ -1,5 +1,7 @@
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);