2015-04-12 01:10:48 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< ? php  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*  
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 *  LibreNMS 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  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 . 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-29 07:36:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  Copyright  ( c )  2015  Søren  Friis  Rosiak  < sorenrosiak @ gmail . com > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  @ package     LibreNMS 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  @ subpackage  webui 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  @ link        http :// librenms . org 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  @ copyright   2017  LibreNMS 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  @ author      LibreNMS  Contributors 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*/  
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-11 07:51:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								use  LibreNMS\Authentication\LegacyAuth ;  
						 
					
						
							
								
									
										
										
										
											2018-04-07 15:55:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-12 01:10:48 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								$pagetitle []  =  " Alert Stats " ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-25 10:43:56 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$sql  =  " " ;  
						 
					
						
							
								
									
										
										
										
											2015-04-12 01:10:48 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								if  ( isset ( $device [ 'device_id' ])  &&  $device [ 'device_id' ]  >  0 )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $sql  =  "  AND alert_log.device_id=? " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $param  =  array ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $device [ 'device_id' ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-11 07:51:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								if  ( LegacyAuth :: user () -> hasGlobalRead ())  {  
						 
					
						
							
								
									
										
										
										
											2015-04-15 12:55:34 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    $query  =  " SELECT DATE_FORMAT(time_logged, ' " . $config [ 'alert_graph_date_format' ] . " ') Date, COUNT(alert_log.rule_id) totalCount, alert_rules.severity Severity FROM alert_log,alert_rules WHERE alert_log.rule_id=alert_rules.id AND `alert_log`.`state` != 0  $sql  GROUP BY DATE_FORMAT(time_logged, ' " . $config [ 'alert_graph_date_format' ] . " '),alert_rules.severity " ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-12 01:10:48 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-11 07:51:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								if  ( ! LegacyAuth :: user () -> hasGlobalRead ())  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $query  =  " SELECT DATE_FORMAT(time_logged, ' " . $config [ 'alert_graph_date_format' ] . " ') Date, COUNT(alert_log.device_id) totalCount, alert_rules.severity Severity FROM alert_log,alert_rules,devices_perms WHERE alert_log.rule_id=alert_rules.id AND `alert_log`.`state` != 0  $sql  AND alert_log.device_id = devices_perms.device_id AND devices_perms.user_id =  "  .  LegacyAuth :: id ()  .  "  GROUP BY DATE_FORMAT(time_logged, ' " . $config [ 'alert_graph_date_format' ] . " '),alert_rules.severity " ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-12 01:10:48 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								?> 
  
						 
					
						
							
								
									
										
										
										
											2017-12-29 07:36:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< br >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< div  class = " panel panel-default " >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < div  class = " panel-heading " > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Device  alerts 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    </ div > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < div  style = " margin:0 auto;width:99%; " > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-12 01:10:48 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< script  src = " js/vis.min.js " ></ script >  
						 
					
						
							
								
									
										
										
										
											2017-12-29 07:36:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< div  id = " visualization "  style = " margin-bottom: -120px; " ></ div >  
						 
					
						
							
								
									
										
										
										
											2015-04-12 01:10:48 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< script  type = " text/javascript " >  
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-12 01:10:48 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    var  container  =  document . getElementById ( 'visualization' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < ? php 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-18 20:28:22 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    $groups  =  array (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $max_count  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-12 01:10:48 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-18 20:28:22 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    foreach  ( dbFetchRows ( $query ,  $param )  as  $return_value )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $date  =  $return_value [ 'Date' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $count  =  $return_value [ 'totalCount' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( $count  >  $max_count )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $max_count  =  $count ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-12 01:10:48 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-18 20:28:22 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        $severity  =  $return_value [ 'Severity' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $data []  =  array ( 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-12 01:10:48 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        'x'  =>  $date , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        'y'  =>  $count , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        'group'  =>  $severity 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-18 20:28:22 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! in_array ( $severity ,  $groups ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            array_push ( $groups ,  $severity ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-12 01:10:48 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-18 20:28:22 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    $graph_data  =  _json_encode ( $data ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-12 01:10:48 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								?> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    var  groups  =  new  vis . DataSet (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< ? php  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-18 20:28:22 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								foreach  ( $groups  as  $group )  {  
						 
					
						
							
								
									
										
										
										
											2015-04-12 01:10:48 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    echo  " groups.add( { id: ' $group ', content: ' $group ' }) \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								?> 
  
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-12 01:10:48 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    var  items  = 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        < ? php 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-18 20:28:22 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        echo  $graph_data ;  ?> 
 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-12 01:10:48 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    var  dataset  =  new  vis . DataSet ( items ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    var  options  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        style : 'bar' , 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-18 15:26:44 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        barChart :  {  width : 50 ,  align : 'right' ,  sideBySide : true },  // align: left, center, right
 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-12 01:10:48 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        drawPoints :  false , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        legend :  { left : { position : " bottom-left " }}, 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        dataAxis :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            icons : true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            showMajorLabels :  true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            showMinorLabels :  true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }, 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-15 13:01:35 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        zoomMin :  86400 ,  //24hrs
 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-12 01:10:48 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        zoomMax :  < ? php 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-18 20:28:22 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        $first_date  =  reset ( $data ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $last_date  =  end ( $data ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-18 15:26:44 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        $milisec_diff  =  abs ( strtotime ( $first_date [ " x " ])  -  strtotime ( $last_date [ " x " ]))  *  1000 ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-18 20:28:22 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        echo  $milisec_diff ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-12 01:10:48 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								?> ,
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        orientation : 'top' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    var  graph2d  =  new  vis . Graph2d ( container ,  items ,  groups ,  options ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-15 12:35:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								</ script >