diff --git a/html/includes/common/alerts.inc.php b/html/includes/common/alerts.inc.php index b135ee48f..e5577b7b2 100644 --- a/html/includes/common/alerts.inc.php +++ b/html/includes/common/alerts.inc.php @@ -1,6 +1,97 @@ 0, + 'alerted' => 1, + 'acknowledged' => 2, + 'worse' => 3, + 'better' => 4 +); + +$alert_severities = array( + // alert_rules.status is enum('ok','warning','critical') + 'ok' => 1, + 'warning' => 2, + 'critical' => 3 +); + +//if( defined('show_settings') || empty($widget_settings) ) { +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'] : ''; + + $common_output[] = ' +
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+
+'; +} +else { + $device_id = $device['device_id']; + $acknowledged = $widget_settings['acknowledged']; + $state = $widget_settings['state']; + $min_severity = $widget_settings['min_severity']; + + $common_output[] = ""; + $common_output[] = ""; + + + $common_output[] = '
@@ -28,8 +119,21 @@ var alerts_grid = $("#alerts").bootgrid({ { return { id: "alerts", +'; + + if (is_numeric($acknowledged)) { + $common_output[]="acknowledged: '$acknowledged',\n"; + } + if (isset($state) && $state != '') { + $common_output[]="state: '$state',\n"; + } + if (isset($min_severity) && $min_severity != '') { + $common_output[]="min_severity: '$min_severity',\n"; + } + + $common_output[]=' device_id: \'' . $device['device_id'] .'\' - }; + } }, url: "ajax_table.php", formatters: { @@ -85,5 +189,5 @@ var alerts_grid = $("#alerts").bootgrid({ }); }); '; - +} diff --git a/html/includes/table/alerts.inc.php b/html/includes/table/alerts.inc.php index 9ea26d49b..b0fbe62cc 100644 --- a/html/includes/table/alerts.inc.php +++ b/html/includes/table/alerts.inc.php @@ -2,10 +2,47 @@ $where = 1; +$alert_states = array( + // divined from librenms/alerts.php + 'recovered' => 0, + 'alerted' => 1, + 'acknowledged' => 2, + 'worse' => 3, + 'better' => 4 +); + +$alert_severities = array( + // alert_rules.status is enum('ok','warning','critical') + 'ok' => 1, + 'warning' => 2, + 'critical' => 3 +); + if (is_numeric($_POST['device_id']) && $_POST['device_id'] > 0) { $where .= ' AND `alerts`.`device_id`='.$_POST['device_id']; } +if (is_numeric($_POST['acknowledged'])) { + // I assume that if we are searching for acknowleged/not, we aren't interested in recovered + $where .= " AND `alerts`.`state`".($_POST['acknowledged'] ? "=" : "!=").$alert_states['acknowledged']; +} + +if (is_numeric($_POST['state'])) { + $where .= " AND `alerts`.`state`=".$_POST['state']; +} + +if (isset($_POST['min_severity'])) { + if (is_numeric($_POST['min_severity'])) { + $min_severity_id = $_POST['min_severity']; + } + else if (!empty($_POST['min_severity'])) { + $min_severity_id = $alert_severities[$_POST['min_severity']]; + } + if (isset($min_severity_id)) { + $where .= " AND `alert_rules`.`severity` >= ".$min_severity_id; + } +} + if (isset($searchPhrase) && !empty($searchPhrase)) { $sql_search .= " AND (`timestamp` LIKE '%$searchPhrase%' OR `rule` LIKE '%$searchPhrase%' OR `name` LIKE '%$searchPhrase%' OR `hostname` LIKE '%$searchPhrase%')"; } @@ -18,7 +55,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 `state` IN (1,2,3,4) $sql_search"; +$sql .= " RIGHT JOIN `alert_rules` ON `alerts`.`rule_id`=`alert_rules`.`id` WHERE $where AND `alerts`.`state`!=".$alert_states['recovered']." $sql_search"; $count_sql = "SELECT COUNT(`alerts`.`id`) $sql"; $total = dbFetchCell($count_sql, $param);