From 7aab831feb8777eb196a1686c520a0a503509e5c Mon Sep 17 00:00:00 2001 From: f0o Date: Sun, 17 May 2015 11:44:33 +0000 Subject: [PATCH] Show details of alert in the alert-logs Move alert-detail generation to own function --- html/includes/functions.inc.php | 29 ++++++++++++++++++++++++++++ html/includes/table/alertlog.inc.php | 10 +++++++--- html/includes/table/alerts.inc.php | 24 +---------------------- html/pages/alert-log.inc.php | 25 ++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 26 deletions(-) diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index 7118facdb9..68324611cf 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -777,4 +777,33 @@ function clean_bootgrid($string) { } +function alert_details($details) { + if( !is_array($details) ) { + $details = json_decode(gzuncompress($details),true); + } + $fault_detail = ''; + foreach( $details['rule'] as $o=>$tmp_alerts ) { + $fallback = true; + $fault_detail .= "#".($o+1).": "; + if( $tmp_alerts['bill_id'] ) { + $fault_detail .= ''.$tmp_alerts['bill_name'].'; '; + $fallback = false; + } + if( $tmp_alerts['port_id'] ) { + $fault_detail .= generate_port_link($tmp_alerts).'; '; + $fallback = false; + } + if( $fallback === true ) { + foreach( $tmp_alerts as $k=>$v ) { + if (!empty($v) && $k != 'device_id' && (stristr($k,'id') || stristr($k,'desc') || stristr($k,'msg')) && substr_count($k,'_') <= 1) { + $fault_detail .= "$k => '$v', "; + } + } + $fault_detail = rtrim($fault_detail,", "); + } + $fault_detail .= "
"; + } + return $fault_detail; +} + ?> diff --git a/html/includes/table/alertlog.inc.php b/html/includes/table/alertlog.inc.php index 0d15037c3d..860d6066fe 100644 --- a/html/includes/table/alertlog.inc.php +++ b/html/includes/table/alertlog.inc.php @@ -39,10 +39,12 @@ if ($rowCount != -1) { $sql .= " LIMIT $limit_low,$limit_high"; } -$sql = "SELECT D.device_id,name AS alert,state,time_logged,DATE_FORMAT(time_logged, '%D %b %Y %T') as humandate $sql"; +$sql = "SELECT D.device_id,name AS alert,state,time_logged,DATE_FORMAT(time_logged, '%D %b %Y %T') as humandate,details $sql"; +$rulei = 0; foreach (dbFetchRows($sql,$param) as $alertlog) { $dev = device_by_id_cache($alertlog['device_id']); + $fault_detail = alert_details($alertlog['details']); $alert_state = $alertlog['state']; if ($alert_state=='0') { $glyph_icon = 'ok'; @@ -69,8 +71,10 @@ foreach (dbFetchRows($sql,$param) as $alertlog) { $glyph_color = 'khaki'; $text = 'Better'; } - $response[] = array('time_logged'=>$alertlog['humandate'], - 'hostname'=>generate_device_link($dev, shorthost($dev['hostname'])), + $response[] = array('id'=>$rulei++, + 'time_logged'=>$alertlog['humandate'], + 'details'=>'', + 'hostname'=>'
'.generate_device_link($dev, shorthost($dev['hostname'])).'
'.$fault_detail.'
', 'alert'=>htmlspecialchars($alertlog['alert']), 'status'=>" $text"); } diff --git a/html/includes/table/alerts.inc.php b/html/includes/table/alerts.inc.php index fb23c6c841..da2a6d1c6a 100644 --- a/html/includes/table/alerts.inc.php +++ b/html/includes/table/alerts.inc.php @@ -39,29 +39,7 @@ $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); - $fault_detail = ''; - foreach ( $log_detail['rule'] as $o=>$tmp_alerts ) { - $fallback = true; - $fault_detail .= "#".($o+1).": "; - if( $tmp_alerts['bill_id'] ) { - $fault_detail .= ''.$tmp_alerts['bill_name'].'; '; - $fallback = false; - } - if( $tmp_alerts['port_id'] ) { - $fault_detail .= generate_port_link($tmp_alerts).'; '; - $fallback = false; - } - if( $fallback === true ) { - foreach ($tmp_alerts as $k=>$v) { - if (!empty($v) && $k != 'device_id' && (stristr($k,'id') || stristr($k,'desc') || stristr($k,'msg')) && substr_count($k,'_') <= 1) { - $fault_detail .= "$k => '$v', "; - } - } - $fault_detail = rtrim($fault_detail,", "); - } - $fault_detail .= "
"; - } + $fault_detail = alert_details($log); $ico = "ok"; $col = "green"; diff --git a/html/pages/alert-log.inc.php b/html/pages/alert-log.inc.php index 45cfac998d..44eeb404c6 100644 --- a/html/pages/alert-log.inc.php +++ b/html/pages/alert-log.inc.php @@ -17,10 +17,12 @@ $pagetitle[] = "Alert Log"; '); ?> +
+ @@ -28,6 +30,7 @@ $pagetitle[] = "Alert Log";
Time logged  Device alert Status
+