2010-02-15 01:26:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								< ? php 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 17:08:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/* 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-08 14:12:23 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  LibreNMS  Network  Management  and  Monitoring  System 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Copyright  ( C )  2006 - 2011 ,  Observium  Developers  -  http :// www . observium . org 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  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 . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  See  COPYING  for  more  details . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-09-11 15:26:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								use  LibreNMS\Config ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-21 08:07:14 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								use  LibreNMS\Exceptions\HostExistsException ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-08 14:14:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								use  LibreNMS\Util\IP ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								use  LibreNMS\Util\IPv6 ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-21 08:07:14 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  discover_new_device ( $hostname ,  $device  =  '' ,  $method  =  '' ,  $interface  =  '' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-11 15:26:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( Config :: has ( 'mydomain' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $full_host  =  rtrim ( $hostname ,  '.' )  .  '.'  .  Config :: get ( 'mydomain' ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-24 15:56:51 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( isDomainResolves ( $full_host ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $hostname  =  $full_host ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-24 15:56:51 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    d_echo ( " discovering  $hostname\n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-24 15:56:51 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $ip  =  gethostbyname ( $hostname ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( filter_var ( $ip ,  FILTER_VALIDATE_IP ,  FILTER_FLAG_IPV4 )  ===  false  &&  filter_var ( $ip ,  FILTER_VALIDATE_IP ,  FILTER_FLAG_IPV6 )  ===  false )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-07 19:43:25 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        // $ip isn't a valid IP so it must be a name.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-24 15:56:51 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( $ip  ==  $hostname )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            d_echo ( " name lookup of  $hostname  failed \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-14 00:32:02 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            log_event ( " $method  discovery of  "  .  $hostname  .  "  failed - Check name lookup " ,  $device [ 'device_id' ],  'discovery' ,  5 ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-29 15:12:51 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-07 19:43:25 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-24 15:56:51 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  elseif  ( filter_var ( $hostname ,  FILTER_VALIDATE_IP ,  FILTER_FLAG_IPV4 )  ===  true  ||  filter_var ( $hostname ,  FILTER_VALIDATE_IP ,  FILTER_FLAG_IPV6 )  ===  true )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-18 14:48:54 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        // gethostbyname returned a valid $ip, was $dst_host an IP?
 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-11 15:26:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( ! Config :: get ( 'discovery_by_ip' ,  false ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-24 15:56:51 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            d_echo ( 'Discovery by IP disabled, skipping '  .  $hostname ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-14 00:32:02 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            log_event ( " $method  discovery of  "  .  $hostname  .  "  failed - Discovery by IP disabled " ,  $device [ 'device_id' ],  'discovery' ,  4 ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-29 15:12:51 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-20 16:12:03 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-20 15:59:43 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    d_echo ( " ip lookup result:  $ip\n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-28 15:55:57 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-24 15:56:51 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $hostname  =  rtrim ( $hostname ,  '.' ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // remove trailing dot
 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-11 15:26:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( match_network ( Config :: get ( 'autodiscovery.nets-exclude' ),  $ip ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-20 15:59:43 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        d_echo ( " $ip  in an excluded network - skipping \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-09-11 15:26:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( match_network ( Config :: get ( 'nets' ),  $ip ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-07 12:16:40 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        try  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-11 15:26:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $remote_device_id  =  addHost ( $hostname ,  '' ,  '161' ,  'udp' ,  Config :: get ( 'distributed_poller_group' )); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $remote_device  =  device_by_id_cache ( $remote_device_id ,  1 ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            echo  '+['  .  $remote_device [ 'hostname' ]  .  '('  .  $remote_device [ 'device_id' ]  .  ')]' ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            discover_device ( $remote_device ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            device_by_id_cache ( $remote_device_id ,  1 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( $remote_device_id  &&  is_array ( $device )  &&  ! empty ( $method ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $extra_log  =  '' ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-04 08:08:23 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                $int  =  cleanPort ( $interface ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                if  ( is_array ( $int ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    $extra_log  =  ' (port '  .  $int [ 'label' ]  .  ') ' ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-14 00:32:02 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                log_event ( 'Device '  .  $remote_device [ 'hostname' ]  .  "  ( $ip )  $extra_log  autodiscovered through  $method  on  "  .  $device [ 'hostname' ],  $remote_device_id ,  'discovery' ,  1 ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-14 00:32:02 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                log_event ( " $method  discovery of  "  .  $remote_device [ 'hostname' ]  .  "  ( $ip ) failed - Check ping and SNMP access " ,  $device [ 'device_id' ],  'discovery' ,  5 ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            return  $remote_device_id ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-07 12:16:40 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        }  catch  ( HostExistsException  $e )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            // already have this device
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        }  catch  ( Exception  $e )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-18 22:43:55 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            log_event ( " $method  discovery of  "  .  $hostname  .  "  ( $ip ) failed -  "  .  $e -> getMessage (),  $device [ 'device_id' ],  'discovery' ,  5 ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-20 15:59:43 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        d_echo ( " $ip  not in a matched network - skipping \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } //end if
 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								//end discover_new_device()
 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-06-26 23:27:57 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  $device 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  load_discovery ( & $device ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-11 15:26:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $yaml_discovery  =  Config :: get ( 'install_dir' )  .  '/includes/definitions/discovery/'  .  $device [ 'os' ]  .  '.yaml' ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-26 23:27:57 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( file_exists ( $yaml_discovery ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $device [ 'dynamic_discovery' ]  =  Symfony\Component\Yaml\Yaml :: parse ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            file_get_contents ( $yaml_discovery ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    unset ( $yaml_discovery ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-04-28 16:50:00 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  discover_device ( & $device ,  $options  =  null ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-11 15:26:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    global  $valid ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $valid  =  array (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // Reset $valid array
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $attribs  =  get_dev_attribs ( $device [ 'device_id' ]); 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-22 09:49:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $device [ 'attribs' ]  =  $attribs ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-30 15:11:29 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $device [ 'snmp_max_repeaters' ]  =  $attribs [ 'snmp_max_repeaters' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-01-08 13:33:32 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $device_start  =  microtime ( true ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // Start counting device poll time
 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    echo  $device [ 'hostname' ]  .  ' '  .  $device [ 'device_id' ]  .  ' '  .  $device [ 'os' ]  .  ' ' ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-15 15:22:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $response  =  device_is_up ( $device ,  true ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $response [ 'status' ]  !==  '1' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $device [ 'os' ]  ==  'generic' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        // verify if OS has changed from generic
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $device [ 'os' ]  =  getHostOS ( $device ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-23 17:53:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( $device [ 'os' ]  !=  'generic' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            echo  " \n Device os was updated to  "  .  $device [ 'os' ]  .  '!' ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            dbUpdate ( array ( 'os'  =>  $device [ 'os' ]),  'devices' ,  '`device_id` = ?' ,  array ( $device [ 'device_id' ])); 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-06 21:04:23 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-09 02:16:09 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    load_os ( $device ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-26 23:27:57 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    load_discovery ( $device ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-14 00:43:14 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    register_mibs ( $device ,  Config :: getOsSetting ( $device [ 'os' ],  'register_mibs' ,  array ()),  'includes/discovery/os/'  .  $device [ 'os' ]  .  '.inc.php' ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-23 17:53:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    echo  " \n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // If we've specified modules, use them, else walk the modules array
 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-11 12:28:54 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $force_module  =  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $options [ 'm' ])  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-11 15:26:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        Config :: set ( 'discovery_modules' ,  array ()); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        foreach  ( explode ( ',' ,  $options [ 'm' ])  as  $module )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( is_file ( " includes/discovery/ $module .inc.php " ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-11 15:26:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                Config :: set ( " discovery_modules. $module " ,  1 ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-11 12:28:54 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                $force_module  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-24 15:32:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-11 15:26:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    foreach  ( Config :: get ( 'discovery_modules' ,  array ())  as  $module  =>  $module_status )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-14 00:43:14 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $os_module_status  =  Config :: getOsSetting ( $device [ 'os' ],  " discovery_modules. $module " ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-13 20:46:05 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        d_echo ( " Modules status: Global "  .  ( isset ( $module_status )  ?  ( $module_status  ?  '+ '  :  '- ' )  :  '  ' )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        d_echo ( " OS "  .  ( isset ( $os_module_status )  ?  ( $os_module_status  ?  '+ '  :  '- ' )  :  '  ' )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        d_echo ( " Device "  .  ( isset ( $attribs [ 'discover_'  .  $module ])  ?  ( $attribs [ 'discover_'  .  $module ]  ?  '+ '  :  '- ' )  :  '  ' )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $force_module  ===  true  || 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $attribs [ 'discover_'  .  $module ]  || 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            ( $os_module_status  &&  ! isset ( $attribs [ 'discover_'  .  $module ]))  || 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-15 15:22:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            ( $module_status  &&  ! isset ( $os_module_status )  &&  ! isset ( $attribs [ 'discover_'  .  $module ])) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-24 15:32:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $module_start  =  microtime ( true ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-08 04:54:30 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $start_memory  =  memory_get_usage (); 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-13 20:46:05 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            echo  " \n #### Load disco module  $module  #### \n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-24 15:32:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            include  " includes/discovery/ $module .inc.php " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $module_time  =  microtime ( true )  -  $module_start ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $module_time  =  substr ( $module_time ,  0 ,  5 ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-15 15:22:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $module_mem  =  ( memory_get_usage ()  -  $start_memory ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-08 04:54:30 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            printf ( " \n >> Runtime for discovery module '%s': %.4f seconds with %s bytes \n " ,  $module ,  $module_time ,  $module_mem ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-24 15:32:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            echo  " #### Unload disco module  $module  #### \n \n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        }  elseif  ( isset ( $attribs [ 'discover_'  .  $module ])  &&  $attribs [ 'discover_'  .  $module ]  ==  '0' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-24 15:32:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            echo  " Module [  $module  ] disabled on host. \n \n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-13 20:46:05 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        }  elseif  ( isset ( $os_module_status )  &&  $os_module_status  ==  '0' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            echo  " Module [  $module  ] disabled on os. \n \n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-24 15:32:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            echo  " Module [  $module  ] disabled globally. \n \n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-16 22:09:17 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( is_mib_poller_enabled ( $device ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $devicemib  =  array ( $device [ 'sysObjectID' ]  =>  'all' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        register_mibs ( $device ,  $devicemib ,  " includes/discovery/functions.inc.php " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-21 17:01:59 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $device_time   =  round ( microtime ( true )  -  $device_start ,  3 ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-11 16:36:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    dbUpdate ( array ( 'last_discovered'  =>  array ( 'NOW()' ),  'last_discovered_timetaken'  =>  $device_time ),  'devices' ,  '`device_id` = ?' ,  array ( $device [ 'device_id' ])); 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    echo  " Discovered in  $device_time  seconds \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    global  $discovered_devices ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    echo  " \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $discovered_devices ++ ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								//end discover_device()
 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 19:21:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-06-26 23:27:57 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// Discover sensors
 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-28 19:44:24 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  discover_sensor ( & $valid ,  $class ,  $device ,  $oid ,  $index ,  $type ,  $descr ,  $divisor  =  1 ,  $multiplier  =  1 ,  $low_limit  =  null ,  $low_warn_limit  =  null ,  $warn_limit  =  null ,  $high_limit  =  null ,  $current  =  null ,  $poller_type  =  'snmp' ,  $entPhysicalIndex  =  null ,  $entPhysicalIndex_measured  =  null ,  $user_func  =  null ,  $entity_link_type  =  null ,  $entity_link_index  =  0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-18 08:48:33 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $low_limit       =  set_null ( $low_limit ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $low_warn_limit  =  set_null ( $low_warn_limit ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $warn_limit      =  set_null ( $warn_limit ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $high_limit      =  set_null ( $high_limit ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-13 12:47:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( ! is_numeric ( $divisor ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $divisor   =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-03-12 09:56:56 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    d_echo ( " Discover sensor:  $oid ,  $index ,  $type ,  $descr ,  $poller_type ,  $divisor ,  $multiplier ,  $entPhysicalIndex ,  $current\n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 17:08:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( is_null ( $low_warn_limit )  &&  ! is_null ( $warn_limit ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        // Warn limits only make sense when we have both a high and a low limit
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $low_warn_limit  =  null ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $warn_limit  =  null ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-12 09:56:56 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  elseif  ( ! is_null ( $warn_limit )  &&  $low_warn_limit  >  $warn_limit )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        // Fix high/low thresholds (i.e. on negative numbers)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        list ( $warn_limit ,  $low_warn_limit )  =  array ( $low_warn_limit ,  $warn_limit ); 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-09 12:57:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( dbFetchCell ( 'SELECT COUNT(sensor_id) FROM `sensors` WHERE `poller_type`= ? AND `sensor_class` = ? AND `device_id` = ? AND sensor_type = ? AND `sensor_index` = ?' ,  array ( $poller_type ,  $class ,  $device [ 'device_id' ],  $type ,  $index ))  ==  '0' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-12 09:56:56 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( is_null ( $high_limit ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $high_limit  =  sensor_limit ( $class ,  $current ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 12:46:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-03-12 09:56:56 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( is_null ( $low_limit ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $low_limit  =  sensor_low_limit ( $class ,  $current ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-09 12:57:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-03-12 09:56:56 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( ! is_null ( $high_limit )  &&  $low_limit  >  $high_limit )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            // Fix high/low thresholds (i.e. on negative numbers)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            list ( $high_limit ,  $low_limit )  =  array ( $low_limit ,  $high_limit ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-09 12:57:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $insert  =  array ( 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            'poller_type'  =>  $poller_type , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'sensor_class'  =>  $class , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'device_id'  =>  $device [ 'device_id' ], 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'sensor_oid'  =>  $oid , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'sensor_index'  =>  $index , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'sensor_type'  =>  $type , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'sensor_descr'  =>  $descr , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'sensor_divisor'  =>  $divisor , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'sensor_multiplier'  =>  $multiplier , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'sensor_limit'  =>  $high_limit , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'sensor_limit_warn'  =>  $warn_limit , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'sensor_limit_low'  =>  $low_limit , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'sensor_limit_low_warn'  =>  $low_warn_limit , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'sensor_current'  =>  $current , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'entPhysicalIndex'  =>  $entPhysicalIndex , 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            'entPhysicalIndex_measured'  =>  $entPhysicalIndex_measured , 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-17 22:41:53 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            'user_func'  =>  $user_func , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-28 19:44:24 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            'entity_link_type'  =>  $entity_link_type , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'entity_link_index'  =>  $entity_link_index , 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        foreach  ( $insert  as  $key  =>  $val_check )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( ! isset ( $val_check ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                unset ( $insert [ $key ]); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $inserted  =  dbInsert ( $insert ,  'sensors' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-20 15:59:43 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        d_echo ( " (  $inserted  inserted ) \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        echo  '+' ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-14 00:32:02 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        log_event ( 'Sensor Added: '  .  mres ( $class )  .  ' '  .  mres ( $type )  .  ' '  .  mres ( $index )  .  ' '  .  mres ( $descr ),  $device ,  'sensor' ,  3 ,  $inserted ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $sensor_entry  =  dbFetchRow ( 'SELECT * FROM `sensors` WHERE `sensor_class` = ? AND `device_id` = ? AND `sensor_type` = ? AND `sensor_index` = ?' ,  array ( $class ,  $device [ 'device_id' ],  $type ,  $index )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( ! isset ( $high_limit ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( ! $sensor_entry [ 'sensor_limit' ])  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                // Calculate a reasonable limit
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $high_limit  =  sensor_limit ( $class ,  $current ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                // Use existing limit
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $high_limit  =  $sensor_entry [ 'sensor_limit' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2010-02-28 22:04:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( ! isset ( $low_limit ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( ! $sensor_entry [ 'sensor_limit_low' ])  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                // Calculate a reasonable limit
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $low_limit  =  sensor_low_limit ( $class ,  $current ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                // Use existing limit
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $low_limit  =  $sensor_entry [ 'sensor_limit_low' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        // Fix high/low thresholds (i.e. on negative numbers)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $low_limit  >  $high_limit )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            list ( $high_limit ,  $low_limit )  =  array ( $low_limit ,  $high_limit ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $high_limit  !=  $sensor_entry [ 'sensor_limit' ]  &&  $sensor_entry [ 'sensor_custom' ]  ==  'No' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $update  =  array ( 'sensor_limit'  =>  ( $high_limit  ==  null  ?  array ( 'NULL' )  :  $high_limit )); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $updated  =  dbUpdate ( $update ,  'sensors' ,  '`sensor_id` = ?' ,  array ( $sensor_entry [ 'sensor_id' ])); 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-20 15:59:43 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            d_echo ( " (  $updated  updated ) \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            echo  'H' ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-14 00:32:02 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            log_event ( 'Sensor High Limit Updated: '  .  mres ( $class )  .  ' '  .  mres ( $type )  .  ' '  .  mres ( $index )  .  ' '  .  mres ( $descr )  .  ' ('  .  $high_limit  .  ')' ,  $device ,  'sensor' ,  3 ,  $sensor_id ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $sensor_entry [ 'sensor_limit_low' ]  !=  $low_limit  &&  $sensor_entry [ 'sensor_custom' ]  ==  'No' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $update  =  array ( 'sensor_limit_low'  =>  ( $low_limit  ==  null  ?  array ( 'NULL' )  :  $low_limit )); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $updated  =  dbUpdate ( $update ,  'sensors' ,  '`sensor_id` = ?' ,  array ( $sensor_entry [ 'sensor_id' ])); 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-20 15:59:43 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            d_echo ( " (  $updated  updated ) \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            echo  'L' ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-14 00:32:02 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            log_event ( 'Sensor Low Limit Updated: '  .  mres ( $class )  .  ' '  .  mres ( $type )  .  ' '  .  mres ( $index )  .  ' '  .  mres ( $descr )  .  ' ('  .  $low_limit  .  ')' ,  $device ,  'sensor' ,  3 ,  $sensor_id ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $warn_limit  !=  $sensor_entry [ 'sensor_limit_warn' ]  &&  $sensor_entry [ 'sensor_custom' ]  ==  'No' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $update  =  array ( 'sensor_limit_warn'  =>  ( $warn_limit  ==  null  ?  array ( 'NULL' )  :  $warn_limit )); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $updated  =  dbUpdate ( $update ,  'sensors' ,  '`sensor_id` = ?' ,  array ( $sensor_entry [ 'sensor_id' ])); 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-20 15:59:43 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            d_echo ( " (  $updated  updated ) \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            echo  'WH' ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-14 00:32:02 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            log_event ( 'Sensor Warn High Limit Updated: '  .  mres ( $class )  .  ' '  .  mres ( $type )  .  ' '  .  mres ( $index )  .  ' '  .  mres ( $descr )  .  ' ('  .  $warn_limit  .  ')' ,  $device ,  'sensor' ,  3 ,  $sensor_id ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $sensor_entry [ 'sensor_limit_low_warn' ]  !=  $low_warn_limit  &&  $sensor_entry [ 'sensor_custom' ]  ==  'No' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $update  =  array ( 'sensor_limit_low_warn'  =>  ( $low_warn_limit  ==  null  ?  array ( 'NULL' )  :  $low_warn_limit )); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $updated  =  dbUpdate ( $update ,  'sensors' ,  '`sensor_id` = ?' ,  array ( $sensor_entry [ 'sensor_id' ])); 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-20 15:59:43 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            d_echo ( " (  $updated  updated ) \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            echo  'WL' ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-14 00:32:02 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            log_event ( 'Sensor Warn Low Limit Updated: '  .  mres ( $class )  .  ' '  .  mres ( $type )  .  ' '  .  mres ( $index )  .  ' '  .  mres ( $descr )  .  ' ('  .  $low_warn_limit  .  ')' ,  $device ,  'sensor' ,  3 ,  $sensor_id ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-04-13 04:52:07 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( $oid  ==  $sensor_entry [ 'sensor_oid' ]  && 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $descr  ==  $sensor_entry [ 'sensor_descr' ]  && 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $multiplier  ==  $sensor_entry [ 'sensor_multiplier' ]  && 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $divisor  ==  $sensor_entry [ 'sensor_divisor' ]  && 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $entPhysicalIndex_measured  ==  $sensor_entry [ 'entPhysicalIndex_measured' ]  && 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-17 22:41:53 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $entPhysicalIndex  ==  $sensor_entry [ 'entPhysicalIndex' ]  && 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-28 19:44:24 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $user_func  ==  $sensor_entry [ 'user_func' ]  && 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $entity_link_type  ==  $sensor_entry [ 'entity_link_type' ]  && 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $entity_link_index  ==  $sensor_entry [ 'entity_link_index' ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-04-13 04:52:07 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            echo  '.' ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $update  =  array ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'sensor_oid'  =>  $oid , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'sensor_descr'  =>  $descr , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'sensor_multiplier'  =>  $multiplier , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'sensor_divisor'  =>  $divisor , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'entPhysicalIndex'  =>  $entPhysicalIndex , 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                'entPhysicalIndex_measured'  =>  $entPhysicalIndex_measured , 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-17 22:41:53 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                'user_func'  =>  $user_func , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-28 19:44:24 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                'entity_link_type'  =>  $entity_link_type , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'entity_link_index'  =>  $entity_link_index , 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $updated  =  dbUpdate ( $update ,  'sensors' ,  '`sensor_id` = ?' ,  array ( $sensor_entry [ 'sensor_id' ])); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            echo  'U' ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-14 00:32:02 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            log_event ( 'Sensor Updated: '  .  mres ( $class )  .  ' '  .  mres ( $type )  .  ' '  .  mres ( $index )  .  ' '  .  mres ( $descr ),  $device ,  'sensor' ,  3 ,  $sensor_id ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-20 15:59:43 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            d_echo ( " (  $updated  updated ) \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } //end if
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $valid [ $class ][ $type ][ $index ]  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								//end discover_sensor()
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  sensor_low_limit ( $class ,  $current ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $limit  =  null ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    switch  ( $class )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        case  'temperature' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $limit  =  ( $current  *  0.7 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        case  'voltage' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( $current  <  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $limit  =  ( $current  *  ( 1  +  ( sgn ( $current )  *  0.15 ))); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $limit  =  ( $current  *  ( 1  -  ( sgn ( $current )  *  0.15 ))); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        case  'humidity' : 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-30 17:32:39 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $limit  =  '30' ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        case  'current' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $limit  =  null ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        case  'fanspeed' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $limit  =  ( $current  *  0.80 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        case  'power' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $limit  =  null ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            break ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-22 10:37:07 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        case  'signal' : 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-06 08:20:10 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $limit  =  - 80 ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-22 10:37:07 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            break ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-30 17:32:39 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        case  'airflow' : 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-23 16:28:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        case  'dbm' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        case  'snr' : 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-29 21:13:27 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        case  'frequency' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        case  'pressure' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        case  'cooling' : 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-30 17:32:39 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $limit  =  ( $current  *  0.95 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            break ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } //end switch
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  $limit ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								//end sensor_low_limit()
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  sensor_limit ( $class ,  $current ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $limit  =  null ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    switch  ( $class )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        case  'temperature' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $limit  =  ( $current  *  1.60 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        case  'voltage' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( $current  <  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $limit  =  ( $current  *  ( 1  -  ( sgn ( $current )  *  0.15 ))); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $limit  =  ( $current  *  ( 1  +  ( sgn ( $current )  *  0.15 ))); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        case  'humidity' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $limit  =  '70' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        case  'current' : 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-29 21:13:27 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        case  'power' : 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $limit  =  ( $current  *  1.50 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        case  'fanspeed' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $limit  =  ( $current  *  1.80 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            break ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        case  'signal' : 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-06 08:20:10 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $limit  =  - 30 ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-22 10:37:07 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            break ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-13 19:03:46 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        case  'load' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $limit  =  80 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            break ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-30 17:32:39 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        case  'airflow' : 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-23 16:28:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        case  'dbm' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        case  'snr' : 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-29 21:13:27 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        case  'frequency' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        case  'pressure' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        case  'cooling' : 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-30 17:32:39 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $limit  =  ( $current  *  1.05 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            break ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } //end switch
 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 19:21:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  $limit ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 19:21:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								//end sensor_limit()
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  check_valid_sensors ( $device ,  $class ,  $valid ,  $poller_type  =  'snmp' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $entries  =  dbFetchRows ( 'SELECT * FROM sensors AS S, devices AS D WHERE S.sensor_class=? AND S.device_id = D.device_id AND D.device_id = ? AND S.poller_type = ?' ,  array ( $class ,  $device [ 'device_id' ],  $poller_type )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( count ( $entries ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        foreach  ( $entries  as  $entry )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $index  =  $entry [ 'sensor_index' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $type  =  $entry [ 'sensor_type' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-12 23:27:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $class  =  $entry [ 'sensor_class' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            d_echo ( $index  .  ' -> '  .  $type  .  " \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( ! $valid [ $class ][ $type ][ $index ])  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                echo  '-' ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-12 23:27:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                if  ( $class  ==  'state' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    dbDelete ( 'sensors_to_state_indexes' ,  '`sensor_id` =  ?' ,  array ( $entry [ 'sensor_id' ])); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                } 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                dbDelete ( 'sensors' ,  '`sensor_id` =  ?' ,  array ( $entry [ 'sensor_id' ])); 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-14 00:32:02 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                log_event ( 'Sensor Deleted: '  .  $entry [ 'sensor_class' ]  .  ' '  .  $entry [ 'sensor_type' ]  .  ' '  .  $entry [ 'sensor_index' ]  .  ' '  .  $entry [ 'sensor_descr' ],  $device ,  'sensor' ,  3 ,  $sensor_id ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            unset ( $oid ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            unset ( $type ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								//end check_valid_sensors()
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-14 12:06:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  discover_juniAtmVp ( & $valid ,  $device ,  $port_id ,  $vp_id ,  $vp_descr ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-27 14:18:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    d_echo ( " Discover Juniper ATM VP:  $port_id ,  $vp_id ,  $vp_descr\n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( dbFetchCell ( 'SELECT COUNT(*) FROM `juniAtmVp` WHERE `port_id` = ? AND `vp_id` = ?' ,  array ( $port_id ,  $vp_id ))  ==  '0' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $inserted  =  dbInsert ( array ( 'port_id'  =>  $port_id ,  'vp_id'  =>  $vp_id ,  'vp_descr'  =>  $vp_descr ),  'juniAtmVp' ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-20 15:59:43 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        d_echo ( " (  $inserted  inserted ) \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        // FIXME vv no $device!
 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-14 12:06:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        log_event ( 'Juniper ATM VP Added: port '  .  mres ( $port_id )  .  ' vp '  .  mres ( $vp_id )  .  ' descr'  .  mres ( $vp_descr ),  $device ,  'juniAtmVp' ,  3 ,  $inserted ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        echo  '.' ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $valid [ $port_id ][ $vp_id ]  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								//end discover_juniAtmVp()
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  discover_link ( $local_port_id ,  $protocol ,  $remote_port_id ,  $remote_hostname ,  $remote_port ,  $remote_platform ,  $remote_version ,  $local_device_id ,  $remote_device_id ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-27 14:18:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    global  $link_exists ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-27 14:18:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    d_echo ( " Discover link:  $local_port_id ,  $protocol ,  $remote_port_id ,  $remote_hostname ,  $remote_port ,  $remote_platform ,  $remote_version\n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( dbFetchCell ( 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        'SELECT COUNT(*) FROM `links` WHERE `remote_hostname` = ? AND `local_port_id` = ? AND `protocol` = ? AND `remote_port` = ?' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        array ( 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                $remote_hostname , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $local_port_id , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $protocol , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $remote_port , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    )  ==  '0' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $insert_data  =  array ( 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            'local_port_id'  =>  $local_port_id , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'local_device_id'  =>  $local_device_id , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'protocol'  =>  $protocol , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'remote_hostname'  =>  $remote_hostname , 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            'remote_device_id'  =>  $remote_device_id , 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            'remote_port'  =>  $remote_port , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'remote_platform'  =>  $remote_platform , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'remote_version'  =>  $remote_version , 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( ! empty ( $remote_port_id ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $insert_data [ 'remote_port_id' ]  =  $remote_port_id ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $inserted  =  dbInsert ( $insert_data ,  'links' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        echo  '+' ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-20 15:59:43 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        d_echo ( " (  $inserted  inserted ) " ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $data  =  dbFetchRow ( 'SELECT * FROM `links` WHERE `remote_hostname` = ? AND `local_port_id` = ? AND `protocol` = ? AND `remote_port` = ?' ,  array ( $remote_hostname ,  $local_port_id ,  $protocol ,  $remote_port )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $data [ 'remote_port_id' ]  ==  $remote_port_id  &&  $data [ 'remote_platform' ]  ==  $remote_platform  &&  $remote_version  ==  $remote_version  &&  $data [ 'local_device_id' ]  >  0  &&  $data [ 'remote_device_id' ]  >  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            echo  '.' ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $update_data  =  array ( 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                'remote_platform'  =>  $remote_platform , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'remote_version'  =>  $remote_version , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'local_device_id'  =>  $local_device_id , 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                'remote_device_id'  =>  $remote_device_id , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( ! empty ( $remote_port_id ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $update_data [ 'remote_port_id' ]  =  $remote_port_id ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $updated  =  dbUpdate ( $update_data ,  'links' ,  '`id` = ?' ,  array ( $data [ 'id' ])); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            echo  'U' ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-20 15:59:43 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            d_echo ( " (  $updated  updated ) " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } //end if
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } //end if
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $link_exists [ $local_port_id ][ $remote_hostname ][ $remote_port ]  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								//end discover_link()
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  discover_storage ( & $valid ,  $device ,  $index ,  $type ,  $mib ,  $descr ,  $size ,  $units ,  $used  =  null ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-27 14:18:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    d_echo ( " Discover Storage:  $index ,  $type ,  $mib ,  $descr ,  $size ,  $units ,  $used\n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $descr  &&  $size  >  '0' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $storage  =  dbFetchRow ( 'SELECT * FROM `storage` WHERE `storage_index` = ? AND `device_id` = ? AND `storage_mib` = ?' ,  array ( $index ,  $device [ 'device_id' ],  $mib )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $storage  ===  false  ||  ! count ( $storage ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $insert  =  dbInsert ( 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                array ( 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-27 14:18:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    'device_id'  =>  $device [ 'device_id' ], 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'storage_descr'  =>  $descr , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'storage_index'  =>  $index , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'storage_mib'  =>  $mib , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'storage_type'  =>  $type , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'storage_units'  =>  $units , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'storage_size'  =>  $size , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'storage_used'  =>  $used , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                ), 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                'storage' 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            echo  '+' ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $updated  =  dbUpdate ( array ( 'storage_descr'  =>  $descr ,  'storage_type'  =>  $type ,  'storage_units'  =>  $units ,  'storage_size'  =>  $size ),  'storage' ,  '`device_id` = ? AND `storage_index` = ? AND `storage_mib` = ?' ,  array ( $device [ 'device_id' ],  $index ,  $mib )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( $updated )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                echo  'U' ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                echo  '.' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } //end if
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $valid [ $mib ][ $index ]  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } //end if
 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								//end discover_storage()
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  discover_processor ( & $valid ,  $device ,  $oid ,  $index ,  $type ,  $descr ,  $precision  =  '1' ,  $current  =  null ,  $entPhysicalIndex  =  null ,  $hrDeviceIndex  =  null ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-27 14:18:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    d_echo ( " Discover Processor:  $oid ,  $index ,  $type ,  $descr ,  $precision ,  $current ,  $entPhysicalIndex ,  $hrDeviceIndex\n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $descr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $descr  =  trim ( str_replace ( '"' ,  '' ,  $descr )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( dbFetchCell ( 'SELECT COUNT(processor_id) FROM `processors` WHERE `processor_index` = ? AND `device_id` = ? AND `processor_type` = ?' ,  array ( $index ,  $device [ 'device_id' ],  $type ))  ==  '0' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $insert_data  =  array ( 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                'device_id'  =>  $device [ 'device_id' ], 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'processor_descr'  =>  $descr , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'processor_index'  =>  $index , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'processor_oid'  =>  $oid , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'processor_usage'  =>  $current , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'processor_type'  =>  $type , 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                'processor_precision'  =>  $precision , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( ! empty ( $hrDeviceIndex ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $insert_data [ 'hrDeviceIndex' ]  =  $hrDeviceIndex ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( ! empty ( $entPhysicalIndex ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $insert_data [ 'entPhysicalIndex' ]  =  $entPhysicalIndex ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $inserted  =  dbInsert ( $insert_data ,  'processors' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            echo  '+' ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-14 00:32:02 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            log_event ( 'Processor added: type '  .  mres ( $type )  .  ' index '  .  mres ( $index )  .  ' descr '  .  mres ( $descr ),  $device ,  'processor' ,  3 ,  $inserted ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            echo  '.' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $update_data  =  array ( 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                'processor_descr'  =>  $descr , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'processor_oid'  =>  $oid , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'processor_usage'  =>  $current , 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                'processor_precision'  =>  $precision , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            dbUpdate ( $update_data ,  'processors' ,  '`device_id`=? AND `processor_index`=? AND `processor_type`=?' ,  array ( $device [ 'device_id' ],  $index ,  $type )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } //end if
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $valid [ $type ][ $index ]  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } //end if
 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								//end discover_processor()
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  discover_mempool ( & $valid ,  $device ,  $index ,  $type ,  $descr ,  $precision  =  '1' ,  $entPhysicalIndex  =  null ,  $hrDeviceIndex  =  null ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-27 14:18:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    d_echo ( " Discover Mempool:  $index ,  $type ,  $descr ,  $precision ,  $entPhysicalIndex ,  $hrDeviceIndex\n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // FIXME implement the mempool_perc, mempool_used, etc.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $descr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( dbFetchCell ( 'SELECT COUNT(mempool_id) FROM `mempools` WHERE `mempool_index` = ? AND `device_id` = ? AND `mempool_type` = ?' ,  array ( $index ,  $device [ 'device_id' ],  $type ))  ==  '0' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $insert_data  =  array ( 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                'device_id'  =>  $device [ 'device_id' ], 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'mempool_descr'  =>  $descr , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'mempool_index'  =>  $index , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'mempool_type'  =>  $type , 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                'mempool_precision'  =>  $precision , 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                'mempool_perc'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'mempool_used'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'mempool_free'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'mempool_total'  =>  0 , 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-06-28 22:03:35 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            if  ( is_numeric ( $entPhysicalIndex ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                $insert_data [ 'entPhysicalIndex' ]  =  $entPhysicalIndex ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-06-28 22:03:35 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            if  ( is_numeric ( $hrDeviceIndex ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                $insert_data [ 'hrDeviceIndex' ]  =  $hrDeviceIndex ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $inserted  =  dbInsert ( $insert_data ,  'mempools' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            echo  '+' ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-14 00:32:02 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            log_event ( 'Memory pool added: type '  .  mres ( $type )  .  ' index '  .  mres ( $index )  .  ' descr '  .  mres ( $descr ),  $device ,  'mempool' ,  3 ,  $inserted ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            echo  '.' ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-04 18:34:24 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $update_data  =  array ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'mempool_descr'  =>  $descr , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( ! empty ( $entPhysicalIndex ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $update_data [ 'entPhysicalIndex' ]  =  $entPhysicalIndex ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( ! empty ( $hrDeviceIndex ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $update_data [ 'hrDeviceIndex' ]  =  $hrDeviceIndex ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            dbUpdate ( $update_data ,  'mempools' ,  'device_id=? AND mempool_index=? AND mempool_type=?' ,  array ( $device [ 'device_id' ],  $index ,  $type )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } //end if
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $valid [ $type ][ $index ]  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } //end if
 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								//end discover_mempool()
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  discover_toner ( & $valid ,  $device ,  $oid ,  $index ,  $type ,  $descr ,  $capacity_oid  =  null ,  $capacity  =  null ,  $current  =  null ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-27 14:18:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    d_echo ( " Discover Toner:  $oid ,  $index ,  $type ,  $descr ,  $capacity_oid ,  $capacity ,  $current\n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-13 15:30:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( dbFetchCell ( 'SELECT COUNT(toner_id) FROM `toner` WHERE device_id = ? AND toner_type = ? AND `toner_index` = ? AND `toner_oid` =?' ,  array ( $device [ 'device_id' ],  $type ,  $index ,  $oid ))  ==  '0' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $inserted  =  dbInsert ( array ( 'device_id'  =>  $device [ 'device_id' ],  'toner_oid'  =>  $oid ,  'toner_capacity_oid'  =>  $capacity_oid ,  'toner_index'  =>  $index ,  'toner_type'  =>  $type ,  'toner_descr'  =>  $descr ,  'toner_capacity'  =>  $capacity ,  'toner_current'  =>  $current ),  'toner' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        echo  '+' ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-14 00:32:02 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        log_event ( 'Toner added: type '  .  mres ( $type )  .  ' index '  .  mres ( $index )  .  ' descr '  .  mres ( $descr ),  $device ,  'toner' ,  3 ,  $inserted ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $toner_entry  =  dbFetchRow ( 'SELECT * FROM `toner` WHERE `device_id` = ? AND `toner_type` = ? AND `toner_index` =?' ,  array ( $device [ 'device_id' ],  $type ,  $index )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $oid  ==  $toner_entry [ 'toner_oid' ]  &&  $descr  ==  $toner_entry [ 'toner_descr' ]  &&  $capacity  ==  $toner_entry [ 'toner_capacity' ]  &&  $capacity_oid  ==  $toner_entry [ 'toner_capacity_oid' ])  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            echo  '.' ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            dbUpdate ( array ( 'toner_descr'  =>  $descr ,  'toner_oid'  =>  $oid ,  'toner_capacity_oid'  =>  $capacity_oid ,  'toner_capacity'  =>  $capacity ),  'toner' ,  'device_id=? AND toner_type=? AND `toner_index`=?' ,  array ( $device [ 'device_id' ],  $type ,  $index )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            echo  'U' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-13 15:30:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $valid [ $type ][ $oid ]  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-04 10:45:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								//end discover_toner()
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  discover_process_ipv6 ( & $valid ,  $ifIndex ,  $ipv6_address ,  $ipv6_prefixlen ,  $ipv6_origin ,  $context_name  =  '' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-27 14:18:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    global  $device ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-08 14:14:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( ! IPv6 :: isValid ( $ipv6_address ,  true ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        // ignore link-locals (coming from IPV6-MIB)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-04 10:45:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-08 14:14:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $ipv6  =  new  IPv6 ( $ipv6_address ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $ipv6_network  =  $ipv6 -> getNetwork ( $ipv6_prefixlen ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $ipv6_compressed  =  $ipv6 -> compressed (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( dbFetchCell ( 'SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?' ,  array ( $device [ 'device_id' ],  $ifIndex ))  !=  '0'  &&  $ipv6_prefixlen  >  '0'  &&  $ipv6_prefixlen  <  '129'  &&  $ipv6_compressed  !=  '::1' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $port_id  =  dbFetchCell ( 'SELECT port_id FROM `ports` WHERE device_id = ? AND ifIndex = ?' ,  array ( $device [ 'device_id' ],  $ifIndex )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-04-25 21:28:25 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( is_numeric ( $port_id ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( dbFetchCell ( 'SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?' ,  array ( $ipv6_network ))  <  '1' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                dbInsert ( array ( 'ipv6_network'  =>  $ipv6_network ,  'context_name'  =>  $context_name ),  'ipv6_networks' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                echo  'N' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                //Update Context
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                dbUpdate ( array ( 'context_name'  =>  $device [ 'context_name' ]),  'ipv6_networks' ,  '`ipv6_network` = ?' ,  array ( $ipv6_network )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                echo  'n' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-02 12:21:45 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-04-25 21:28:25 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $ipv6_network_id  =  dbFetchCell ( 'SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?' ,  array ( $ipv6_network ,  $context_name )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( dbFetchCell ( 'SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ?' ,  array ( $ipv6_address ,  $ipv6_prefixlen ,  $port_id ))  ==  '0' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                dbInsert ( array ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'ipv6_address'  =>  $ipv6_address , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'ipv6_compressed'  =>  $ipv6_compressed , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'ipv6_prefixlen'  =>  $ipv6_prefixlen , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'ipv6_origin'  =>  $ipv6_origin , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'ipv6_network_id'  =>  $ipv6_network_id , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'port_id'  =>  $port_id , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'context_name'  =>  $context_name 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                ),  'ipv6_addresses' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                echo  '+' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                //Update Context
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                dbUpdate ( array ( 'context_name'  =>  $device [ 'context_name' ]),  'ipv6_addresses' ,  '`ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ?' ,  array ( $ipv6_address ,  $ipv6_prefixlen ,  $port_id )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                echo  '.' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-04 10:45:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-04-25 21:28:25 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $full_address  =  " $ipv6_address / $ipv6_prefixlen " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $valid_address  =  $full_address  .  '-'  .  $port_id ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $valid [ 'ipv6' ][ $valid_address ]  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } //end if
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} //end discover_process_ipv6()
 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-25 22:37:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Check  entity  sensors  to  be  excluded 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-29 15:12:51 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-25 22:37:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param  string  value  to  check 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  array  device 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  bool  true  if  sensor  is  valid 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *               false  if  sensor  is  invalid 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*/ 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  check_entity_sensor ( $string ,  $device ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-14 00:43:14 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $fringe  =  array_merge ( Config :: get ( 'bad_entity_sensor_regex' ,  array ()),  Config :: getOsSetting ( $device [ 'os' ],  'bad_entity_sensor_regex' ,  array ())); 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-11 15:26:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    foreach  ( $fringe  as  $bad )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( preg_match ( $bad  .  " i " ,  $string ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            d_echo ( " Ignored entity sensor:  $bad  :  $string " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-25 22:37:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-11 15:26:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-25 22:37:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-06 06:52:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-03-05 08:33:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Helper  function  to  improve  readability 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Can ' t  use  mib  based  polling ,  because  the  snmp  implentation  and  mibs  are  terrible 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-29 13:37:24 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param  array  $device  device  array 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  array  $sensor  array ( id ,  oid ,  type ,  descr ,  descr_oid ,  min ,  max ,  divisor ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  array  $valid  valid  sensors  array 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  bool 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-05 08:33:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-29 13:37:24 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  avtech_add_sensor ( $device ,  $sensor ,  & $valid ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-05 08:33:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // set the id, must be unique
 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-09 12:34:29 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( isset ( $sensor [ 'id' ]))  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-05 08:33:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $id  =  $sensor [ 'id' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-05 08:33:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        d_echo ( 'Error: No id set for this sensor'  .  " \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    d_echo ( 'Sensor id: '  .  $id  .  " \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // set the sensor oid
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $sensor [ 'oid' ])  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $oid  =  $sensor [ 'oid' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-05 08:33:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        d_echo ( 'Error: No oid set for this sensor'  .  " \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    d_echo ( 'Sensor oid: '  .  $oid  .  " \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-29 13:37:24 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // get the type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $type  =  $sensor [ 'type' ]  ?  $sensor [ 'type' ]  :  'temperature' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    d_echo ( 'Sensor type: '  .  $type  .  " \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-03-05 08:33:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // get the sensor value
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $value  =  snmp_get ( $device ,  $oid ,  '-OvQ' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // if the sensor doesn't exist abort
 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 15:33:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $value  ===  false  ||  ( $type  ==  'temperature'  &&  $value  ==  0 ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        //issue unfortunately some non-existant sensors return 0
 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-05 08:33:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        d_echo ( 'Error: sensor returned no data, skipping'  .  " \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    d_echo ( 'Sensor value: '  .  $value  .  " \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 15:33:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $type_name  =  $device [ 'os' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-03 21:44:21 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $type  ==  'switch' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        // set up state sensor
 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 15:33:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $type_name  .=  ucfirst ( $type ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-03 21:44:21 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $type  =  'state' ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 15:33:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $state_index_id  =  create_state_index ( $type_name ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-03 21:44:21 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        //Create State Translation
 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-04 10:06:31 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( isset ( $state_index_id ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-03 21:44:21 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $states  =  array ( 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 19:17:19 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                 array ( $state_index_id , 'Off' , 1 , 0 , - 1 ), 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                 array ( $state_index_id , 'On' , 1 , 1 , 0 ), 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-03 21:44:21 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								             ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            foreach  ( $states  as  $value )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-03 21:44:21 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                $insert  =  array ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'state_index_id'  =>  $value [ 0 ], 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'state_descr'  =>  $value [ 1 ], 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'state_draw_graph'  =>  $value [ 2 ], 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'state_value'  =>  $value [ 3 ], 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'state_generic_value'  =>  $value [ 4 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                dbInsert ( $insert ,  'state_translations' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-05 08:33:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // set the description
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $sensor [ 'descr_oid' ])  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-09 12:34:29 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $descr  =  trim ( snmp_get ( $device ,  $sensor [ 'descr_oid' ],  '-OvQ' ),  '"' ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  elseif  ( $sensor [ 'descr' ])  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-05 08:33:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $descr  =  $sensor [ 'descr' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-05 08:33:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        d_echo ( 'Error: No description set for this sensor'  .  " \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    d_echo ( 'Sensor description: '  .  $descr  .  " \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // set divisor
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $sensor [ 'divisor' ])  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $divisor  =  $sensor [ 'divisor' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  elseif  ( $type  ==  'temperature' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-05 08:33:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $divisor  =  100 ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 15:33:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $divisor  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-05 08:33:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    d_echo ( 'Sensor divisor: '  .  $divisor  .  " \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // set min for alarm
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $sensor [ 'min_oid' ])  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $min  =  snmp_get ( $device ,  $sensor [ 'min_oid' ],  '-OvQ' )  /  $divisor ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-05 08:33:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $min  =  null ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    d_echo ( 'Sensor alarm min: '  .  $min  .  " \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // set max for alarm
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $sensor [ 'max_oid' ])  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $max  =  snmp_get ( $device ,  $sensor [ 'max_oid' ],  '-OvQ' )  /  $divisor ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-05 08:33:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $max  =  null ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    d_echo ( 'Sensor alarm max: '  .  $max  .  " \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // add the sensor
 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 15:33:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    discover_sensor ( $valid [ 'sensor' ],  $type ,  $device ,  $oid ,  $id ,  $type_name ,  $descr ,  $divisor ,  '1' ,  $min ,  null ,  null ,  $max ,  $value / $divisor ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-03 21:44:21 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 15:33:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $type  ==  'state' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        create_sensor_to_state_index ( $device ,  $type_name ,  $id ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-03 21:44:21 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-03-05 08:33:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-18 19:38:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-03-10 04:47:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-18 19:38:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-10 04:47:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Get  the  device  divisor ,  account  for  device  specific  quirks 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  The  default  divisor  is  10 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  array  $device  device  array 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  string  $os_version  firmware  version  poweralert  quirks 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  string  $sensor_type  the  type  of  this  sensor 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  string  $oid  the  OID  of  this  sensor 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-18 19:38:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ return  int 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-10 04:47:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_device_divisor ( $device ,  $os_version ,  $sensor_type ,  $oid ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-18 19:38:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-27 22:40:15 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $device [ 'os' ]  ==  'poweralert' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-11 18:03:04 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( $sensor_type  ==  'current'  ||  $sensor_type  ==  'frequency' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-10 04:47:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            if  ( version_compare ( $os_version ,  '12.06.0068' ,  '>=' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                return  10 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            }  elseif  ( version_compare ( $os_version ,  '12.04.0055' ,  '=' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                return  10 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            }  elseif  ( version_compare ( $os_version ,  '12.04.0056' ,  '>=' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                return  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-11 00:38:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-10 04:47:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        }  elseif  ( $sensor_type  ==  'load' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( version_compare ( $os_version ,  '12.06.0064' ,  '=' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                return  10 ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-11 00:38:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-10 04:47:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                return  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-27 22:40:15 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-18 19:38:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-13 12:09:56 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  elseif  ( $device [ 'os' ]  ==  'huaweiups' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $sensor_type  ==  'frequency' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  100 ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-03 23:38:43 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-16 22:42:10 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  elseif  ( $device [ 'os' ]  ==  'hpe-rtups' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-13 12:09:56 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( $sensor_type  ==  'voltage'  &&  ! starts_with ( $oid ,  '.1.3.6.1.2.1.33.1.2.5.' )  &&  ! starts_with ( $oid ,  '.1.3.6.1.2.1.33.1.3.3.1.3' ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-16 22:42:10 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            return  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-18 19:38:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-10 04:47:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-13 12:09:56 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // UPS-MIB Defaults
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $sensor_type  ==  'load' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $sensor_type  ==  'voltage'  &&  ! starts_with ( $oid ,  '.1.3.6.1.2.1.33.1.2.5.' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-09-14 15:55:07 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $sensor_type  ==  'runtime' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( starts_with ( $oid ,  '.1.3.6.1.2.1.33.1.2.2.' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  60 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( starts_with ( $oid ,  '.1.3.6.1.2.1.33.1.2.3.' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-13 12:09:56 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  10 ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-18 19:38:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-03 19:49:23 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 18:14:18 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param  int  $raw_capacity  The  value  return  from  snmp 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  int  normalized  capacity  value 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-03 19:49:23 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 18:14:18 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_toner_capacity ( $raw_capacity ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-03 19:49:23 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 18:14:18 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // unknown or unrestricted capacity, assume 100
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( empty ( $raw_capacity )  ||  $raw_capacity  <  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  100 ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-03 19:49:23 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-14 18:14:18 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  $raw_capacity ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-03 19:49:23 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-30 20:50:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-13 13:43:21 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Should  we  ignore  this  storage  device  based  on  teh  description ?  ( usually  the  mount  path  or  drive ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  string  $os  The  OS  of  the  device 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  string  $descr  The  description  of  the  storage 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  boolean 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-30 20:50:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-13 13:43:21 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  ignore_storage ( $os ,  $descr ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-30 20:50:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-13 13:43:21 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    foreach  ( Config :: getOsSetting ( $os ,  'ignore_mount' )  as  $im )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $im  ==  $descr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            d_echo ( " ignored  $descr  (matched:  $im ) \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-11 15:26:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-30 20:50:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-09-13 13:43:21 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    foreach  ( Config :: getOsSetting ( $os ,  'ignore_mount_string' )  as  $ims )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( str_contains ( $descr ,  $ims ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            d_echo ( " ignored  $descr  (matched:  $ims ) \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-11 15:26:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-30 20:50:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-09-13 13:43:21 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    foreach  ( Config :: getOsSetting ( $os ,  'ignore_mount_regexp' )  as  $imr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( preg_match ( $imr ,  $descr ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            d_echo ( " ignored  $descr  (matched:  $imr ) \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-11 15:26:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-30 20:50:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-09-11 15:26:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-30 20:50:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-03 12:39:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-10 22:27:46 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  $value 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  $data 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  $group 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  can_skip_sensor ( $value ,  $data ,  $group ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $skip_values  =  array_replace (( array ) $group [ 'skip_values' ],  ( array ) $data [ 'skip_values' ]); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    foreach  ( $skip_values  as  $skip_value )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $value  ==  $skip_value )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-14 01:02:27 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $skip_value_lt  =  array_replace (( array ) $group [ 'skip_value_lt' ],  ( array ) $data [ 'skip_value_lt' ]); 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-10 22:27:46 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    foreach  ( $skip_value_lt  as  $skip_value )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $value  <  $skip_value )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-14 01:02:27 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $skip_value_gt  =  array_reduce (( array ) $group [ 'skip_value_gt' ],  ( array ) $data [ 'skip_value_gt' ]); 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-10 22:27:46 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    foreach  ( $skip_value_gt  as  $skip_value )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $value  >  $skip_value )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  $valid 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  $device 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  $sensor_type 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  $pre_cache 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-26 23:27:57 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  discovery_process ( & $valid ,  $device ,  $sensor_type ,  $pre_cache ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $device [ 'dynamic_discovery' ][ 'modules' ][ 'sensors' ][ $sensor_type ])  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-10 22:27:46 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $sensor_options  =  array (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( isset ( $device [ 'dynamic_discovery' ][ 'modules' ][ 'sensors' ][ $sensor_type ][ 'options' ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $sensor_options  =  $device [ 'dynamic_discovery' ][ 'modules' ][ 'sensors' ][ $sensor_type ][ 'options' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-03 13:58:39 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        d_echo ( " Dynamic Discovery ( $sensor_type ):  " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        d_echo ( $device [ 'dynamic_discovery' ][ 'modules' ][ 'sensors' ][ $sensor_type ]); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-10 22:27:46 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        foreach  ( $device [ 'dynamic_discovery' ][ 'modules' ][ 'sensors' ][ $sensor_type ][ 'data' ]  as  $data )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-26 23:27:57 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $tmp_name  =  $data [ 'oid' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-03 13:58:39 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $raw_data  =  ( array ) $pre_cache [ $tmp_name ]; 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-13 20:21:55 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $cached_data  =  $pre_cache [ '__cached' ]  ? :  array (); 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-03 13:58:39 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            d_echo ( " Data  $tmp_name :  " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            d_echo ( $raw_data ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-06-26 23:27:57 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            foreach  ( $raw_data  as  $index  =>  $snmp_data )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-03 13:58:39 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                // get the value for this sensor, check 'value' and 'oid', if state string, translate to a number
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $data_name  =  isset ( $data [ 'value' ])  ?  $data [ 'value' ]  :  $data [ 'oid' ];   // fallback to oid if value is not set
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                if  ( is_numeric ( $snmp_data [ $data_name ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    $value  =  $snmp_data [ $data_name ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                }  elseif  ( $sensor_type  ===  'state' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    // translate string states to values (poller does this as well)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    $states  =  array_column ( $data [ 'states' ],  'value' ,  'descr' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    $value  =  isset ( $states [ $snmp_data [ $data_name ]])  ?  $states [ $snmp_data [ $data_name ]]  :  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    $value  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                d_echo ( " Final sensor value:  $value\n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-10 22:27:46 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                if  ( can_skip_sensor ( $value ,  $data ,  $sensor_options )  ===  false  &&  is_numeric ( $value ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-26 23:27:57 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    $oid  =  $data [ 'num_oid' ]  .  $index ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    if  ( isset ( $snmp_data [ $data [ 'descr' ]]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        $descr  =  $snmp_data [ $data [ 'descr' ]]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        $descr  =  str_replace ( '{{ $index }}' ,  $index ,  $data [ 'descr' ]); 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-13 20:21:55 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        preg_match_all ( '/({{ [\$a-zA-Z0-9]+ }})/' ,  $descr ,  $tmp_var ,  PREG_PATTERN_ORDER ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        $tmp_vars  =  $tmp_var [ 0 ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        foreach  ( $tmp_vars  as  $k  =>  $tmp_var )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                            $tmp_var  =  preg_replace ( '/({{ | }}|\$)/' ,  '' ,  $tmp_var ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-14 03:12:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                            if  ( isset ( $snmp_data [ $tmp_var ]))  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-13 20:21:55 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                $descr  =  str_replace ( " { {   \$ $tmp_var  }} " ,  $snmp_data [ $tmp_var ],  $descr ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                            } 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-14 03:12:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                            if  ( isset ( $cached_data [ $index ][ $tmp_var ]))  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-13 20:21:55 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                $descr  =  str_replace ( " { {   \$ $tmp_var  }} " ,  $cached_data [ $index ][ $tmp_var ],  $descr ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                            } 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-19 22:06:59 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        } 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-26 23:27:57 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    } 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-14 01:02:27 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    $divisor  =  $data [ 'divisor' ]  ? :  ( $sensor_options [ 'divisor' ]  ? :  1 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    $multiplier  =  $data [ 'multiplier' ]  ? :  ( $sensor_options [ 'multiplier' ]  ? :  1 ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-19 22:06:59 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    $low_limit  =  is_numeric ( $data [ 'low_limit' ])  ?  $data [ 'low_limit' ]  :  ( $snmp_data [ $data [ 'low_limit' ]]  ? :  'null' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    $low_warn_limit  =  is_numeric ( $data [ 'low_warn_limit' ])  ?  $data [ 'low_warn_limit' ]  :  ( $snmp_data [ $data [ 'low_warn_limit' ]]  ? :  'null' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    $warn_limit  =  is_numeric ( $data [ 'warn_limit' ])  ?  $data [ 'warn_limit' ]  :  ( $snmp_data [ $data [ 'warn_limit' ]]  ? :  'null' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    $high_limit  =  is_numeric ( $data [ 'high_limit' ])  ?  $data [ 'high_limit' ]  :  ( $snmp_data [ $data [ 'high_limit' ]]  ? :  'null' ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-03 13:58:39 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    $sensor_name  =  $device [ 'os' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    if  ( $sensor_type  ===  'state' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        $sensor_name  =  $data [ 'state_name' ]  ? :  $data [ 'oid' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        create_state_index ( $sensor_name ,  $data [ 'states' ]); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-26 23:27:57 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        if  ( is_numeric ( $divisor ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                            $value  =  $value  /  $divisor ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        if  ( is_numeric ( $multiplier ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                            $value  =  $value  *  $multiplier ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    } 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-03 13:58:39 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    $uindex  =  str_replace ( '{{ $index }}' ,  $index ,  $data [ 'index' ]  ? :  $index ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    discover_sensor ( $valid [ 'sensor' ],  $sensor_type ,  $device ,  $oid ,  $uindex ,  $sensor_name ,  $descr ,  $divisor ,  $multiplier ,  $low_limit ,  $low_warn_limit ,  $warn_limit ,  $high_limit ,  $value ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-06-26 23:27:57 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    if  ( $sensor_type  ===  'state' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-03 13:58:39 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        create_sensor_to_state_index ( $device ,  $sensor_name ,  $uindex ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-26 23:27:57 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-03 12:39:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  $types 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  $device 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  array  $pre_cache 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  sensors ( $types ,  $device ,  $valid ,  $pre_cache  =  array ()) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-06 22:37:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    foreach  (( array ) $types  as  $sensor_type )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        echo  ucfirst ( $sensor_type )  .  ': ' ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-11 15:26:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $dir  =  Config :: get ( 'install_dir' )  .  '/includes/discovery/sensors/'  .  $sensor_type  . '/' ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-03 12:39:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( is_file ( $dir  .  $device [ 'os_group' ]  .  '.inc.php' ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-01 23:06:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            include  $dir  .  $device [ 'os_group' ]  .  '.inc.php' ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-03 12:39:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( is_file ( $dir  .  $device [ 'os' ]  .  '.inc.php' ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-01 23:06:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            include  $dir  .  $device [ 'os' ]  .  '.inc.php' ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-03 12:39:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-14 00:43:14 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( Config :: getOsSetting ( $device [ 'os' ],  'rfc1628_compat' ,  false ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-03 12:39:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            if  ( is_file ( $dir   .  '/rfc1628.inc.php' ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-01 23:06:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                include  $dir  .  '/rfc1628.inc.php' ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-03 12:39:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-26 23:27:57 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        discovery_process ( $valid ,  $device ,  $sensor_type ,  $pre_cache ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-06 22:37:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        d_echo ( $valid [ 'sensor' ][ $sensor_type ]); 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-06 15:39:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        check_valid_sensors ( $device ,  $sensor_type ,  $valid [ 'sensor' ]); 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-03 12:39:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        echo  " \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-11 23:16:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  build_bgp_peers ( $device ,  $data ,  $peer2 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    d_echo ( " Peers :  $data\n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $peers  =  trim ( str_replace ( 'ARISTA-BGP4V2-MIB::aristaBgp4V2PeerRemoteAs.1.' ,  '' ,  $data )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $peers  =  trim ( str_replace ( 'CISCO-BGP4-MIB::cbgpPeer2RemoteAs.' ,  '' ,  $peers )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $peers  =  trim ( str_replace ( 'BGP4-MIB::bgpPeerRemoteAs.' ,  '' ,  $peers )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $peers   =  trim ( str_replace ( '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.' ,  '' ,  $peers )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $peerlist  =  array (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $ver  =  '' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    foreach  ( explode ( " \n " ,  $peers )  as  $peer )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $peer2  ===  true )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            list ( $ver ,  $peer )  =  explode ( '.' ,  $peer ,  2 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        list ( $peer_ip ,  $peer_as )  =  explode ( ' ' ,  $peer ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $device [ 'os' ]  ===  'junos' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $ver  =  '' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $octets  =  count ( explode ( " . " ,  $peer_ip )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( $octets  >  11 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                // ipv6
 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-08 14:14:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                $peer_ip  =  ( string ) IP :: parse ( snmp2ipv6 ( implode ( '.' ,  array_slice ( explode ( '.' ,  $peer_ip ),  ( count ( explode ( '.' ,  $peer_ip ))  -  16 )))),  true ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-11 23:16:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                // ipv4
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $peer_ip  =  implode ( '.' ,  array_slice ( explode ( '.' ,  $peer_ip ),  ( count ( explode ( '.' ,  $peer_ip ))  -  4 ))); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( strstr ( $peer_ip ,  ':' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $peer_ip_snmp  =  preg_replace ( '/:/' ,  ' ' ,  $peer_ip ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $peer_ip  =  preg_replace ( '/(\S+\s+\S+)\s/' ,  '$1:' ,  $peer_ip_snmp ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $peer_ip  =  str_replace ( '"' ,  '' ,  str_replace ( ' ' ,  '' ,  $peer_ip )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $peer  &&  $peer_ip  !=  '0.0.0.0' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            d_echo ( " Found peer  $peer_ip  (AS $peer_as ) \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $peerlist []  =  array ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'ip'   =>  $peer_ip , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'as'   =>  $peer_as , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                'ver'  =>  $ver , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  $peerlist ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  build_cbgp_peers ( $device ,  $peer ,  $af_data ,  $peer2 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    d_echo ( 'afi data :: ' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    d_echo ( $af_data ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $af_list  =  array (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    foreach  ( $af_data  as  $k  =>  $v )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $peer2  ===  true )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            list (, $k )  =  explode ( '.' ,  $k ,  2 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        d_echo ( " AFISAFI =  $k\n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $afisafi_tmp  =  explode ( '.' ,  $k ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $safi         =  array_pop ( $afisafi_tmp ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $afi          =  array_pop ( $afisafi_tmp ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $bgp_ip       =  str_replace ( " . $afi . $safi " ,  '' ,  $k ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $device [ 'os_group' ]  ===  'arista' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $bgp_ip       =  str_replace ( " $afi . " ,  '' ,  $bgp_ip ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $bgp_ip       =  preg_replace ( '/:/' ,  ' ' ,  $bgp_ip ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $bgp_ip       =  preg_replace ( '/(\S+\s+\S+)\s/' ,  '$1:' ,  $bgp_ip ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $bgp_ip       =  str_replace ( '"' ,  '' ,  str_replace ( ' ' ,  '' ,  $bgp_ip )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $afi  &&  $safi  &&  $bgp_ip  ==  $peer [ 'ip' ])  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $af_list [ $bgp_ip ][ $afi ][ $safi ]  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            add_cbgp_peer ( $device ,  $peer ,  $afi ,  $safi ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  $af_list ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  add_bgp_peer ( $device ,  $peer ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( dbFetchCell ( 'SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ?' ,  array ( $device [ 'device_id' ],  $peer [ 'ip' ]))  <  '1' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $bgpPeers  =  array ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'device_id'  =>  $device [ 'device_id' ], 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'bgpPeerIdentifier'  =>  $peer [ 'ip' ], 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'bgpPeerRemoteAs'  =>  $peer [ 'as' ], 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'context_name'  =>  $device [ 'context_name' ], 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'astext'  =>  $peer [ 'astext' ], 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'bgpPeerState'  =>  'idle' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'bgpPeerAdminStatus'  =>  'stop' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'bgpLocalAddr'  =>  '0.0.0.0' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'bgpPeerRemoteAddr'  =>  '0.0.0.0' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'bgpPeerInUpdates'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'bgpPeerOutUpdates'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'bgpPeerInTotalMessages'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'bgpPeerOutTotalMessages'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'bgpPeerFsmEstablishedTime'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'bgpPeerInUpdateElapsedTime'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        dbInsert ( $bgpPeers ,  'bgpPeers' ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-11 15:26:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( Config :: get ( 'autodiscovery.bgp' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $name  =  gethostbyaddr ( $peer [ 'ip' ]); 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-11 23:16:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            discover_new_device ( $name ,  $device ,  'BGP' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        echo  '+' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        dbUpdate ( array ( 'bgpPeerRemoteAs'  =>  $peer [ 'as' ],  'astext'  =>  mres ( $peer [ 'astext' ])),  'bgpPeers' ,  'device_id=? AND bgpPeerIdentifier=?' ,  array ( $device [ 'device_id' ],  $peer [ 'ip' ])); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        echo  '.' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  add_cbgp_peer ( $device ,  $peer ,  $afi ,  $safi ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( dbFetchCell ( 'SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ? AND afi=? AND safi=?' ,  array ( $device [ 'device_id' ],  $peer [ 'ip' ],  $afi ,  $safi ))  ==  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $cbgp  =  array ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'device_id'  =>  $device [ 'device_id' ], 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'bgpPeerIdentifier'  =>  $peer [ 'ip' ], 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'afi'  =>  $afi , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'safi'  =>  $safi , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'context_name'  =>  $device [ 'context_name' ], 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'AcceptedPrefixes'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'DeniedPrefixes'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'PrefixAdminLimit'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'PrefixThreshold'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'PrefixClearThreshold'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'AdvertisedPrefixes'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'SuppressedPrefixes'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'WithdrawnPrefixes'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'AcceptedPrefixes_delta'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'AcceptedPrefixes_prev'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'DeniedPrefixes_delta'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'DeniedPrefixes_prev'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'AdvertisedPrefixes_delta'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'AdvertisedPrefixes_prev'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'SuppressedPrefixes_delta'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'SuppressedPrefixes_prev'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'WithdrawnPrefixes_delta'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'WithdrawnPrefixes_prev'  =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        dbInsert ( $cbgp ,  'bgpPeers_cbgp' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}