From 8ebec5c95582c0750a371707a46613be3d4c6b0d Mon Sep 17 00:00:00 2001 From: laf Date: Sun, 19 Apr 2015 23:19:13 +0100 Subject: [PATCH] Added ability to expand alerts to see triggers --- html/includes/print-alerts.php | 35 +++++++++++++++++++++++++++++- html/includes/table/alerts.inc.php | 22 ++++++++++++++----- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/html/includes/print-alerts.php b/html/includes/print-alerts.php index 944fdec19..dcef2447e 100644 --- a/html/includes/print-alerts.php +++ b/html/includes/print-alerts.php @@ -1,3 +1,6 @@ +
@@ -31,7 +34,8 @@ var grid = $("#alerts").bootgrid({ { return { id: "alerts", - device_id: '' + device_id: '', + format: '' }; }, url: "/ajax_table.php", @@ -42,6 +46,35 @@ var grid = $("#alerts").bootgrid({ "ack": function(column,row) { return ""; } + }, + templates: { + header: "
"+ + "
"+ +Alerts » "+'); + +$menu_options = array('basic' => 'Basic', + 'detail' => 'Detail'); + +$sep = ""; +foreach ($menu_options as $option => $text) +{ + echo("\"$sep\"+"); + if ($vars['format'] == $option) + { + echo("\"\"+"); + } + echo('" $option)) . '\">' . $text . '"+'); + if ($vars['format'] == $option) + { + echo("\"\"+"); + } + $sep = " | "; +} +?> + "
"+ + "

" } }).on("loaded.rs.jquery.bootgrid", function() { grid.find(".command-ack-alert").on("click", function(e) { diff --git a/html/includes/table/alerts.inc.php b/html/includes/table/alerts.inc.php index 82bce89ee..b230cf539 100644 --- a/html/includes/table/alerts.inc.php +++ b/html/includes/table/alerts.inc.php @@ -7,8 +7,7 @@ if (is_numeric($_POST['device_id']) && $_POST['device_id'] > 0) { } if (isset($searchPhrase) && !empty($searchPhrase)) { - $sql .= " AND (`timestamp` LIKE '%?%' OR `rule` LIKE '%?%' OR `name` LIKE '%?%' OR `hostname` LIKE '%?%')"; - $param[] = array($searchPhrase,$searchPhrase,$searchPhrase,$serchPhrase); + $sql .= " 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` RIGHT JOIN alert_rules ON alerts.rule_id=alert_rules.id WHERE $where AND `state` IN (1,2,3,4) $sql"; @@ -36,7 +35,9 @@ if ($rowCount != -1) { $sql = "SELECT `alerts`.*, `devices`.`hostname` AS `hostname`,`alert_rules`.`rule` AS `rule`, `alert_rules`.`name` AS `name`, `alert_rules`.`severity` AS `severity` $sql"; +system("echo '$sql' >> /tmp/testing"); $rulei = 0; +$format = $_POST['format']; foreach (dbFetchRows($sql,$param) as $alert) { $log = dbFetchCell("SELECT details FROM alert_log WHERE rule_id = ? AND device_id = ? ORDER BY id DESC LIMIT 1", array($alert['rule_id'],$alert['device_id'])); $log_detail = json_decode(gzuncompress($log),true); @@ -44,10 +45,16 @@ foreach (dbFetchRows($sql,$param) as $alert) { $fault_detail = ''; foreach ($tmp_alerts as $k=>$v) { if (!empty($v) && $k != 'device_id' && (stristr($k,'id') || stristr($k,'desc')) && substr_count($k,'_') <= 1) { - $fault_detail .= $k.' => '.$v.", "; + if ($format == 'basic') { + $fault_detail .= $k.' => '.$v."\n "; + } else { + $fault_detail .= $k.' => '.$v.", "; + } } } - $fault_detail = rtrim($fault_detail,", "); + if ($format == 'detail') { + $fault_detail = rtrim($fault_detail,", "); + } $fault_detail .= "\n"; } @@ -96,10 +103,15 @@ foreach (dbFetchRows($sql,$param) as $alert) { $ack_col = 'danger'; } } + if ($format == 'basic') { + $hostname = "".$alert['hostname'].""; + } else { + $hostname = "".$alert['hostname']."
$fault_detail
"; + } $response[] = array('id'=>"#".$rulei++."", 'rule'=>"".htmlentities($alert['name'])."", - 'hostname'=>"".$alert['hostname']."
$fault_detail
", + 'hostname'=>$hostname, 'timestamp'=>($alert['timestamp'] ? $alert['timestamp'] : "N/A"), 'severity'=>$severity, 'ack_col'=>$ack_col,