2009-10-28 13:49:37 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< ? php  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-25 12:24:34 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// FIXME -- we're walking, so we can discover here too.
  
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								if  ( $device [ 'os_group' ]  ==  'cisco' )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $cip_oids  =  array ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        'cipMacHCSwitchedBytes' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        'cipMacHCSwitchedPkts' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $cip_array  =  array (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    foreach  ( $cip_oids  as  $oid )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        echo  " $oid   " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $cip_array  =  snmpwalk_cache_cip ( $device ,  $oid ,  $cip_array ,  'CISCO-IP-STAT-MIB' ); 
							 
						 
					
						
							
								
									
										
										
										
											2009-10-28 13:49:37 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-09 15:30:45 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    $polled  =  time (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $mac_entries  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $acc_rows  =  dbFetchRows ( 'SELECT *, A.poll_time AS poll_time FROM `mac_accounting` as A, `ports` AS I where A.port_id = I.port_id AND I.device_id = ?' ,  array ( $device [ 'device_id' ])); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    foreach  ( $acc_rows  as  $acc )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $device_id  =  $acc [ 'device_id' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $ifIndex    =  $acc [ 'ifIndex' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $mac        =  $acc [ 'mac' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $polled_period  =  ( $polled  -  $acc [ 'poll_time' ]); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( $cip_array [ $ifIndex ][ $mac ])  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $acc [ 'update' ][ 'poll_time' ]    =  $polled ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $acc [ 'update' ][ 'poll_prev' ]    =  $acc [ 'poll_time' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $acc [ 'update' ][ 'poll_period' ]  =  $polled_period ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $mac_entries ++ ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $b_in   =  $cip_array [ $ifIndex ][ $mac ][ 'cipMacHCSwitchedBytes' ][ 'input' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $b_out  =  $cip_array [ $ifIndex ][ $mac ][ 'cipMacHCSwitchedBytes' ][ 'output' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $p_in   =  $cip_array [ $ifIndex ][ $mac ][ 'cipMacHCSwitchedPkts' ][ 'input' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $p_out  =  $cip_array [ $ifIndex ][ $mac ][ 'cipMacHCSwitchedPkts' ][ 'output' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $this_ma  =  & $cip_array [ $ifIndex ][ $mac ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // Update metrics
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            foreach  ( $cip_oids  as  $oid )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                foreach  ( array ( 'input' ,  'output' )  as  $dir )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    $oid_dir                  =  $oid . '_' . $dir ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    $acc [ 'update' ][ $oid_dir ]  =  $this_ma [ $oid ][ $dir ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    $acc [ 'update' ][ $oid_dir . '_prev' ]  =  $acc [ $oid_dir ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    $oid_prev  =  $oid_dir . '_prev' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  ( $this_ma [ $oid ][ $dir ])  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        $oid_diff  =  ( $this_ma [ $oid ][ $dir ]  -  $acc [ $oid_dir ]); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        $oid_rate  =  ( $oid_diff  /  $polled_period ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        $acc [ 'update' ][ $oid_dir . '_rate' ]   =  $oid_rate ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        $acc [ 'update' ][ $oid_dir . '_delta' ]  =  $oid_diff ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-20 15:02:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                        d_echo ( " \n   $oid_dir  ( $oid_diff  B)  $oid_rate  Bps  $polled_period  secs \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-20 15:02:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            d_echo ( " \n " . $acc [ 'hostname' ] . ' ' . $acc [ 'ifDescr' ] . "    $mac  ->  $b_in : $b_out : $p_in : $p_out   " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-07-07 01:33:43 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            $rrd_name  =  array ( 'cip' ,  $ifIndex ,  $mac ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $rrd_dev  =  array ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                'DS:IN:COUNTER:600:0:12500000000' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                'DS:OUT:COUNTER:600:0:12500000000' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                'DS:PIN:COUNTER:600:0:12500000000' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                'DS:POUT:COUNTER:600:0:12500000000' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // FIXME - use memcached to make sure these values don't go backwards?
 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-18 16:26:55 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            $fields  =  array ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                'IN'    =>  $b_in , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                'OUT'   =>  $b_out , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                'PIN'   =>  $p_in , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                'POUT'  =>  $p_out , 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-07-07 01:33:43 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            $tags  =  compact ( 'ifIndex' ,  'mac' ,  'rrd_name' ,  'rrd_def' ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            data_update ( $device ,  'cip' ,  $tags ,  $fields ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-19 20:58:02 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( $acc [ 'update' ])  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                // Do Updates
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                dbUpdate ( $acc [ 'update' ],  'mac_accounting' ,  '`ma_id` = ?' ,  array ( $acc [ 'ma_id' ])); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            }  //end if
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } //end if
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } //end foreach
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    unset ( $cip_array ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( $mac_entries )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        echo  "   $mac_entries  MAC accounting entries \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-09 15:30:45 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    echo  " \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} //end if