2009-10-28 13:49:37 +00:00
< ? php
$cip_oids = array ( 'cipMacHCSwitchedBytes' , 'cipMacHCSwitchedPkts' );
echo ( " Caching OID: " );
2010-05-02 20:32:34 +00:00
$cip_array = array ();
2011-03-16 17:57:40 +00:00
foreach ( $cip_oids as $oid )
{
echo ( " $oid " );
$cip_array = snmpwalk_cache_cip ( $device , $oid , $cip_array , " CISCO-IP-STAT-MIB " );
2010-05-02 20:32:34 +00:00
}
2009-10-28 13:49:37 +00:00
$polled = time ();
$mac_entries = 0 ;
2010-05-02 20:32:34 +00:00
$mac_accounting_query = mysql_query ( " 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 = ' " . $device [ 'device_id' ] . " ' " );
2011-03-16 01:11:27 +00:00
while ( $acc = mysql_fetch_assoc ( $mac_accounting_query ))
{
2009-10-28 13:49:37 +00:00
$device_id = $acc [ 'device_id' ];
$ifIndex = $acc [ 'ifIndex' ];
$mac = $acc [ 'mac' ];
2010-05-02 20:32:34 +00:00
$polled_period = $polled - $acc [ 'poll_time' ];
2011-03-16 01:11:27 +00:00
if ( $cip_array [ $ifIndex ][ $mac ])
{
2009-10-28 13:49:37 +00:00
$update .= " `poll_time` = ' " . $polled . " ' " ;
$update .= " , `poll_prev` = ' " . $acc [ 'poll_time' ] . " ' " ;
$update .= " , `poll_period` = ' " . $polled_period . " ' " ;
$mac_entries ++ ;
2010-08-11 17:08:56 +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' ];
2009-10-28 13:49:37 +00:00
2011-03-16 17:57:40 +00:00
$this_ma = & $cip_array [ $ifIndex ][ $mac ];
2009-10-28 13:49:37 +00:00
/// Update metrics
2011-03-16 01:11:27 +00:00
foreach ( $cip_oids as $oid )
{
foreach ( array ( 'input' , 'output' ) as $dir )
{
2009-10-28 13:49:37 +00:00
$oid_dir = $oid . " _ " . $dir ;
$update .= " , ` " . $oid_dir . " ` = ' " . $this_ma [ $oid ][ $dir ] . " ' " ;
$update .= " , ` " . $oid_dir . " _prev` = ' " . $acc [ $oid_dir ] . " ' " ;
$oid_prev = $oid_dir . " _prev " ;
2011-03-16 01:11:27 +00:00
if ( $this_ma [ $oid ][ $dir ])
{
2009-10-28 13:49:37 +00:00
$oid_diff = $this_ma [ $oid ][ $dir ] - $acc [ $oid_dir ];
$oid_rate = $oid_diff / $polled_period ;
$update .= " , ` " . $oid_dir . " _rate` = ' " . $oid_rate . " ' " ;
$update .= " , ` " . $oid_dir . " _delta` = ' " . $oid_diff . " ' " ;
2011-03-16 01:11:27 +00:00
if ( $debug ) { echo ( " \n $oid_dir ( $oid_diff B) $oid_rate Bps $polled_period secs \n " ); }
2009-10-28 13:49:37 +00:00
}
}
}
2011-03-16 01:11:27 +00:00
if ( $debug ) { echo ( " \n " . $acc [ 'hostname' ] . " " . $acc [ 'ifDescr' ] . " $mac -> $b_in : $b_out : $p_in : $p_out " ); }
2010-02-05 22:10:06 +00:00
$rrdfile = $host_rrd . " / " . safename ( " cip- " . $acc [ 'ifIndex' ] . " - " . $acc [ 'mac' ] . " .rrd " );
2009-10-28 13:49:37 +00:00
2011-03-16 01:11:27 +00:00
if ( ! is_file ( $rrdfile ))
2011-03-10 15:51:56 +00:00
{
rrdtool_create ( $rrdfile , " DS:IN:COUNTER:600:0:12500000000 \
2009-10-28 13:49:37 +00:00
DS : OUT : COUNTER : 600 : 0 : 12500000000 \
DS : PIN : COUNTER : 600 : 0 : 12500000000 \
DS : POUT : COUNTER : 600 : 0 : 12500000000 \
RRA : AVERAGE : 0.5 : 1 : 600 \
RRA : AVERAGE : 0.5 : 6 : 700 \
RRA : AVERAGE : 0.5 : 24 : 775 \
RRA : AVERAGE : 0.5 : 288 : 797 \
RRA : MAX : 0.5 : 1 : 600 \
RRA : MAX : 0.5 : 6 : 700 \
RRA : MAX : 0.5 : 24 : 775 \
RRA : MAX : 0.5 : 288 : 797 " );
}
$woo = " N: " . ( $b_in + 0 ) . " : " . ( $b_out + 0 ) . " : " . ( $p_in + 0 ) . " : " . ( $p_out + 0 );
$ret = rrdtool_update ( " $rrdfile " , $woo );
2011-03-16 01:11:27 +00:00
if ( $update )
{ /// Do Updates
$update_query = " UPDATE `mac_accounting` SET " . $update . " WHERE `ma_id` = ' " . $acc [ 'ma_id' ] . " ' " ;
@ mysql_query ( $update_query );
if ( $debug ) { echo ( " \n MYSQL : [ $update_query ] " ); }
} /// End Updates
2009-10-28 13:49:37 +00:00
2011-03-16 01:11:27 +00:00
unset ( $update_query ); unset ( $update );
2009-10-28 13:49:37 +00:00
}
}
2010-05-02 20:32:34 +00:00
unset ( $cip_array );
2011-03-16 01:11:27 +00:00
if ( $mac_entries ) { echo ( " $mac_entries MAC accounting entries \n " ); }
2009-10-28 13:49:37 +00:00
2010-11-23 14:32:37 +00:00
echo ( " \n " );
2011-03-16 01:11:27 +00:00
?>