2010-02-15 01:26:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								< ? php 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 17:08:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*  Observium  Network  Management  and  Monitoring  System 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  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 . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  discover_new_device ( $hostname ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  global  $config ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-09-20 14:22:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  if  ( $config [ 'autodiscovery' ][ 'xdp' ])  { 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  (  isDomainResolves ( $hostname  .  " . "  .  $config [ 'mydomain' ])  )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      $dst_host  =  $hostname  .  " . "  .  $config [ 'mydomain' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      $dst_host  =  $hostname ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $ip  =  gethostbyname ( $dst_host ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  (  match_network ( $config [ 'nets' ],  $ip )  ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-16 14:54:10 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      $remote_device_id  =  addHost  ( $dst_host ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-20 14:22:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      if  ( $remote_device_id )  { 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $remote_device  =  device_by_id_cache ( $remote_device_id ,  1 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        echo ( " +[ " . $remote_device [ 'hostname' ] . " ( " . $remote_device [ 'device_id' ] . " )] " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        discover_device ( $remote_device ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $remote_device  =  device_by_id_cache ( $remote_device_id ,  1 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  $remote_device_id ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  FALSE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  discover_device ( $device ,  $options  =  NULL ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:45:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  global  $config ,  $valid ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-25 12:24:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  $valid  =  array ();  // Reset $valid array
 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  $attribs  =  get_dev_attribs ( $device [ 'device_id' ]); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  $device_start  =  utime ();   // Start counting device poll time
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  echo ( $device [ 'hostname' ]  .  "   " . $device [ 'device_id' ] . "   " . $device [ 'os' ] . "   " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-09-20 14:22:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  if  ( $device [ 'os' ]  ==  'generic' )  // verify if OS has changed from generic
 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      $device [ 'os' ] =  getHostOS ( $device ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-20 14:22:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      if  ( $device [ 'os' ]  !=  'generic' ) 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      { 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-15 22:21:57 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								          echo  " \n Device os was updated to  " . $device [ 'os' ] . " ! " ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								          dbUpdate ( array ( 'os'  =>  $device [ 'os' ]),  'devices' ,  '`device_id` = ?' ,  array ( $device [ 'device_id' ])); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  if  ( $config [ 'os' ][ $device [ 'os' ]][ 'group' ]) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $device [ 'os_group' ]  =  $config [ 'os' ][ $device [ 'os' ]][ 'group' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-07 18:21:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    echo ( "  ( " . $device [ 'os_group' ] . " ) " ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  echo ( " \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-25 12:24:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  // If we've specified a module, use that, else walk the modules array
 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  if  ( $options [ 'm' ]) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( is_file ( " includes/discovery/ " . $options [ 'm' ] . " .inc.php " )) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      include ( " includes/discovery/ " . $options [ 'm' ] . " .inc.php " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2011-10-04 09:10:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    foreach  ( $config [ 'discovery_modules' ]  as  $module  =>  $module_status ) 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      if  ( $attribs [ 'discover_' . $module ]  ||  (  $module_status  &&  ! isset ( $attribs [ 'discover_' . $module ]))) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        include ( 'includes/discovery/' . $module . '.inc.php' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      }  elseif  ( isset ( $attribs [ 'discover_' . $module ])  &&  $attribs [ 'discover_' . $module ]  ==  " 0 " )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        echo ( " Module [  $module  ] disabled on host. \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        echo ( " Module [  $module  ] disabled globally. \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-25 12:24:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  // Set type to a predefined type for the OS if it's not already set
 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-15 15:03:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  if  ( $device [ 'type' ]  ==  " unknown "  ||  $device [ 'type' ]  ==  " " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $config [ 'os' ][ $device [ 'os' ]][ 'type' ]) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      $device [ 'type' ]  =  $config [ 'os' ][ $device [ 'os' ]][ 'type' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  $device_end  =  utime ();  $device_run  =  $device_end  -  $device_start ;  $device_time  =  substr ( $device_run ,  0 ,  5 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  dbUpdate ( array ( 'last_discovered'  =>  array ( 'NOW()' ),  'type'  =>  $device [ 'type' ],  'last_discovered_timetaken'  =>  $device_time ),  'devices' ,  '`device_id` = ?' ,  array ( $device [ 'device_id' ])); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  echo ( " Discovered in  $device_time  seconds \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  global  $discovered_devices ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  echo ( " \n " );  $discovered_devices ++ ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-25 12:24:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// Discover sensors
 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 22:10:23 +00: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 ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-07-07 14:55:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  global  $config ,  $debug ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-20 18:23:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  if  ( $debug )  {  echo ( " Discover sensor:  $oid ,  $index ,  $type ,  $descr ,  $poller_type ,  $precision ,  $entPhysicalIndex\n " );  } 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 12:46:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-04-09 12:57:02 +00: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 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $warn_limit  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  elseif  ( $low_warn_limit  >  $warn_limit ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // Fix high/low thresholds (i.e. on negative numbers)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    list ( $warn_limit ,  $low_warn_limit )  =  array ( $low_warn_limit ,  $warn_limit ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-09 15:30:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 19:21:20 +00: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' ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-07-07 14:55:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  { 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( ! $high_limit )  {  $high_limit  =  sensor_limit ( $class ,  $current );  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( ! $low_limit )   {  $low_limit   =  sensor_low_limit ( $class ,  $current );  } 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 12:46:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-04-09 12:57:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $low_limit  >  $high_limit ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      // Fix high/low thresholds (i.e. on negative numbers)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      list ( $high_limit ,  $low_limit )  =  array ( $low_limit ,  $high_limit ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 19:21:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $insert  =  array ( 'poller_type'  =>  $poller_type ,  'sensor_class'  =>  $class ,  'device_id'  =>  $device [ 'device_id' ],  'sensor_oid'  =>  $oid ,  'sensor_index'  =>  $index ,  'sensor_type'  =>  $type ,  'sensor_descr'  =>  $descr , 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-20 09:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    'sensor_divisor'  =>  $divisor ,  'sensor_multiplier'  =>  $multiplier ,  'sensor_limit'  =>  $high_limit ,  'sensor_limit_warn'  =>  $warn_limit ,  'sensor_limit_low'  =>  $low_limit , 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-25 16:16:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    'sensor_limit_low_warn'  =>  $low_warn_limit ,  'sensor_current'  =>  $current ,  'entPhysicalIndex'  =>  $entPhysicalIndex ,  'entPhysicalIndex_measured'  =>  $entPhysicalIndex_measured  ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 19:21:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $inserted  =  dbInsert ( $insert ,  'sensors' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $debug )  {  echo ( " (  $inserted  inserted ) \n " );  } 
							 
						 
					
						
							
								
									
										
										
										
											2010-07-07 14:55:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    echo ( " + " ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-04-03 19:36:32 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    log_event ( " Sensor Added:  " . mres ( $class ) . "   " . mres ( $type ) . "   " .  mres ( $index ) . "   " . mres ( $descr ),  $device ,  'sensor' ,  mysql_insert_id ()); 
							 
						 
					
						
							
								
									
										
										
										
											2010-07-07 14:55:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  { 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 19:21:20 +00: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 )); 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 12:46:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-09-28 14:30:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( ! isset ( $high_limit )) 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      if  ( ! $sensor_entry [ 'sensor_limit' ]) 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 17:08:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      { 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-09 12:57:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        // Calculate a reasonable limit
 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-28 14:30:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $high_limit  =  sensor_limit ( $class ,  $current ); 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 17:08:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-09 12:57:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        // Use existing limit
 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 17:08:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $high_limit  =  $sensor_entry [ 'sensor_limit' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-09-28 14:30:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( ! isset ( $low_limit )) 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      if  ( ! $sensor_entry [ 'sensor_limit_low' ]) 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 17:08:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      { 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-09 12:57:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        // Calculate a reasonable limit
 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-28 14:30:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $low_limit  =  sensor_low_limit ( $class ,  $current ); 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 17:08:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-09 12:57:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        // Use existing limit
 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 17:08:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $low_limit  =  $sensor_entry [ 'sensor_limit_low' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-04-09 12:57:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // 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' ]) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      $update  =  array ( 'sensor_limit'  =>  ( $high_limit  ==  NULL  ?  array ( 'NULL' )  :  $high_limit )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      $updated  =  dbUpdate ( $update ,  'sensors' ,  '`sensor_id` = ?' ,  array ( $sensor_entry [ 'sensor_id' ])); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      if  ( $debug )  {  echo ( " (  $updated  updated ) \n " );  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      echo ( " H " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      log_event ( " Sensor High Limit Updated:  " . mres ( $class ) . "   " . mres ( $type ) . "   " .  mres ( $index ) . "   " . mres ( $descr ) . "  ( " . $high_limit . " ) " ,  $device ,  'sensor' ,  $sensor_id ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 17:08:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $sensor_entry [ 'sensor_limit_low' ]  !=  $low_limit ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-28 17:08:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      $update  =  array ( 'sensor_limit_low'  =>  ( $low_limit  ==  NULL  ?  array ( 'NULL' )  :  $low_limit )); 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 22:21:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      $updated  =  dbUpdate ( $update ,  'sensors' ,  '`sensor_id` = ?' ,  array ( $sensor_entry [ 'sensor_id' ])); 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 19:21:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      if  ( $debug )  {  echo ( " (  $updated  updated ) \n " );  } 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 12:46:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      echo ( " L " ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-04-03 19:36:32 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      log_event ( " Sensor Low Limit Updated:  " . mres ( $class ) . "   " . mres ( $type ) . "   " .  mres ( $index ) . "   " . mres ( $descr ) . "  ( " . $low_limit . " ) " ,  $device ,  'sensor' ,  $sensor_id ); 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 12:46:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-04-09 12:57:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $warn_limit  !=  $sensor_entry [ 'sensor_limit_warn' ]) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      $update  =  array ( 'sensor_limit_warn'  =>  ( $warn_limit  ==  NULL  ?  array ( 'NULL' )  :  $warn_limit )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      $updated  =  dbUpdate ( $update ,  'sensors' ,  '`sensor_id` = ?' ,  array ( $sensor_entry [ 'sensor_id' ])); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      if  ( $debug )  {  echo ( " (  $updated  updated ) \n " );  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      echo ( " WH " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      log_event ( " Sensor Warn High Limit Updated:  " . mres ( $class ) . "   " . mres ( $type ) . "   " .  mres ( $index ) . "   " . mres ( $descr ) . "  ( " . $warn_limit . " ) " ,  $device ,  'sensor' ,  $sensor_id ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $sensor_entry [ 'sensor_limit_low_warn' ]  !=  $low_warn_limit ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      $update  =  array ( 'sensor_limit_low_warn'  =>  ( $low_warn_limit  ==  NULL  ?  array ( 'NULL' )  :  $low_warn_limit )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      $updated  =  dbUpdate ( $update ,  'sensors' ,  '`sensor_id` = ?' ,  array ( $sensor_entry [ 'sensor_id' ])); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      if  ( $debug )  {  echo ( " (  $updated  updated ) \n " );  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      echo ( " WL " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      log_event ( " Sensor Warn Low Limit Updated:  " . mres ( $class ) . "   " . mres ( $type ) . "   " .  mres ( $index ) . "   " . mres ( $descr ) . "  ( " . $low_warn_limit . " ) " ,  $device ,  'sensor' ,  $sensor_id ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 22:10:23 +00: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' ]  &&  $entPhysicalIndex  ==  $sensor_entry [ 'entPhysicalIndex' ]) 
							 
						 
					
						
							
								
									
										
										
										
											2010-07-07 14:55:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      echo ( " . " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 22:10:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      $update  =  array ( 'sensor_oid'  =>  $oid ,  'sensor_descr'  =>  $descr ,  'sensor_multiplier'  =>  $multiplier ,  'sensor_divisor'  =>  $divisor , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                      'entPhysicalIndex'  =>  $entPhysicalIndex ,  'entPhysicalIndex_measured'  =>  $entPhysicalIndex_measured ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 22:21:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      $updated  =  dbUpdate ( $update ,  'sensors' ,  '`sensor_id` = ?' ,  array ( $sensor_entry [ 'sensor_id' ])); 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 19:21:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								       echo ( " U " ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-04-03 19:36:32 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      log_event ( " Sensor Updated:  " . mres ( $class ) . "   " . mres ( $type ) . "   " .  mres ( $index ) . "   " . mres ( $descr ),  $device ,  'sensor' ,  $sensor_id ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 19:21:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      if  ( $debug )  {  echo ( " (  $updated  updated ) \n " );  } 
							 
						 
					
						
							
								
									
										
										
										
											2010-07-07 14:55:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-04 13:22:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  $valid [ $class ][ $type ][ $index ]  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-07-07 14:55:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2010-02-28 22:04:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  sensor_low_limit ( $class ,  $current ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-12-15 17:54:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 12:46:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  $limit  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  switch ( $class ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-12-15 17:54:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  { 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 12:46:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    case  'temperature' : 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      $limit  =  $current  *  0.7 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      break ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 12:46:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    case  'voltage' : 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-09 12:57:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      if  ( $current  <  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $limit  =  $current  *  ( 1  +  ( sgn ( $current )  *  0.15 )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $limit  =  $current  *  ( 1  -  ( sgn ( $current )  *  0.15 )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      } 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      break ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 12:46:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    case  'humidity' : 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      $limit  =  " 70 " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      break ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-04-21 10:41:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    case  'frequency' : 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      $limit  =  $current  *  0.95 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      break ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 12:46:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    case  'current' : 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-17 13:57:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      $limit  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      break ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 12:46:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    case  'fanspeed' : 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      $limit  =  $current  *  0.80 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      break ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-04-20 09:59:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    case  'power' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      $limit  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      break ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 12:46:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  return  $limit ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  sensor_limit ( $class ,  $current ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-12-15 17:54:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 12:46:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  $limit  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-12-15 17:54:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  switch ( $class ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  { 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 12:46:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    case  'temperature' : 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      $limit  =  $current  *  1.60 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      break ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 12:46:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    case  'voltage' : 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-09 12:57:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      if  ( $current  <  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $limit  =  $current  *  ( 1  -  ( sgn ( $current )  *  0.15 )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $limit  =  $current  *  ( 1  +  ( sgn ( $current )  *  0.15 )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      } 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      break ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 12:46:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    case  'humidity' : 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      $limit  =  " 70 " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      break ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-04-21 10:41:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    case  'frequency' : 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      $limit  =  $current  *  1.05 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      break ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 12:46:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    case  'current' : 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      $limit  =  $current  *  1.50 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      break ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 12:46:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    case  'fanspeed' : 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-02 23:01:57 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      $limit  =  $current  *  1.80 ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      break ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-04-20 09:59:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    case  'power' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      $limit  =  $current  *  1.50 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      break ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-11 12:46:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  return  $limit ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-20 18:23:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  check_valid_sensors ( $device ,  $class ,  $valid ,  $poller_type  =  'snmp' ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-12-15 17:54:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-20 18:23:40 +00: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 )); 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 19:21:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  if  ( count ( $entries )) 
							 
						 
					
						
							
								
									
										
										
										
											2010-07-29 18:25:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  { 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 19:21:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    foreach  ( $entries  as  $entry ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-07-29 18:25:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 19:21:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      $index  =  $entry [ 'sensor_index' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      $type  =  $entry [ 'sensor_type' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      if  ( $debug )  {  echo ( $index  .  "  ->  "  .  $type  .  " \n " );  } 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-04 13:22:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      if  ( ! $valid [ $class ][ $type ][ $index ]) 
							 
						 
					
						
							
								
									
										
										
										
											2010-07-29 18:25:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        echo ( " - " ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 19:21:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        dbDelete ( 'sensors' ,  " `sensor_id` =  ? " ,  array ( $entry [ 'sensor_id' ])); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        log_event ( " Sensor Deleted:  " . $entry [ 'sensor_class' ] . "   " . $entry [ 'sensor_type' ] . "   " .  $entry [ 'sensor_index' ] . "   " . $entry [ 'sensor_descr' ],  $device ,  'sensor' ,  $sensor_id ); 
							 
						 
					
						
							
								
									
										
										
										
											2010-07-29 18:25:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      unset ( $oid );  unset ( $type ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-16 13:25:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  discover_juniAtmVp ( & $valid ,  $port_id ,  $vp_id ,  $vp_descr ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  global  $config ,  $debug ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-02-28 22:04:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-16 13:25:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  if  ( dbFetchCell ( " SELECT COUNT(*) FROM `juniAtmVp` WHERE `port_id` = ? AND `vp_id` = ? " ,  array ( $port_id ,  $vp_id ))  ==  " 0 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-16 13:25:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     $inserted  =  dbInsert ( array ( 'port_id'  =>  $port_id , 'vp_id'  =>  $vp_id , 'vp_descr'  =>  $vp_descr ),  'juniAtmVp' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 19:21:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     if  ( $debug )  {  echo ( " (  $inserted  inserted ) \n " );  } 
							 
						 
					
						
							
								
									
										
										
										
											2011-04-03 19:36:32 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     #FIXME vv no $device!
 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-16 13:25:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     log_event ( " Juniper ATM VP Added: port  " . mres ( $port_id ) . "  vp  " . mres ( $vp_id ) . "  descr " .  mres ( $vp_descr ),  'juniAtmVp' ,  mysql_insert_id ()); 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  else 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    echo ( " . " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-16 13:25:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  $valid [ $port_id ][ $vp_id ]  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-02-28 22:04:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-16 13:25:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  discover_link ( $local_port_id ,  $protocol ,  $remote_port_id ,  $remote_hostname ,  $remote_port ,  $remote_platform ,  $remote_version ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  global  $config ,  $debug ,  $link_exists ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-02-15 23:56:30 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-16 13:25:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  if  ( dbFetchCell ( " SELECT COUNT(*) FROM `links` WHERE `remote_hostname` = ? AND `local_port_id` = ? AND `protocol` = ? AND `remote_port` = ? " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                  array ( $remote_hostname ,  $local_port_id ,  $protocol ,  $remote_port ))  ==  " 0 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  { 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 19:21:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-16 13:25:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $inserted  =  dbInsert ( array ( 'local_port_id'  =>  $local_port_id , 'protocol'  =>  $protocol , 'remote_port_id'  =>  $remote_port_id , 'remote_hostname'  =>  $remote_hostname , 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 19:21:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								             'remote_port'  =>  $remote_port , 'remote_platform'  =>  $remote_platform , 'remote_version'  =>  $remote_version ),  'links' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    echo ( " + " );  if  ( $debug )  {  echo ( " (  $inserted  inserted ) " );  } 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-16 13:25:50 +00: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 ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      echo ( " . " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-16 13:25:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      $updated  =  dbUpdate ( array ( 'remote_port_id'  =>  $remote_port_id ,  'remote_platform'  =>  $remote_platform ,  'remote_version'  =>  $remote_version ),  'links' ,  '`id` = ?' ,  array ( $data [ 'id' ])); 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 19:21:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      echo ( " U " );  if  ( $debug )  {  echo ( " (  $updated  updated ) " );  } 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-16 13:25:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  $link_exists [ $local_port_id ][ $remote_hostname ][ $remote_port ]  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-02-15 23:56:30 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-05-04 13:22:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  discover_storage ( & $valid ,  $device ,  $index ,  $type ,  $mib ,  $descr ,  $size ,  $units ,  $used  =  NULL ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  global  $config ,  $debug ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  if  ( $debug )  {  echo ( " $device ,  $index ,  $type ,  $mib ,  $descr ,  $units ,  $used ,  $size\n " );  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  if  ( $descr  &&  $size  >  " 0 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  { 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 19:21:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $storage  =  dbFetchRow ( " SELECT * FROM `storage` WHERE `storage_index` = ? AND `device_id` = ? AND `storage_mib` = ? " ,  array ( $index ,  $device [ 'device_id' ],  $mib )); 
							 
						 
					
						
							
								
									
										
										
										
											2011-06-17 13:38:27 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $storage  ===  FALSE  ||  ! count ( $storage )) 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-20 09:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      $insert  =  dbInsert ( array ( 'device_id'  =>  $device [ 'device_id' ],  'storage_descr'  =>  $descr ,  'storage_index'  =>  $index ,  'storage_mib'  =>  $mib ,  'storage_type'  =>  $type , 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 19:21:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                               'storage_units'  =>  $units ,  'storage_size'  =>  $size ,  'storage_used'  =>  $used ),  'storage' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      if  ( $debug )  {  mysql_error ();  } 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      echo ( " + " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-17 19:21:20 +00: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 )); 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-20 14:22:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      if  ( $updated )  {  echo ( " U " );  }  else  {  echo ( " . " );  } 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-04 13:22:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $valid [ $mib ][ $index ]  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
									
										
										
										
											2010-02-24 13:46:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-05-04 13:22:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  discover_processor ( & $valid ,  $device ,  $oid ,  $index ,  $type ,  $descr ,  $precision  =  " 1 " ,  $current  =  NULL ,  $entPhysicalIndex  =  NULL ,  $hrDeviceIndex  =  NULL ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  global  $config ,  $debug ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  if  ( $debug )  {  echo ( " $device ,  $oid ,  $index ,  $type ,  $descr ,  $precision ,  $current ,  $entPhysicalIndex ,  $hrDeviceIndex\n " );  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  if  ( $descr ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-21 00:42:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $descr  =  trim ( str_replace ( " \" " ,  " " ,  $descr )); 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( mysql_result ( mysql_query ( " SELECT count(processor_id) FROM `processors` WHERE `processor_index` = ' $index ' AND `device_id` = ' " . $device [ 'device_id' ] . " ' AND `processor_type` = ' $type ' " ), 0 )  ==  '0' ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      $query  =  " INSERT INTO processors (`entPhysicalIndex`, `hrDeviceIndex`, `device_id`, `processor_descr`, `processor_index`, `processor_oid`, `processor_usage`, `processor_type`, `processor_precision`)
 
							 
						 
					
						
							
								
									
										
										
										
											2010-02-21 02:44:00 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                      values  ( '$entPhysicalIndex' ,  '$hrDeviceIndex' ,  '".$device[' device_id ']."' ,  '$descr' ,  '$index' ,  '$oid' ,  '$current' ,  '$type' , '$precision' ) " ;
 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      mysql_query ( $query ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      if  ( $debug )  {  print  $query  .  " \n " ;  } 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      echo ( " + " ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-04-03 19:36:32 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      log_event ( " Processor added: type  " . mres ( $type ) . "  index  " . mres ( $index ) . "  descr  " .  mres ( $descr ),  $device ,  'processor' ,  mysql_insert_id ()); 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      echo ( " . " ); 
							 
						 
					
						
							
								
									
										
										
										
											2010-07-09 14:04:05 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      $query  =  " UPDATE `processors` SET `processor_descr` = ' " . $descr . " ', `processor_oid` = ' " . $oid . " ', `processor_precision` = ' " . $precision . " '
 
							 
						 
					
						
							
								
									
										
										
										
											2010-02-21 01:35:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                      WHERE  `device_id`  =  '".$device[' device_id ']."'  AND  `processor_index`  =  '".$index."'  AND  `processor_type`  =  '".$type."' " ;
 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      mysql_query ( $query ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      if  ( $debug )  {  print  $query  .  " \n " ;  } 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-04 13:22:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $valid [ $type ][ $index ]  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2010-02-22 00:57:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-05-04 13:22:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  discover_mempool ( & $valid ,  $device ,  $index ,  $type ,  $descr ,  $precision  =  " 1 " ,  $entPhysicalIndex  =  NULL ,  $hrDeviceIndex  =  NULL ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  global  $config ,  $debug ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  if  ( $debug )  {  echo ( " $device ,  $oid ,  $index ,  $type ,  $descr ,  $precision ,  $current ,  $entPhysicalIndex ,  $hrDeviceIndex\n " );  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  if  ( $descr ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  { 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( mysql_result ( mysql_query ( " SELECT count(mempool_id) FROM `mempools` WHERE `mempool_index` = ' $index ' AND `device_id` = ' " . $device [ 'device_id' ] . " ' AND `mempool_type` = ' $type ' " ), 0 )  ==  '0' ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      $query  =  " INSERT INTO mempools (`entPhysicalIndex`, `hrDeviceIndex`, `device_id`, `mempool_descr`, `mempool_index`, `mempool_type`, `mempool_precision`)
 
							 
						 
					
						
							
								
									
										
										
										
											2010-02-22 00:57:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                      values  ( '$entPhysicalIndex' ,  '$hrDeviceIndex' ,  '".$device[' device_id ']."' ,  '$descr' ,  '$index' ,  '$type' , '$precision' ) " ;
 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 02:53:17 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      mysql_query ( $query ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      if  ( $debug )  {  print  $query  .  " \n " ;  } 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      echo ( " + " ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-04-03 19:36:32 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      log_event ( " Memory pool added: type  " . mres ( $type ) . "  index  " . mres ( $index ) . "  descr  " .  mres ( $descr ),  $device ,  'mempool' ,  mysql_insert_id ()); 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      echo ( " . " ); 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-26 18:34:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      $query   =  " UPDATE `mempools` SET `mempool_descr` = ' " . $descr . " ', `entPhysicalIndex` = ' " . $entPhysicalIndex . " ' " ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-26 18:30:27 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      $query  .=  " , `hrDeviceIndex` = ' $hrDeviceIndex '  " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      $query  .=  " WHERE `device_id` = ' " . $device [ 'device_id' ] . " ' AND `mempool_index` = ' " . $index . " ' AND `mempool_type` = ' " . $type . " ' " ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      mysql_query ( $query ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      if  ( $debug )  {  print  $query  .  " \n " ;  } 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-04 13:22:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $valid [ $type ][ $index ]  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
									
										
										
										
											2010-02-22 00:57:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-06 20:07:03 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  discover_toner ( & $valid ,  $device ,  $oid ,  $index ,  $type ,  $descr ,  $capacity_oid  =  NULL ,  $capacity  =  NULL ,  $current  =  NULL ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  global  $config ,  $debug ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-06 20:07:03 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  if  ( $debug )  {  echo ( " $oid ,  $index ,  $type ,  $descr ,  $capacity ,  $capacity_oid\n " );  } 
							 
						 
					
						
							
								
									
										
										
										
											2010-02-15 05:07:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-06 20:07:03 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  if  ( mysql_result ( mysql_query ( " SELECT count(toner_id) FROM `toner` WHERE device_id = ' " . $device [ 'device_id' ] . " ' AND toner_type = ' $type ' AND `toner_index` = ' $index ' AND `toner_capacity_oid` = ' $capacity_oid ' " ), 0 )  ==  '0' ) 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-06 19:56:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $query  =  " INSERT INTO toner (`device_id`, `toner_oid`, `toner_capacity_oid`, `toner_index`, `toner_type`, `toner_descr`, `toner_capacity`, `toner_current`)  " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $query  .=  "  VALUES (' " . $device [ 'device_id' ] . " ', ' $oid ', ' $capacity_oid ', ' $index ', ' $type ', ' $descr ', ' $capacity ', ' $current ') " ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    mysql_query ( $query ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    echo ( " + " ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-04-03 19:36:32 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    log_event ( " Toner added: type  " . mres ( $type ) . "  index  " . mres ( $index ) . "  descr  " .  mres ( $descr ),  $device ,  'toner' ,  mysql_insert_id ()); 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  else 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  { 
							 
						 
					
						
							
								
									
										
										
										
											2010-12-15 17:54:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $toner_entry  =  mysql_fetch_assoc ( mysql_query ( " SELECT * FROM `toner` WHERE device_id = ' " . $device [ 'device_id' ] . " ' AND toner_type = ' $type ' AND `toner_index` = ' $index ' " )); 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-06 20:07:03 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $oid  ==  $toner_entry [ 'toner_oid' ]  &&  $descr  ==  $toner_entry [ 'toner_descr' ]  &&  $capacity  ==  $toner_entry [ 'toner_capacity' ]  &&  $capacity_oid  ==  $toner_entry [ 'toner_capacity_oid' ]) 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      echo ( " . " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-15 11:24:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    else 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-06 19:56:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      mysql_query ( " UPDATE toner SET `toner_descr` = ' $descr ', `toner_oid` = ' $oid ', `toner_capacity_oid` = ' $capacity_oid ', `toner_capacity` = ' $capacity ' WHERE `device_id` = ' " . $device [ 'device_id' ] . " ' AND toner_type = ' $type ' AND `toner_index` = ' $index '  " ); 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      echo ( " U " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-04 13:22:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  $valid [ $type ][ $index ]  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-03-11 19:09:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2010-02-15 01:26:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-05-04 13:22:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  discover_process_ipv6 ( & $valid ,  $ifIndex , $ipv6_address , $ipv6_prefixlen , $ipv6_origin ) 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-04 10:45:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  global  $device , $config ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  $ipv6_network  =  Net_IPv6 :: getNetmask ( " $ipv6_address / $ipv6_prefixlen " )  .  '/'  .  $ipv6_prefixlen ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  $ipv6_compressed  =  Net_IPv6 :: compress ( $ipv6_address ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  if  ( Net_IPv6 :: getAddressType ( $ipv6_address )  ==  NET_IPV6_LOCAL_LINK ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    # ignore link-locals (coming from IPV6-MIB)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  if  ( mysql_result ( mysql_query ( " SELECT count(*) FROM `ports`
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        WHERE  device_id  =  '".$device[' device_id ']."'  AND  `ifIndex`  =  '$ifIndex' " ), 0) != '0' &&  $ipv6_prefixlen  > '0' &&  $ipv6_prefixlen  < '129' &&  $ipv6_compressed  != '::1')
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-16 13:25:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $i_query  =  " SELECT port_id FROM `ports` WHERE device_id = ' " . $device [ 'device_id' ] . " ' AND `ifIndex` = ' $ifIndex ' " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $port_id  =  mysql_result ( mysql_query ( $i_query ),  0 ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-04 10:45:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( mysql_result ( mysql_query ( " SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ' $ipv6_network ' " ),  0 )  <  '1' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      mysql_query ( " INSERT INTO `ipv6_networks` (`ipv6_network`) VALUES (' $ipv6_network ') " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      echo ( " N " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( mysql_result ( mysql_query ( " SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ' $ipv6_network ' " ),  0 )  <  '1' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      mysql_query ( " INSERT INTO `ipv6_networks` (`ipv6_network`) VALUES (' $ipv6_network ') " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      echo ( " N " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $ipv6_network_id  =  @ mysql_result ( mysql_query ( " SELECT `ipv6_network_id` from `ipv6_networks` WHERE `ipv6_network` = ' $ipv6_network ' " ),  0 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-16 13:25:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( mysql_result ( mysql_query ( " SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = ' $ipv6_address ' AND `ipv6_prefixlen` = ' $ipv6_prefixlen ' AND `port_id` = ' $port_id ' " ),  0 )  ==  '0' ) 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-04 10:45:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-16 13:25:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     mysql_query ( " INSERT INTO `ipv6_addresses` (`ipv6_address`, `ipv6_compressed`, `ipv6_prefixlen`, `ipv6_origin`, `ipv6_network_id`, `port_id`)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                                   VALUES  ( '$ipv6_address' ,  '$ipv6_compressed' ,  '$ipv6_prefixlen' ,  '$ipv6_origin' ,  '$ipv6_network_id' ,  '$port_id' ) " );
 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-04 10:45:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     echo ( " + " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      echo ( " . " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $full_address  =  " $ipv6_address / $ipv6_prefixlen " ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-16 13:25:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $valid_address  =  $full_address   .  " - "  .  $port_id ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-04 13:22:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $valid [ 'ipv6' ][ $valid_address ]  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-04 10:45:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-04-20 09:59:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								?>