2015-04-01 00:21:56 +01:00
< ? php
$where = 1 ;
if ( is_numeric ( $_POST [ 'device_id' ])) {
2015-07-13 20:10:26 +02:00
$where .= ' AND E.device_id = ?' ;
2015-04-01 00:21:56 +01:00
$param [] = $_POST [ 'device_id' ];
}
if ( $_SESSION [ 'userlevel' ] >= '5' ) {
$sql = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id WHERE $where " ;
2015-07-13 20:10:26 +02:00
}
else {
$sql = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id RIGHT JOIN devices_perms AS P ON E.device_id = P.device_id WHERE $where AND P.user_id = ? " ;
2015-04-22 20:51:14 +01:00
$param [] = array ( $_SESSION [ 'user_id' ]);
2015-04-01 00:21:56 +01:00
}
if ( isset ( $searchPhrase ) && ! empty ( $searchPhrase )) {
$sql .= " AND (`D`.`hostname` LIKE '% $searchPhrase %' OR `E`.`time_logged` LIKE '% $searchPhrase %' OR `name` LIKE '% $searchPhrase %') " ;
}
$count_sql = " SELECT COUNT(`E`.`id`) $sql " ;
2015-07-13 20:10:26 +02:00
$total = dbFetchCell ( $count_sql , $param );
2015-04-12 11:47:21 +01:00
if ( empty ( $total )) {
$total = 0 ;
}
2015-04-01 00:21:56 +01:00
if ( ! isset ( $sort ) || empty ( $sort )) {
$sort = 'time_logged DESC' ;
}
$sql .= " ORDER BY $sort " ;
if ( isset ( $current )) {
2015-07-13 20:10:26 +02:00
$limit_low = (( $current * $rowCount ) - ( $rowCount ));
2015-04-01 00:21:56 +01:00
$limit_high = $rowCount ;
}
if ( $rowCount != - 1 ) {
$sql .= " LIMIT $limit_low , $limit_high " ;
}
2015-05-22 13:38:52 +01:00
$sql = " SELECT D.device_id,name AS alert,state,time_logged,DATE_FORMAT(time_logged, ' " . $config [ 'dateformat' ][ 'mysql' ][ 'compact' ] . " ') as humandate,details $sql " ;
2015-04-01 00:21:56 +01:00
2015-05-17 11:44:33 +00:00
$rulei = 0 ;
2015-07-13 20:10:26 +02:00
foreach ( dbFetchRows ( $sql , $param ) as $alertlog ) {
$dev = device_by_id_cache ( $alertlog [ 'device_id' ]);
2015-05-17 11:44:33 +00:00
$fault_detail = alert_details ( $alertlog [ 'details' ]);
2015-07-13 20:10:26 +02:00
$alert_state = $alertlog [ 'state' ];
if ( $alert_state == '0' ) {
$glyph_icon = 'ok' ;
2015-04-01 00:21:56 +01:00
$glyph_color = 'green' ;
2015-07-13 20:10:26 +02:00
$text = 'Ok' ;
2015-04-01 00:21:56 +01:00
}
2015-07-13 20:10:26 +02:00
else if ( $alert_state == '1' ) {
$glyph_icon = 'remove' ;
2015-04-01 00:21:56 +01:00
$glyph_color = 'red' ;
2015-07-13 20:10:26 +02:00
$text = 'Alert' ;
2015-04-01 00:21:56 +01:00
}
2015-07-13 20:10:26 +02:00
else if ( $alert_state == '2' ) {
$glyph_icon = 'info-sign' ;
2015-04-01 00:21:56 +01:00
$glyph_color = 'lightgrey' ;
2015-07-13 20:10:26 +02:00
$text = 'Ack' ;
2015-04-01 00:21:56 +01:00
}
2015-07-13 20:10:26 +02:00
else if ( $alert_state == '3' ) {
$glyph_icon = 'arrow-down' ;
2015-04-01 00:21:56 +01:00
$glyph_color = 'orange' ;
2015-07-13 20:10:26 +02:00
$text = 'Worse' ;
2015-04-01 00:21:56 +01:00
}
2015-07-13 20:10:26 +02:00
else if ( $alert_state == '4' ) {
$glyph_icon = 'arrow-up' ;
2015-04-01 00:21:56 +01:00
$glyph_color = 'khaki' ;
2015-07-13 20:10:26 +02:00
$text = 'Better' ;
} //end if
$response [] = array (
'id' => $rulei ++ ,
'time_logged' => $alertlog [ 'humandate' ],
'details' => '<a class="glyphicon glyphicon-plus incident-toggle" style="display:none" data-toggle="collapse" data-target="#incident' . ( $rulei ) . '" data-parent="#alerts"></a>' ,
'hostname' => '<div class="incident">' . generate_device_link ( $dev , shorthost ( $dev [ 'hostname' ])) . '<div id="incident' . ( $rulei ) . '" class="collapse">' . $fault_detail . '</div></div>' ,
'alert' => htmlspecialchars ( $alertlog [ 'alert' ]),
'status' => " <b><span class='glyphicon glyphicon- " . $glyph_icon . " ' style='color: " . $glyph_color . " '></span> $text </b> " ,
);
} //end foreach
2015-04-01 00:21:56 +01:00
2015-07-13 20:10:26 +02:00
$output = array (
'current' => $current ,
'rowCount' => $rowCount ,
'rows' => $response ,
'total' => $total ,
);
echo _json_encode ( $output );