2010-01-05 18:40:05 +00:00
< ? php
2010-07-05 19:21:36 +00:00
2010-11-20 14:04:07 +00:00
echo ( " Discovery protocols: " );
2010-01-05 18:40:05 +00:00
2011-05-04 09:13:32 +00:00
global $link_exists ;
2010-01-05 18:40:05 +00:00
$community = $device [ 'community' ];
2011-03-15 11:24:35 +00:00
if ( $device [ 'os' ] == " ironware " )
{
2010-07-05 19:21:36 +00:00
echo ( " Brocade FDP: " );
2010-07-22 21:58:49 +00:00
$fdp_array = snmpwalk_cache_twopart_oid ( $device , " snFdpCacheEntry " , array (), " FOUNDRY-SN-SWITCH-GROUP-MIB " );
2011-03-15 11:24:35 +00:00
if ( $fdp_array )
{
2010-07-05 19:21:36 +00:00
unset ( $fdp_links );
2011-03-15 11:24:35 +00:00
foreach ( array_keys ( $fdp_array ) as $key )
2010-08-03 15:33:20 +00:00
{
2011-04-06 13:54:50 +00:00
$interface = mysql_fetch_assoc ( mysql_query ( " SELECT * FROM `ports` WHERE device_id = ' " . $device [ 'device_id' ] . " ' AND `ifIndex` = ' " . $key . " ' " ));
2010-07-05 19:21:36 +00:00
$fdp_if_array = $fdp_array [ $key ];
2011-03-15 11:24:35 +00:00
foreach ( array_keys ( $fdp_if_array ) as $entry_key )
2010-07-05 19:21:36 +00:00
{
$fdp = $fdp_if_array [ $entry_key ];
$remote_device_id = @ mysql_result ( mysql_query ( " SELECT `device_id` FROM `devices` WHERE `sysName` = ' " . $fdp [ 'snFdpCacheDeviceId' ] . " ' OR `hostname`=' " . $fdp [ 'snFdpCacheDeviceId' ] . " ' " ), 0 );
2010-08-03 15:33:20 +00:00
2011-03-15 11:24:35 +00:00
if ( $remote_device_id )
{
2010-07-05 19:21:36 +00:00
$if = $fdp [ 'snFdpCacheDevicePort' ];
$remote_interface_id = @ mysql_result ( mysql_query ( " SELECT interface_id FROM `ports` WHERE (`ifDescr` = ' $if ' OR `ifName`=' $if ') AND `device_id` = ' " . $remote_device_id . " ' " ), 0 );
} else { $remote_interface_id = " 0 " ; }
2010-02-15 23:56:30 +00:00
2010-07-05 19:21:36 +00:00
discover_link ( $interface [ 'interface_id' ], $fdp [ 'snFdpCacheVendorId' ], $remote_interface_id , $fdp [ 'snFdpCacheDeviceId' ], $fdp [ 'snFdpCacheDevicePort' ], $fdp [ 'snFdpCachePlatform' ], $fdp [ 'snFdpCacheVersion' ]);
}
2010-02-15 23:56:30 +00:00
}
}
}
2011-03-15 11:24:35 +00:00
echo ( " CISCO-CDP-MIB: " );
2010-08-03 15:33:20 +00:00
unset ( $cdp_array );
$cdp_array = snmpwalk_cache_twopart_oid ( $device , " cdpCache " , array (), " CISCO-CDP-MIB " );
2011-03-15 11:24:35 +00:00
if ( $cdp_array )
{
2010-08-03 15:33:20 +00:00
unset ( $cdp_links );
2011-03-15 11:24:35 +00:00
foreach ( array_keys ( $cdp_array ) as $key )
{
2011-04-06 13:54:50 +00:00
$interface = mysql_fetch_assoc ( mysql_query ( " SELECT * FROM `ports` WHERE device_id = ' " . $device [ 'device_id' ] . " ' AND `ifIndex` = ' " . $key . " ' " ));
2011-03-15 11:24:35 +00:00
$cdp_if_array = $cdp_array [ $key ];
foreach ( array_keys ( $cdp_if_array ) as $entry_key )
2010-08-03 15:33:20 +00:00
{
$cdp = $cdp_if_array [ $entry_key ];
$remote_device_id = @ mysql_result ( mysql_query ( " SELECT `device_id` FROM `devices` WHERE `sysName` = ' " . $cdp [ 'cdpCacheDeviceId' ] . " ' OR `hostname`=' " . $cdp [ 'cdpCacheDeviceId' ] . " ' " ), 0 );
2011-03-15 11:24:35 +00:00
if ( $remote_device_id )
2010-08-03 15:33:20 +00:00
{
$if = $cdp [ 'cdpCacheDevicePort' ];
$remote_interface_id = @ mysql_result ( mysql_query ( " SELECT interface_id FROM `ports` WHERE (`ifDescr` = ' $if ' OR `ifName`=' $if ') AND `device_id` = ' " . $remote_device_id . " ' " ), 0 );
} else { $remote_interface_id = " 0 " ; }
2011-03-15 11:24:35 +00:00
if ( $interface [ 'interface_id' ] && $cdp [ 'cdpCacheDeviceId' ] && $cdp [ 'cdpCacheDevicePort' ])
2010-08-03 15:33:20 +00:00
{
discover_link ( $interface [ 'interface_id' ], 'cdp' , $remote_interface_id , $cdp [ 'cdpCacheDeviceId' ], $cdp [ 'cdpCacheDevicePort' ], $cdp [ 'cdpCachePlatform' ], $cdp [ 'cdpCacheVersion' ]);
}
2011-03-15 11:24:35 +00:00
}
2010-01-05 18:40:05 +00:00
}
}
2010-02-17 18:54:34 +00:00
echo ( " LLDP-MIB: " );
2010-01-05 18:40:05 +00:00
unset ( $lldp_array );
2010-07-22 21:58:49 +00:00
$lldp_array = snmpwalk_cache_threepart_oid ( $device , " lldpRemoteSystemsData " , array (), " LLDP-MIB " );
2010-07-28 18:56:14 +00:00
$dot1d_array = snmpwalk_cache_oid ( $device , " dot1dBasePortIfIndex " , array (), " BRIDGE-MIB " );
2011-03-15 11:24:35 +00:00
if ( $lldp_array )
{
2010-01-17 00:05:14 +00:00
$lldp_links = " " ;
2011-03-15 11:24:35 +00:00
foreach ( array_keys ( $lldp_array ) as $key )
{
$lldp_if_array = $lldp_array [ $key ];
foreach ( array_keys ( $lldp_if_array ) as $entry_key )
{
if ( is_numeric ( $dot1d_array [ $entry_key ][ 'dot1dBasePortIfIndex' ]))
2010-07-28 18:56:14 +00:00
{
$ifIndex = $dot1d_array [ $entry_key ][ 'dot1dBasePortIfIndex' ];
} else {
$ifIndex = $entry_key ;
2011-03-15 11:24:35 +00:00
}
2011-04-06 13:54:50 +00:00
$interface = mysql_fetch_assoc ( mysql_query ( " SELECT * FROM `ports` WHERE device_id = ' " . $device [ 'device_id' ] . " ' AND `ifIndex` = ' " . $ifIndex . " ' " ));
2010-02-15 23:56:30 +00:00
$lldp_instance = $lldp_if_array [ $entry_key ];
2011-03-15 11:24:35 +00:00
foreach ( array_keys ( $lldp_instance ) as $entry_instance )
2010-08-03 15:33:20 +00:00
{
2010-07-05 19:21:36 +00:00
$lldp = $lldp_instance [ $entry_instance ];
$remote_device_id = @ mysql_result ( mysql_query ( " SELECT `device_id` FROM `devices` WHERE `sysName` = ' " . $lldp [ 'lldpRemSysName' ] . " ' OR `hostname`=' " . $lldp [ 'lldpRemSysName' ] . " ' " ), 0 );
2010-08-03 15:33:20 +00:00
2011-03-15 11:24:35 +00:00
if ( $remote_device_id )
2010-08-03 15:33:20 +00:00
{
2010-07-30 15:04:44 +00:00
$if = $lldp [ 'lldpRemPortDesc' ]; $id = $lldp [ 'lldpRemPortId' ];
$remote_interface_id = @ mysql_result ( mysql_query ( " SELECT interface_id FROM `ports` WHERE (`ifDescr` = ' $if ' OR `ifName`=' $if ' OR `ifDescr`= ' $id ' OR `ifName`=' $id ') AND `device_id` = ' " . $remote_device_id . " ' " ), 0 );
2010-07-05 19:21:36 +00:00
} else { $remote_interface_id = " 0 " ; }
2010-08-03 15:33:20 +00:00
2011-03-15 11:24:35 +00:00
if ( is_numeric ( $interface [ 'interface_id' ]) && isset ( $lldp [ 'lldpRemSysName' ]) && isset ( $lldp [ 'lldpRemPortId' ]))
{
2010-07-28 18:56:14 +00:00
discover_link ( $interface [ 'interface_id' ], 'lldp' , $remote_interface_id , $lldp [ 'lldpRemSysName' ], $lldp [ 'lldpRemPortId' ], NULL , $lldp [ 'lldpRemSysDesc' ]);
2010-07-05 19:21:36 +00:00
}
2010-01-05 18:40:05 +00:00
}
2011-03-15 11:24:35 +00:00
}
2010-01-05 18:40:05 +00:00
}
}
2011-03-15 11:24:35 +00:00
if ( $debug ) { print_r ( $link_exists ); }
2010-02-15 23:56:30 +00:00
2010-02-20 17:22:22 +00:00
$sql = " SELECT * FROM `links` AS L, `ports` AS I WHERE L.local_interface_id = I.interface_id AND I.device_id = ' " . $device [ 'device_id' ] . " ' " ;
2010-02-15 23:56:30 +00:00
if ( $query = mysql_query ( $sql ))
{
2011-04-06 13:54:50 +00:00
while ( $test = mysql_fetch_assoc ( $query ))
2010-02-15 23:56:30 +00:00
{
$local_interface_id = $test [ 'local_interface_id' ];
$remote_hostname = $test [ 'remote_hostname' ];
$remote_port = $test [ 'remote_port' ];
2011-03-15 11:24:35 +00:00
if ( $debug ) { echo ( " $local_interface_id -> $remote_hostname -> $remote_port \n " ); }
if ( ! $link_exists [ $local_interface_id ][ $remote_hostname ][ $remote_port ])
{
2010-02-15 23:56:30 +00:00
echo ( " - " );
mysql_query ( " DELETE FROM `links` WHERE id = ' " . $test [ 'id' ] . " ' " );
2011-03-15 11:24:35 +00:00
if ( $debug ) { echo ( mysql_affected_rows () . " deleted " ); }
2010-02-15 23:56:30 +00:00
}
2010-01-05 18:40:05 +00:00
}
}
2011-03-15 11:24:35 +00:00
unset ( $link_exists );
2010-07-05 19:21:36 +00:00
echo ( " \n " );
2010-01-05 18:40:05 +00:00
2011-04-20 11:19:46 +00:00
?>