2010-08-10 15:54:01 +00:00
< ? php
2009-10-28 13:49:37 +00:00
2012-05-25 12:24:34 +00:00
// Build SNMP Cache Array
2015-07-13 20:10:26 +02:00
$data_oids = array (
'ifName' ,
'ifDescr' ,
'ifAlias' ,
'ifAdminStatus' ,
'ifOperStatus' ,
'ifMtu' ,
'ifSpeed' ,
'ifHighSpeed' ,
'ifType' ,
'ifPhysAddress' ,
'ifPromiscuousMode' ,
'ifConnectorPresent' ,
'ifDuplex' ,
'ifTrunk' ,
'ifVlan' ,
);
$stat_oids = array (
'ifInErrors' ,
'ifOutErrors' ,
'ifInUcastPkts' ,
'ifOutUcastPkts' ,
'ifInNUcastPkts' ,
'ifOutNUcastPkts' ,
'ifHCInMulticastPkts' ,
'ifHCInBroadcastPkts' ,
'ifHCOutMulticastPkts' ,
'ifHCOutBroadcastPkts' ,
'ifInOctets' ,
'ifOutOctets' ,
'ifHCInOctets' ,
'ifHCOutOctets' ,
'ifInDiscards' ,
'ifOutDiscards' ,
'ifInUnknownProtos' ,
'ifInBroadcastPkts' ,
'ifOutBroadcastPkts' ,
'ifInMulticastPkts' ,
'ifOutMulticastPkts' ,
);
$stat_oids_db = array (
'ifInOctets' ,
'ifOutOctets' ,
'ifInErrors' ,
'ifOutErrors' ,
'ifInUcastPkts' ,
'ifOutUcastPkts' ,
);
2015-11-24 16:14:07 -07:00
$stat_oids_db_extended = array (
'ifInNUcastPkts' ,
'ifOutNUcastPkts' ,
'ifInDiscards' ,
'ifOutDiscards' ,
'ifInUnknownProtos' ,
'ifInBroadcastPkts' ,
'ifOutBroadcastPkts' ,
'ifInMulticastPkts' ,
'ifOutMulticastPkts' ,
);
2015-07-13 20:10:26 +02:00
// From above for DB
$etherlike_oids = array (
'dot3StatsAlignmentErrors' ,
'dot3StatsFCSErrors' ,
'dot3StatsSingleCollisionFrames' ,
'dot3StatsMultipleCollisionFrames' ,
'dot3StatsSQETestErrors' ,
'dot3StatsDeferredTransmissions' ,
'dot3StatsLateCollisions' ,
'dot3StatsExcessiveCollisions' ,
'dot3StatsInternalMacTransmitErrors' ,
'dot3StatsCarrierSenseErrors' ,
'dot3StatsFrameTooLongs' ,
'dot3StatsInternalMacReceiveErrors' ,
'dot3StatsSymbolErrors' ,
);
$cisco_oids = array (
'locIfHardType' ,
'locIfInRunts' ,
'locIfInGiants' ,
'locIfInCRC' ,
'locIfInFrame' ,
'locIfInOverrun' ,
'locIfInIgnored' ,
'locIfInAbort' ,
'locIfCollisions' ,
'locIfInputQueueDrops' ,
'locIfOutputQueueDrops' ,
);
$pagp_oids = array (
'pagpOperationMode' ,
'pagpPortState' ,
'pagpPartnerDeviceId' ,
'pagpPartnerLearnMethod' ,
'pagpPartnerIfIndex' ,
'pagpPartnerGroupIfIndex' ,
'pagpPartnerDeviceName' ,
'pagpEthcOperationMode' ,
'pagpDeviceId' ,
'pagpGroupIfIndex' ,
);
2011-03-16 01:11:27 +00:00
$ifmib_oids = array_merge ( $data_oids , $stat_oids );
2015-07-13 20:10:26 +02:00
$ifmib_oids = array (
'ifEntry' ,
'ifXEntry' ,
);
2011-03-16 01:11:27 +00:00
2015-07-13 20:10:26 +02:00
echo 'Caching Oids: ' ;
foreach ( $ifmib_oids as $oid ) {
echo " $oid " ;
$port_stats = snmpwalk_cache_oid ( $device , $oid , $port_stats , 'IF-MIB' );
2011-03-16 01:11:27 +00:00
}
2015-07-13 20:10:26 +02:00
if ( $config [ 'enable_ports_etherlike' ]) {
echo 'dot3Stats ' ;
$port_stats = snmpwalk_cache_oid ( $device , 'dot3StatsEntry' , $port_stats , 'EtherLike-MIB' );
}
else {
echo 'dot3StatsDuplexStatus' ;
$port_stats = snmpwalk_cache_oid ( $device , 'dot3StatsDuplexStatus' , $port_stats , 'EtherLike-MIB' );
2011-03-16 01:11:27 +00:00
}
2015-07-13 20:10:26 +02:00
if ( $config [ 'enable_ports_adsl' ]) {
$device [ 'adsl_count' ] = dbFetchCell ( " SELECT COUNT(*) FROM `ports` WHERE `device_id` = ? AND `ifType` = 'adsl' " , array ( $device [ 'device_id' ]));
2011-03-16 01:11:27 +00:00
}
2015-07-13 20:10:26 +02:00
if ( $device [ 'adsl_count' ] > '0' ) {
echo 'ADSL ' ;
$port_stats = snmpwalk_cache_oid ( $device , '.1.3.6.1.2.1.10.94.1.1.1.1' , $port_stats , 'ADSL-LINE-MIB' );
$port_stats = snmpwalk_cache_oid ( $device , '.1.3.6.1.2.1.10.94.1.1.2.1' , $port_stats , 'ADSL-LINE-MIB' );
$port_stats = snmpwalk_cache_oid ( $device , '.1.3.6.1.2.1.10.94.1.1.3.1' , $port_stats , 'ADSL-LINE-MIB' );
$port_stats = snmpwalk_cache_oid ( $device , '.1.3.6.1.2.1.10.94.1.1.4.1' , $port_stats , 'ADSL-LINE-MIB' );
$port_stats = snmpwalk_cache_oid ( $device , '.1.3.6.1.2.1.10.94.1.1.5.1' , $port_stats , 'ADSL-LINE-MIB' );
$port_stats = snmpwalk_cache_oid ( $device , '.1.3.6.1.2.1.10.94.1.1.6.1.1' , $port_stats , 'ADSL-LINE-MIB' );
$port_stats = snmpwalk_cache_oid ( $device , '.1.3.6.1.2.1.10.94.1.1.6.1.2' , $port_stats , 'ADSL-LINE-MIB' );
$port_stats = snmpwalk_cache_oid ( $device , '.1.3.6.1.2.1.10.94.1.1.6.1.3' , $port_stats , 'ADSL-LINE-MIB' );
$port_stats = snmpwalk_cache_oid ( $device , '.1.3.6.1.2.1.10.94.1.1.6.1.4' , $port_stats , 'ADSL-LINE-MIB' );
$port_stats = snmpwalk_cache_oid ( $device , '.1.3.6.1.2.1.10.94.1.1.6.1.5' , $port_stats , 'ADSL-LINE-MIB' );
$port_stats = snmpwalk_cache_oid ( $device , '.1.3.6.1.2.1.10.94.1.1.6.1.6' , $port_stats , 'ADSL-LINE-MIB' );
$port_stats = snmpwalk_cache_oid ( $device , '.1.3.6.1.2.1.10.94.1.1.6.1.7' , $port_stats , 'ADSL-LINE-MIB' );
$port_stats = snmpwalk_cache_oid ( $device , '.1.3.6.1.2.1.10.94.1.1.6.1.8' , $port_stats , 'ADSL-LINE-MIB' );
$port_stats = snmpwalk_cache_oid ( $device , '.1.3.6.1.2.1.10.94.1.1.7.1.1' , $port_stats , 'ADSL-LINE-MIB' );
$port_stats = snmpwalk_cache_oid ( $device , '.1.3.6.1.2.1.10.94.1.1.7.1.2' , $port_stats , 'ADSL-LINE-MIB' );
$port_stats = snmpwalk_cache_oid ( $device , '.1.3.6.1.2.1.10.94.1.1.7.1.3' , $port_stats , 'ADSL-LINE-MIB' );
$port_stats = snmpwalk_cache_oid ( $device , '.1.3.6.1.2.1.10.94.1.1.7.1.4' , $port_stats , 'ADSL-LINE-MIB' );
$port_stats = snmpwalk_cache_oid ( $device , '.1.3.6.1.2.1.10.94.1.1.7.1.5' , $port_stats , 'ADSL-LINE-MIB' );
$port_stats = snmpwalk_cache_oid ( $device , '.1.3.6.1.2.1.10.94.1.1.7.1.6' , $port_stats , 'ADSL-LINE-MIB' );
$port_stats = snmpwalk_cache_oid ( $device , '.1.3.6.1.2.1.10.94.1.1.7.1.7' , $port_stats , 'ADSL-LINE-MIB' );
} //end if
2015-08-23 17:04:20 +00:00
if ( $config [ 'enable_ports_poe' ]) {
$port_stats = snmpwalk_cache_oid ( $device , 'pethPsePortEntry' , $port_stats , 'POWER-ETHERNET-MIB' );
$port_stats = snmpwalk_cache_oid ( $device , 'cpeExtPsePortEntry' , $port_stats , 'CISCO-POWER-ETHERNET-EXT-MIB' );
}
2012-05-25 12:24:34 +00:00
// FIXME This probably needs re-enabled. We need to clear these things when they get unset, too.
2015-07-13 20:10:26 +02:00
// foreach ($etherlike_oids as $oid) { $port_stats = snmpwalk_cache_oid($device, $oid, $port_stats, "EtherLike-MIB"); }
// foreach ($cisco_oids as $oid) { $port_stats = snmpwalk_cache_oid($device, $oid, $port_stats, "OLD-CISCO-INTERFACES-MIB"); }
// foreach ($pagp_oids as $oid) { $port_stats = snmpwalk_cache_oid($device, $oid, $port_stats, "CISCO-PAGP-MIB"); }
if ( $device [ 'os_group' ] == 'cisco' ) {
$port_stats = snmp_cache_portIfIndex ( $device , $port_stats );
$port_stats = snmp_cache_portName ( $device , $port_stats );
foreach ( $pagp_oids as $oid ) {
$port_stats = snmpwalk_cache_oid ( $device , $oid , $port_stats , 'CISCO-PAGP-MIB' );
2011-12-15 15:00:45 +00:00
}
2015-07-13 20:10:26 +02:00
$data_oids [] = 'portName' ;
// Grab data to put ports into vlans or make them trunks
// FIXME we probably shouldn't be doing this from the VTP MIB, right?
$port_stats = snmpwalk_cache_oid ( $device , 'vmVlan' , $port_stats , 'CISCO-VLAN-MEMBERSHIP-MIB' );
$port_stats = snmpwalk_cache_oid ( $device , 'vlanTrunkPortEncapsulationOperType' , $port_stats , 'CISCO-VTP-MIB' );
$port_stats = snmpwalk_cache_oid ( $device , 'vlanTrunkPortNativeVlan' , $port_stats , 'CISCO-VTP-MIB' );
2011-12-15 15:00:45 +00:00
}
2015-07-13 20:10:26 +02:00
else {
$port_stats = snmpwalk_cache_oid ( $device , 'dot1qPortVlanTable' , $port_stats , 'Q-BRIDGE-MIB' );
$vlan_ports = snmpwalk_cache_twopart_oid ( $device , 'dot1qVlanCurrentEgressPorts' , $vlan_stats , 'Q-BRIDGE-MIB' );
$vlan_ifindex_map = snmpwalk_cache_oid ( $device , 'dot1dBasePortIfIndex' , $vlan_stats , 'Q-BRIDGE-MIB' );
foreach ( $vlan_ports as $instance ) {
foreach ( array_keys ( $instance ) as $vlan_id ) {
$parts = explode ( ' ' , $instance [ $vlan_id ][ 'dot1qVlanCurrentEgressPorts' ]);
$binary = '' ;
foreach ( $parts as $part ) {
$binary .= zeropad ( decbin ( $part ), 8 );
}
for ( $i = 0 ; $i < strlen ( $binary ); $i ++ ) {
if ( $binary [ $i ]) {
$ifindex = $i ;
// FIXME $vlan_ifindex_map[$i]
$q_bridge_mib [ $ifindex ][] = $vlan_id ;
}
}
}
}
} //end if
2011-09-27 10:07:39 +00:00
2011-03-16 01:11:27 +00:00
$polled = time ();
2012-05-25 12:24:34 +00:00
// End Building SNMP Cache Array
2015-08-20 15:02:40 +02:00
d_echo ( $port_stats );
2011-03-16 01:11:27 +00:00
2012-05-25 12:24:34 +00:00
// Build array of ports in the database
// FIXME -- this stuff is a little messy, looping the array to make an array just seems wrong. :>
2015-07-13 20:10:26 +02:00
// -- i can make it a function, so that you don't know what it's doing.
// -- $ports = adamasMagicFunction($ports_db); ?
2015-11-24 16:14:07 -07:00
if ( $config [ 'enable_extended_port_metrics' ]) {
// select * doesn't do what we want if multiple tables have the same column name -- last one wins :/
$ports_db = dbFetchRows ( 'SELECT *, `ports_statistics`.`port_id` AS `ports_statistics_port_id`, `ports`.`port_id` AS `port_id` FROM `ports` LEFT OUTER JOIN `ports_statistics` ON `ports`.`port_id` = `ports_statistics`.`port_id` WHERE `ports`.`device_id` = ?' , array ( $device [ 'device_id' ]));
}
else {
$ports_db = dbFetchRows ( 'SELECT * FROM `ports` WHERE `device_id` = ?' , array ( $device [ 'device_id' ]));
}
2015-07-13 20:10:26 +02:00
foreach ( $ports_db as $port ) {
$ports [ $port [ 'ifIndex' ]] = $port ;
}
2011-05-16 20:33:51 +00:00
2012-05-25 12:24:34 +00:00
// New interface detection
2015-07-13 20:10:26 +02:00
foreach ( $port_stats as $ifIndex => $port ) {
if ( is_port_valid ( $port , $device )) {
echo 'valid' ;
if ( ! is_array ( $ports [ $port [ 'ifIndex' ]])) {
$port_id = dbInsert ( array ( 'device_id' => $device [ 'device_id' ], 'ifIndex' => $ifIndex ), 'ports' );
2015-11-24 16:14:07 -07:00
if ( $config [ 'enable_extended_port_metrics' ]) {
2015-11-24 16:34:57 -07:00
dbInsert ( array ( 'port_id' => $port_id ), 'ports_statistics' );
2015-11-24 16:14:07 -07:00
}
2015-07-13 20:10:26 +02:00
$ports [ $port [ 'ifIndex' ]] = dbFetchRow ( 'SELECT * FROM `ports` WHERE `port_id` = ?' , array ( $port_id ));
echo 'Adding: ' . $port [ 'ifName' ] . '(' . $ifIndex . ')(' . $ports [ $port [ 'ifIndex' ]][ 'port_id' ] . ')' ;
// print_r($ports);
}
else if ( $ports [ $ifIndex ][ 'deleted' ] == '1' ) {
dbUpdate ( array ( 'deleted' => '0' ), 'ports' , '`port_id` = ?' , array ( $ports [ $ifIndex ][ 'port_id' ]));
$ports [ $ifIndex ][ 'deleted' ] = '0' ;
}
2015-11-24 16:14:07 -07:00
if ( $config [ 'enable_extended_port_metrics' ] &&
$ports [ $ifIndex ][ 'ports_statistics_port_id' ] === null ) {
// in case someone enabled the option after the port was already created
dbInsert ( array ( 'port_id' => $ports [ $ifIndex ][ 'port_id' ]), 'ports_statistics' );
}
2011-05-18 23:08:45 +00:00
}
2015-07-13 20:10:26 +02:00
else {
if ( $ports [ $port [ 'ifIndex' ]][ 'deleted' ] != '1' ) {
dbUpdate ( array ( 'deleted' => '1' ), 'ports' , '`port_id` = ?' , array ( $ports [ $ifIndex ][ 'port_id' ]));
$ports [ $ifIndex ][ 'deleted' ] = '1' ;
}
2012-04-09 12:40:43 +00:00
}
2011-05-16 20:33:51 +00:00
}
2011-03-16 01:11:27 +00:00
2015-07-13 20:10:26 +02:00
// End New interface detection
echo " \n " ;
2012-05-25 12:24:34 +00:00
// Loop ports in the DB and update where necessary
2015-07-13 20:10:26 +02:00
foreach ( $ports as $port ) {
echo 'Port ' . $port [ 'ifDescr' ] . '(' . $port [ 'ifIndex' ] . ') ' ;
if ( $port_stats [ $port [ 'ifIndex' ]] && $port [ 'disabled' ] != '1' ) {
// Check to make sure Port data is cached.
$this_port = & $port_stats [ $port [ 'ifIndex' ]];
if ( $device [ 'os' ] == 'vmware' && preg_match ( '/Device ([a-z0-9]+) at .*/' , $this_port [ 'ifDescr' ], $matches )) {
$this_port [ 'ifDescr' ] = $matches [ 1 ];
}
2012-04-04 18:10:45 +00:00
2015-07-13 20:10:26 +02:00
$polled_period = ( $polled - $port [ 'poll_time' ]);
2011-03-16 01:11:27 +00:00
2015-07-13 20:10:26 +02:00
$port [ 'update' ] = array ();
2015-11-24 16:14:07 -07:00
$port [ 'update_extended' ] = array ();
2015-07-13 20:10:26 +02:00
$port [ 'state' ] = array ();
2009-10-28 13:49:37 +00:00
2015-07-13 20:10:26 +02:00
if ( $config [ 'slow_statistics' ] == true ) {
$port [ 'update' ][ 'poll_time' ] = $polled ;
$port [ 'update' ][ 'poll_prev' ] = $port [ 'poll_time' ];
$port [ 'update' ][ 'poll_period' ] = $polled_period ;
}
2011-04-24 00:28:09 +00:00
2015-07-13 20:10:26 +02:00
// Copy ifHC[In|Out]Octets values to non-HC if they exist
if ( $this_port [ 'ifHCInOctets' ] > 0 && is_numeric ( $this_port [ 'ifHCInOctets' ]) && $this_port [ 'ifHCOutOctets' ] > 0 && is_numeric ( $this_port [ 'ifHCOutOctets' ])) {
echo 'HC ' ;
$this_port [ 'ifInOctets' ] = $this_port [ 'ifHCInOctets' ];
$this_port [ 'ifOutOctets' ] = $this_port [ 'ifHCOutOctets' ];
}
2010-07-20 13:02:54 +00:00
2015-12-02 23:23:31 +00:00
if ( $device [ 'os' ] === 'airos-af' && $port [ 'ifAlias' ] === 'eth0' ) {
$airos_stats = snmpwalk_cache_oid ( $device , '.1.3.6.1.4.1.41112.1.3.3.1' , $airos_stats , 'UBNT-AirFIBER-MIB' );
$this_port [ 'ifInOctets' ] = $airos_stats [ 1 ][ 'rxOctetsOK' ];
$this_port [ 'ifOutOctets' ] = $airos_stats [ 1 ][ 'txOctetsOK' ];
$this_port [ 'ifInErrors' ] = $airos_stats [ 1 ][ 'rxErroredFrames' ];
$this_port [ 'ifOutErrors' ] = $airos_stats [ 1 ][ 'txErroredFrames' ];
$this_port [ 'ifInBroadcastPkts' ] = $airos_stats [ 1 ][ 'rxValidBroadcastFrames' ];
$this_port [ 'ifOutBroadcastPkts' ] = $airos_stats [ 1 ][ 'txValidBroadcastFrames' ];
$this_port [ 'ifInMulticastPkts' ] = $airos_stats [ 1 ][ 'rxValidMulticastFrames' ];
$this_port [ 'ifOutMulticastPkts' ] = $airos_stats [ 1 ][ 'txValidMulticastFrames' ];
$this_port [ 'ifInUcastPkts' ] = $airos_stats [ 1 ][ 'rxValidUnicastFrames' ];
$this_port [ 'ifOutUcastPkts' ] = $airos_stats [ 1 ][ 'txValidUnicastFrames' ];
$ports [ 'update' ][ 'ifInOctets' ] = $airos_stats [ 1 ][ 'rxOctetsOK' ];
$ports [ 'update' ][ 'ifOutOctets' ] = $airos_stats [ 1 ][ 'txOctetsOK' ];
$ports [ 'update' ][ 'ifInErrors' ] = $airos_stats [ 1 ][ 'rxErroredFrames' ];
$ports [ 'update' ][ 'ifOutErrors' ] = $airos_stats [ 1 ][ 'txErroredFrames' ];
$ports [ 'update' ][ 'ifInBroadcastPkts' ] = $airos_stats [ 1 ][ 'rxValidBroadcastFrames' ];
$ports [ 'update' ][ 'ifOutBroadcastPkts' ] = $airos_stats [ 1 ][ 'txValidBroadcastFrames' ];
$ports [ 'update' ][ 'ifInMulticastPkts' ] = $airos_stats [ 1 ][ 'rxValidMulticastFrames' ];
$ports [ 'update' ][ 'ifOutMulticastPkts' ] = $airos_stats [ 1 ][ 'txValidMulticastFrames' ];
$ports [ 'update' ][ 'ifInUcastPkts' ] = $airos_stats [ 1 ][ 'rxValidUnicastFrames' ];
$ports [ 'update' ][ 'ifOutUcastPkts' ] = $airos_stats [ 1 ][ 'txValidUnicastFrames' ];
}
2015-07-13 20:10:26 +02:00
// rewrite the ifPhysAddress
if ( strpos ( $this_port [ 'ifPhysAddress' ], ':' )) {
list ( $a_a , $a_b , $a_c , $a_d , $a_e , $a_f ) = explode ( ':' , $this_port [ 'ifPhysAddress' ]);
$this_port [ 'ifPhysAddress' ] = zeropad ( $a_a ) . zeropad ( $a_b ) . zeropad ( $a_c ) . zeropad ( $a_d ) . zeropad ( $a_e ) . zeropad ( $a_f );
}
2009-10-28 13:49:37 +00:00
2015-07-13 20:10:26 +02:00
if ( is_numeric ( $this_port [ 'ifHCInBroadcastPkts' ]) && is_numeric ( $this_port [ 'ifHCOutBroadcastPkts' ]) && is_numeric ( $this_port [ 'ifHCInMulticastPkts' ]) && is_numeric ( $this_port [ 'ifHCOutMulticastPkts' ])) {
echo 'HC ' ;
$this_port [ 'ifInBroadcastPkts' ] = $this_port [ 'ifHCInBroadcastPkts' ];
$this_port [ 'ifOutBroadcastPkts' ] = $this_port [ 'ifHCOutBroadcastPkts' ];
$this_port [ 'ifInMulticastPkts' ] = $this_port [ 'ifHCInMulticastPkts' ];
$this_port [ 'ifOutMulticastPkts' ] = $this_port [ 'ifHCOutMulticastPkts' ];
}
2012-01-20 13:15:05 +00:00
2015-07-13 20:10:26 +02:00
// Overwrite ifSpeed with ifHighSpeed if it's over 1G
2015-08-23 21:39:37 +00:00
if ( is_numeric ( $this_port [ 'ifHighSpeed' ]) && ( $this_port [ 'ifSpeed' ] > '1000000000' || $this_port [ 'ifSpeed' ] == 0 )) {
2015-07-13 20:10:26 +02:00
echo 'HighSpeed ' ;
$this_port [ 'ifSpeed' ] = ( $this_port [ 'ifHighSpeed' ] * 1000000 );
}
2011-09-27 13:22:38 +00:00
2015-07-13 20:10:26 +02:00
// Overwrite ifDuplex with dot3StatsDuplexStatus if it exists
if ( isset ( $this_port [ 'dot3StatsDuplexStatus' ])) {
echo 'dot3Duplex ' ;
$this_port [ 'ifDuplex' ] = $this_port [ 'dot3StatsDuplexStatus' ];
}
2010-08-10 15:54:01 +00:00
2015-07-13 20:10:26 +02:00
// Set VLAN and Trunk from Cisco
if ( isset ( $this_port [ 'vlanTrunkPortEncapsulationOperType' ]) && $this_port [ 'vlanTrunkPortEncapsulationOperType' ] != 'notApplicable' ) {
$this_port [ 'ifTrunk' ] = $this_port [ 'vlanTrunkPortEncapsulationOperType' ];
if ( isset ( $this_port [ 'vlanTrunkPortNativeVlan' ])) {
$this_port [ 'ifVlan' ] = $this_port [ 'vlanTrunkPortNativeVlan' ];
}
2009-10-28 13:49:37 +00:00
}
2015-07-13 20:10:26 +02:00
if ( isset ( $this_port [ 'vmVlan' ])) {
$this_port [ 'ifVlan' ] = $this_port [ 'vmVlan' ];
2012-04-04 18:10:45 +00:00
}
2015-07-13 20:10:26 +02:00
// Set VLAN and Trunk from Q-BRIDGE-MIB
if ( ! isset ( $this_port [ 'ifVlan' ]) && isset ( $this_port [ 'dot1qPvid' ])) {
$this_port [ 'ifVlan' ] = $this_port [ 'dot1qPvid' ];
}
2012-04-04 18:10:45 +00:00
2015-07-13 20:10:26 +02:00
// FIXME use $q_bridge_mib[$this_port['ifIndex']] to see if it is a trunk (>1 array count)
echo 'VLAN == ' . $this_port [ 'ifVlan' ];
2015-08-07 16:41:33 +02:00
// When devices do not provide ifAlias data, populate with ifDescr data if configured
2015-08-07 17:11:12 +02:00
if (( $this_port [ 'ifAlias' ] == '' || $this_port [ 'ifAlias' ] == NULL ) || $config [ 'os' ][ $device [ 'os' ]][ 'descr_to_alias' ] == 1 ) {
2015-08-07 16:41:33 +02:00
$this_port [ 'ifAlias' ] = $this_port [ 'ifDescr' ];
2015-08-07 17:07:26 +02:00
d_echo ( 'Using ifDescr as ifAlias' );
2015-08-07 16:41:33 +02:00
}
2015-07-13 20:10:26 +02:00
// Update IF-MIB data
foreach ( $data_oids as $oid ) {
2015-08-30 14:34:37 -07:00
if ( $oid == 'ifAlias' ) {
2015-10-10 13:34:51 +00:00
if ( get_dev_attrib ( $device , 'ifName:' . $port [ 'ifName' ], 1 )) {
2015-08-30 14:34:37 -07:00
$this_port [ 'ifAlias' ] = $port [ 'ifAlias' ];
}
}
2015-07-13 20:10:26 +02:00
if ( $port [ $oid ] != $this_port [ $oid ] && ! isset ( $this_port [ $oid ])) {
$port [ 'update' ][ $oid ] = array ( 'NULL' );
log_event ( $oid . ': ' . $port [ $oid ] . ' -> NULL' , $device , 'interface' , $port [ 'port_id' ]);
if ( $debug ) {
2015-08-20 15:02:40 +02:00
d_echo ( $oid . ': ' . $port [ $oid ] . ' -> NULL ' );
2015-07-13 20:10:26 +02:00
}
else {
echo $oid . ' ' ;
}
}
else if ( $port [ $oid ] != $this_port [ $oid ]) {
$port [ 'update' ][ $oid ] = $this_port [ $oid ];
log_event ( $oid . ': ' . $port [ $oid ] . ' -> ' . $this_port [ $oid ], $device , 'interface' , $port [ 'port_id' ]);
if ( $debug ) {
2015-08-20 15:02:40 +02:00
d_echo ( $oid . ': ' . $port [ $oid ] . ' -> ' . $this_port [ $oid ] . ' ' );
2015-07-13 20:10:26 +02:00
}
else {
echo $oid . ' ' ;
}
}
} //end foreach
// Parse description (usually ifAlias) if config option set
if ( isset ( $config [ 'port_descr_parser' ]) && is_file ( $config [ 'install_dir' ] . '/' . $config [ 'port_descr_parser' ])) {
$port_attribs = array (
'type' ,
'descr' ,
'circuit' ,
'speed' ,
'notes' ,
);
include $config [ 'install_dir' ] . '/' . $config [ 'port_descr_parser' ];
foreach ( $port_attribs as $attrib ) {
$attrib_key = 'port_descr_' . $attrib ;
if ( $port_ifAlias [ $attrib ] != $port [ $attrib_key ]) {
if ( ! isset ( $port_ifAlias [ $attrib ])) {
$port_ifAlias [ $attrib ] = array ( 'NULL' );
$log_port = 'NULL' ;
}
else {
$log_port = $port_ifAlias [ $attrib ];
}
$port [ 'update' ][ $attrib_key ] = $port_ifAlias [ $attrib ];
log_event ( $attrib . ': ' . $port [ $attrib_key ] . ' -> ' . $log_port , $device , 'interface' , $port [ 'port_id' ]);
unset ( $log_port );
}
}
} //end if
// End parse ifAlias
// Update IF-MIB metrics
2015-11-24 16:14:07 -07:00
$_stat_oids = $stat_oids_db ;
if ( $config [ 'enable_extended_port_metrics' ]) {
$_stat_oids = $_stat_oids + $stat_oids_db_extended ;
}
foreach ( $_stat_oids as $oid ) {
$port_update = 'update' ;
if ( $config [ 'enable_extended_port_metrics' ]) {
$extended_metric = ! in_array ( $oid , $stat_oids_db , true );
if ( $extended_metric ) {
$port_update = 'update_extended' ;
}
}
2015-07-13 20:10:26 +02:00
if ( $config [ 'slow_statistics' ] == true ) {
2015-11-24 16:14:07 -07:00
$port [ $port_update ][ $oid ] = $this_port [ $oid ];
$port [ $port_update ][ $oid . '_prev' ] = $port [ $oid ];
2015-07-13 20:10:26 +02:00
}
$oid_prev = $oid . '_prev' ;
if ( isset ( $port [ $oid ])) {
$oid_diff = ( $this_port [ $oid ] - $port [ $oid ]);
$oid_rate = ( $oid_diff / $polled_period );
if ( $oid_rate < 0 ) {
$oid_rate = '0' ;
echo " negative $oid " ;
}
$port [ 'stats' ][ $oid . '_rate' ] = $oid_rate ;
$port [ 'stats' ][ $oid . '_diff' ] = $oid_diff ;
if ( $config [ 'slow_statistics' ] == true ) {
2015-11-24 16:14:07 -07:00
$port [ $port_update ][ $oid . '_rate' ] = $oid_rate ;
$port [ $port_update ][ $oid . '_delta' ] = $oid_diff ;
2015-07-13 20:10:26 +02:00
}
2015-08-20 15:02:40 +02:00
d_echo ( " \n $oid ( $oid_diff B) $oid_rate Bps $polled_period secs \n " );
2015-07-13 20:10:26 +02:00
} //end if
} //end foreach
if ( $config [ 'debug_port' ][ $port [ 'port_id' ]]) {
$port_debug = $port [ 'port_id' ] . '|' . $polled . '|' . $polled_period . '|' . $this_port [ 'ifHCInOctets' ] . '|' . $this_port [ 'ifHCOutOctets' ];
$port_debug .= '|' . $port [ 'stats' ][ 'ifInOctets_rate' ] . '|' . $port [ 'stats' ][ 'ifOutOctets_rate' ] . " \n " ;
file_put_contents ( '/tmp/port_debug.txt' , $port_debug , FILE_APPEND );
echo 'Wrote port debugging data' ;
}
2009-10-28 13:49:37 +00:00
2015-07-13 20:10:26 +02:00
$port [ 'stats' ][ 'ifInBits_rate' ] = round (( $port [ 'stats' ][ 'ifInOctets_rate' ] * 8 ));
$port [ 'stats' ][ 'ifOutBits_rate' ] = round (( $port [ 'stats' ][ 'ifOutOctets_rate' ] * 8 ));
2012-05-22 19:40:33 +00:00
2015-07-13 20:10:26 +02:00
// If we have a valid ifSpeed we should populate the stats for checking.
if ( is_numeric ( $this_port [ 'ifSpeed' ])) {
$port [ 'stats' ][ 'ifInBits_perc' ] = round (( $port [ 'stats' ][ 'ifInBits_rate' ] / $this_port [ 'ifSpeed' ] * 100 ));
$port [ 'stats' ][ 'ifOutBits_perc' ] = round (( $port [ 'stats' ][ 'ifOutBits_rate' ] / $this_port [ 'ifSpeed' ] * 100 ));
}
2012-05-16 13:25:50 +00:00
2015-07-13 20:10:26 +02:00
echo 'bps(' . formatRates ( $port [ 'stats' ][ 'ifInBits_rate' ]) . '/' . formatRates ( $port [ 'stats' ][ 'ifOutBits_rate' ]) . ')' ;
echo 'bytes(' . formatStorage ( $port [ 'stats' ][ 'ifInOctets_diff' ]) . '/' . formatStorage ( $port [ 'stats' ][ 'ifOutOctets_diff' ]) . ')' ;
echo 'pkts(' . format_si ( $port [ 'stats' ][ 'ifInUcastPkts_rate' ]) . 'pps/' . format_si ( $port [ 'stats' ][ 'ifOutUcastPkts_rate' ]) . 'pps)' ;
2012-05-16 13:25:50 +00:00
2015-07-13 20:10:26 +02:00
// Port utilisation % threshold alerting. // FIXME allow setting threshold per-port. probably 90% of ports we don't care about.
if ( $config [ 'alerts' ][ 'port_util_alert' ] && $port [ 'ignore' ] == '0' ) {
// Check for port saturation of $config['alerts']['port_util_perc'] or higher. Alert if we see this.
// Check both inbound and outbound rates
$saturation_threshold = ( $this_port [ 'ifSpeed' ] * ( $config [ 'alerts' ][ 'port_util_perc' ] / 100 ));
echo 'IN: ' . $port [ 'stats' ][ 'ifInBits_rate' ] . ' OUT: ' . $port [ 'stats' ][ 'ifOutBits_rate' ] . ' THRESH: ' . $saturation_threshold ;
if (( $port [ 'stats' ][ 'ifInBits_rate' ] >= $saturation_threshold || $port [ 'stats' ][ 'ifOutBits_rate' ] >= $saturation_threshold ) && $saturation_threshold > 0 ) {
log_event ( 'Port reached saturation threshold: ' . formatRates ( $port [ 'stats' ][ 'ifInBits_rate' ]) . '/' . formatRates ( $port [ 'stats' ][ 'ifOutBits_rate' ]) . ' - ifspeed: ' . formatRates ( $this_port [ 'stats' ][ 'ifSpeed' ]), $device , 'interface' , $port [ 'port_id' ]);
}
}
2012-05-25 18:35:17 +00:00
2015-07-13 20:10:26 +02:00
// Update RRDs
$rrdfile = $host_rrd . '/port-' . safename ( $port [ 'ifIndex' ] . '.rrd' );
if ( ! is_file ( $rrdfile )) {
rrdtool_create (
$rrdfile ,
2015-09-28 08:24:57 +00:00
' -- step 300
DS : INOCTETS : DERIVE : 600 : 0 : 12500000000
DS : OUTOCTETS : DERIVE : 600 : 0 : 12500000000
DS : INERRORS : DERIVE : 600 : 0 : 12500000000
DS : OUTERRORS : DERIVE : 600 : 0 : 12500000000
DS : INUCASTPKTS : DERIVE : 600 : 0 : 12500000000
DS : OUTUCASTPKTS : DERIVE : 600 : 0 : 12500000000
DS : INNUCASTPKTS : DERIVE : 600 : 0 : 12500000000
DS : OUTNUCASTPKTS : DERIVE : 600 : 0 : 12500000000
DS : INDISCARDS : DERIVE : 600 : 0 : 12500000000
DS : OUTDISCARDS : DERIVE : 600 : 0 : 12500000000
DS : INUNKNOWNPROTOS : DERIVE : 600 : 0 : 12500000000
DS : INBROADCASTPKTS : DERIVE : 600 : 0 : 12500000000
DS : OUTBROADCASTPKTS : DERIVE : 600 : 0 : 12500000000
DS : INMULTICASTPKTS : DERIVE : 600 : 0 : 12500000000
2015-07-13 20:10:26 +02:00
DS : OUTMULTICASTPKTS : DERIVE : 600 : 0 : 12500000000 '.$config[' rrd_rra ' ]
);
} //end if
2015-08-18 16:26:55 +00:00
$fields = array (
'INOCTETS' => $this_port [ 'ifInOctets' ],
'OUTOCTETS' => $this_port [ 'ifOutOctets' ],
'INERRORS' => $this_port [ 'ifInErrors' ],
'OUTERRORS' => $this_port [ 'ifOutErrors' ],
'INUCASTPKTS' => $this_port [ 'ifInUcastPkts' ],
'OUTUCASTPKTS' => $this_port [ 'ifOutUcastPkts' ],
'INNUCASTPKTS' => $this_port [ 'ifInNUcastPkts' ],
'OUTNUCASTPKTS' => $this_port [ 'ifOutNUcastPkts' ],
'INDISCARDS' => $this_port [ 'ifInDiscards' ],
'OUTDISCARDS' => $this_port [ 'ifOutDiscards' ],
'INUNKNOWNPROTOS' => $this_port [ 'ifInUnknownProtos' ],
'INBROADCASTPKTS' => $this_port [ 'ifInBroadcastPkts' ],
'OUTBROADCASTPKTS' => $this_port [ 'ifOutBroadcastPkts' ],
'INMULTICASTPKTS' => $this_port [ 'ifInMulticastPkts' ],
'OUTMULTICASTPKTS' => $this_port [ 'ifOutMulticastPkts' ],
2015-07-13 20:10:26 +02:00
);
2015-08-18 16:26:55 +00:00
rrdtool_update ( " $rrdfile " , $fields );
2015-07-13 20:10:26 +02:00
// End Update IF-MIB
// Update PAgP
if ( $this_port [ 'pagpOperationMode' ] || $port [ 'pagpOperationMode' ]) {
foreach ( $pagp_oids as $oid ) {
// Loop the OIDs
if ( $this_port [ $oid ] != $port [ $oid ]) {
// If data has changed, build a query
$port [ 'update' ][ $oid ] = $this_port [ $oid ];
echo 'PAgP ' ;
log_event ( " $oid -> " . $this_port [ $oid ], $device , 'interface' , $port [ 'port_id' ]);
}
}
}
2012-01-27 10:57:29 +00:00
2015-07-13 20:10:26 +02:00
// End Update PAgP
// Do EtherLike-MIB
if ( $config [ 'enable_ports_etherlike' ]) {
include 'port-etherlike.inc.php' ;
}
2009-10-28 13:49:37 +00:00
2015-07-13 20:10:26 +02:00
// Do ADSL MIB
if ( $config [ 'enable_ports_adsl' ]) {
include 'port-adsl.inc.php' ;
2009-10-28 13:49:37 +00:00
}
2011-03-23 09:54:56 +00:00
2015-07-13 20:10:26 +02:00
// Do PoE MIBs
if ( $config [ 'enable_ports_poe' ]) {
include 'port-poe.inc.php' ;
}
2011-03-23 09:54:56 +00:00
2015-07-13 20:10:26 +02:00
// Do Alcatel Detailed Stats
if ( $device [ 'os' ] == 'aos' ) {
include 'port-alcatel.inc.php' ;
}
2011-03-23 09:54:56 +00:00
2015-07-13 20:10:26 +02:00
foreach ( $port [ 'update' ] as $key => $val_check ) {
if ( ! isset ( $val_check )) {
unset ( $port [ 'update' ][ $key ]);
}
}
2012-05-25 18:35:17 +00:00
2015-07-13 20:10:26 +02:00
// Update Database
if ( count ( $port [ 'update' ])) {
$updated = dbUpdate ( $port [ 'update' ], 'ports' , '`port_id` = ?' , array ( $port [ 'port_id' ]));
2015-11-24 16:14:07 -07:00
if ( $config [ 'enable_extended_port_metrics' ] and count ( $port [ 'update_extended' ])) {
// do we want to do something else with this?
$updated += dbUpdate ( $port [ 'update_extended' ], 'ports_statistics' , '`port_id` = ?' , array ( $port [ 'port_id' ]));
}
2015-08-20 15:02:40 +02:00
d_echo ( " $updated updated " );
2015-07-13 20:10:26 +02:00
}
2015-02-16 16:33:56 -07:00
2015-07-13 20:10:26 +02:00
// End Update Database
2011-03-23 09:54:56 +00:00
}
2015-07-13 20:10:26 +02:00
else if ( $port [ 'disabled' ] != '1' ) {
echo 'Port Deleted' ;
// Port missing from SNMP cache.
if ( $port [ 'deleted' ] != '1' ) {
dbUpdate ( array ( 'deleted' => '1' ), 'ports' , '`device_id` = ? AND `ifIndex` = ?' , array ( $device [ 'device_id' ], $port [ 'ifIndex' ]));
}
2012-04-09 12:40:43 +00:00
}
2015-07-13 20:10:26 +02:00
else {
echo 'Port Disabled.' ;
} //end if
2011-03-23 09:54:56 +00:00
2015-07-13 20:10:26 +02:00
echo " \n " ;
2011-03-23 09:54:56 +00:00
2015-07-13 20:10:26 +02:00
// Clear Per-Port Variables Here
unset ( $this_port );
} //end foreach
2009-10-28 13:49:37 +00:00
2012-05-25 12:24:34 +00:00
// Clear Variables Here
2011-03-16 01:11:27 +00:00
unset ( $port_stats );