2015-04-01 00:21:56 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								< ? php 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:55:24 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/* 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  This  program  is  free  software :  you  can  redistribute  it  and / or  modify  it 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  under  the  terms  of  the  GNU  General  Public  License  as  published  by  the 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Free  Software  Foundation ,  either  version  3  of  the  License ,  or  ( at  your 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  option )  any  later  version .   Please  see  LICENSE . txt  at  the  top  level  of 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  the  source  code  distribution  for  details . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ package     LibreNMS 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ subpackage  graphs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ link        http :// librenms . org 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 22:50:09 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ copyright   2018  LibreNMS 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:55:24 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ author      LibreNMS  Contributors 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*/ 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-01 00:21:56 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								$where  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 22:50:09 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								if  ( is_numeric ( $vars [ 'device_id' ]))  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:55:24 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $where  .=  ' AND E.device_id = ?' ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 22:50:09 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $param []  =  $vars [ 'device_id' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-01 00:21:56 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 22:50:09 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								if  ( $vars [ 'state' ]  >=  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-02 19:40:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $where  .=  ' AND `E`.`state` = ?' ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 22:50:09 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $param []  =  mres ( $vars [ 'state' ]); 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-02 19:40:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-01 00:21:56 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								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 " ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-18 20:28:22 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:55:24 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $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 ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 22:50:09 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $sql  .=  "  AND (`D`.`hostname` LIKE '% $searchPhrase %' OR `D`.`sysName` LIKE '% $searchPhrase %' OR `E`.`time_logged` LIKE '% $searchPhrase %' OR `name` LIKE '% $searchPhrase %') " ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-01 00:21:56 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								$count_sql  =  " SELECT COUNT(`E`.`id`)  $sql " ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:55:24 +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 ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:55:24 +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 " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:55:24 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								$sql  =  " SELECT D.device_id,name AS alert,rule_id, 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 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:55:24 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $dev  =  device_by_id_cache ( $alertlog [ 'device_id' ]); 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-11 23:21:30 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    logfile ( $alertlog [ 'rule_id' ]); 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:55:24 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $log  =  dbFetchCell ( 'SELECT details FROM alert_log WHERE rule_id = ? AND device_id = ? AND `state` = 1 ORDER BY id DESC LIMIT 1' ,  array ( $alertlog [ 'rule_id' ],  $alertlog [ 'device_id' ])); 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-11 23:21:30 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $fault_detail  =  alert_details ( $log ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( empty ( $fault_detail ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $fault_detail  =  'Rule created, no faults found' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:55:24 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $alert_state  =  $alertlog [ 'state' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $alert_state  ==  '0' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:55:24 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $status  =  'label-success' ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-18 20:28:22 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  elseif  ( $alert_state  ==  '1' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:55:24 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $status  =  'label-danger' ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-18 20:28:22 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  elseif  ( $alert_state  ==  '2' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:55:24 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $status  =  'label-info' ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-18 20:28:22 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  elseif  ( $alert_state  ==  '3' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:55:24 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $status  =  'label-warning' ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-18 20:28:22 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  elseif  ( $alert_state  ==  '4' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:55:24 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $status  =  'label-primary' ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } //end if
 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:55:24 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $response []  =  array ( 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:55:24 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        'id'  =>  $rulei ++ , 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        'time_logged'  =>  $alertlog [ 'humandate' ], 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:55:24 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        'details'  =>  '<a class="fa fa-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'  =>  " <i class='alert-status  "  .  $status  .  " '></i> " 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} //end foreach
 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-01 00:21:56 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								$output  =  array ( 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:55:24 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    'current'  =>  $current , 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    'rowCount'  =>  $rowCount , 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:55:24 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    'rows'  =>  $response , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    'total'  =>  $total , 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								echo  _json_encode ( $output );