2009-10-28 13:49:37 +00:00
< ? php
2011-05-16 21:56:01 +00:00
## FIXME -- we're walking, so we can discover here too.
2012-04-09 10:53:55 +00:00
if ( $device [ 'os_group' ] == " cisco " )
2011-03-16 01:11:27 +00:00
{
2012-04-09 10:53:55 +00:00
$cip_oids = array ( 'cipMacHCSwitchedBytes' , 'cipMacHCSwitchedPkts' );
echo ( " Cisco MAC - Caching OID: " );
$cip_array = array ();
2012-04-09 15:30:45 +00:00
2012-04-09 10:53:55 +00:00
foreach ( $cip_oids as $oid )
2011-03-16 01:11:27 +00:00
{
2012-04-09 10:53:55 +00:00
echo ( " $oid " );
$cip_array = snmpwalk_cache_cip ( $device , $oid , $cip_array , " CISCO-IP-STAT-MIB " );
}
2012-04-09 15:30:45 +00:00
2012-04-09 10:53:55 +00:00
$polled = time ();
2012-04-09 15:30:45 +00:00
2012-04-09 10:53:55 +00:00
$mac_entries = 0 ;
2012-04-09 15:30:45 +00:00
2012-04-09 10:53:55 +00:00
$acc_rows = dbFetchRows ( " SELECT *, A.poll_time AS poll_time FROM `mac_accounting` as A, `ports` AS I where A.interface_id = I.interface_id AND I.device_id = ? " , array ( $device [ 'device_id' ]));
2012-04-09 15:30:45 +00:00
2012-04-09 10:53:55 +00:00
foreach ( $acc_rows as $acc )
{
$device_id = $acc [ 'device_id' ];
$ifIndex = $acc [ 'ifIndex' ];
$mac = $acc [ 'mac' ];
2012-04-09 15:30:45 +00:00
2012-04-09 10:53:55 +00:00
$polled_period = $polled - $acc [ 'poll_time' ];
2012-04-09 15:30:45 +00:00
2012-04-09 10:53:55 +00:00
if ( $cip_array [ $ifIndex ][ $mac ])
2011-03-16 01:11:27 +00:00
{
2012-04-09 10:53:55 +00:00
$acc [ 'update' ][ 'poll_time' ] = $polled ;
$acc [ 'update' ][ 'poll_prev' ] = $acc [ 'poll_time' ];
$acc [ 'update' ][ 'poll_period' ] = $polled_period ;
2012-04-09 15:30:45 +00:00
2012-04-09 10:53:55 +00:00
$mac_entries ++ ;
2012-04-09 15:30:45 +00:00
2012-04-09 10:53:55 +00:00
$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' ];
2012-04-09 15:30:45 +00:00
2012-04-09 10:53:55 +00:00
$this_ma = & $cip_array [ $ifIndex ][ $mac ];
2012-04-09 15:30:45 +00:00
2012-04-09 10:53:55 +00:00
/// Update metrics
foreach ( $cip_oids as $oid )
2011-03-16 01:11:27 +00:00
{
2012-04-09 10:53:55 +00:00
foreach ( array ( 'input' , 'output' ) as $dir )
2011-03-16 01:11:27 +00:00
{
2012-04-09 10:53:55 +00:00
$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 ;
if ( $debug ) { echo ( " \n $oid_dir ( $oid_diff B) $oid_rate Bps $polled_period secs \n " ); }
}
2009-10-28 13:49:37 +00:00
}
}
2012-04-09 15:30:45 +00:00
2012-04-09 10:53:55 +00:00
if ( $debug ) { echo ( " \n " . $acc [ 'hostname' ] . " " . $acc [ 'ifDescr' ] . " $mac -> $b_in : $b_out : $p_in : $p_out " ); }
2012-04-09 15:30:45 +00:00
2012-04-09 10:53:55 +00:00
$rrdfile = $config [ 'rrd_dir' ] . " / " . $device [ 'hostname' ] . " / " . safename ( " cip- " . $acc [ 'ifIndex' ] . " - " . $acc [ 'mac' ] . " .rrd " );
2012-04-09 15:30:45 +00:00
2012-04-09 10:53:55 +00:00
if ( ! is_file ( $rrdfile ))
{
rrdtool_create ( $rrdfile , " DS:IN:COUNTER:600:0:12500000000 \
DS : OUT : COUNTER : 600 : 0 : 12500000000 \
DS : PIN : COUNTER : 600 : 0 : 12500000000 \
2012-04-20 17:37:58 +00:00
DS : POUT : COUNTER : 600 : 0 : 12500000000 " . $config['rrd_rra'] );
2012-04-09 10:53:55 +00:00
}
$woo = " N: " . ( $b_in + 0 ) . " : " . ( $b_out + 0 ) . " : " . ( $p_in + 0 ) . " : " . ( $p_out + 0 );
$ret = rrdtool_update ( " $rrdfile " , $woo );
2012-04-09 15:30:45 +00:00
2012-04-09 10:53:55 +00:00
if ( $acc [ 'update' ])
{ /// Do Updates
dbUpdate ( $acc [ 'update' ], 'mac_accounting' , '`ma_id` = ?' , array ( $acc [ 'ma_id' ]));
} /// End Updates
2009-10-28 13:49:37 +00:00
}
}
2012-04-09 15:30:45 +00:00
2012-04-09 10:53:55 +00:00
unset ( $cip_array );
2012-04-09 15:30:45 +00:00
2012-04-09 10:53:55 +00:00
if ( $mac_entries ) { echo ( " $mac_entries MAC accounting entries \n " ); }
2012-04-09 15:30:45 +00:00
2012-04-09 10:53:55 +00:00
echo ( " \n " );
2009-10-28 13:49:37 +00:00
}
2012-04-09 15:30:45 +00:00
2011-05-16 21:56:01 +00:00
?>