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' ];
2015-05-18 20:32:11 +10:00
if ( $device [ 'os' ] == " ironware " && $config [ 'autodiscovery' ][ 'xdp' ] === TRUE )
2011-03-15 11:24:35 +00:00
{
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
{
2014-01-13 17:43:58 +00:00
$interface = dbFetchRow ( " SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ? " , array ( $device [ 'device_id' ], $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
{
2011-09-20 14:22:34 +00:00
$fdp = $fdp_if_array [ $entry_key ];
2014-01-13 17:43:58 +00:00
$remote_device_id = dbFetchCell ( " SELECT `device_id` FROM `devices` WHERE `sysName` = ? OR `hostname` = ? " , array ( $fdp [ 'snFdpCacheDeviceId' ], $fdp [ 'snFdpCacheDeviceId' ]));
2011-09-14 17:26:59 +00:00
2011-09-20 14:22:34 +00:00
if ( ! $remote_device_id )
2011-09-14 17:26:59 +00:00
{
$remote_device_id = discover_new_device ( $fdp [ 'snFdpCacheDeviceId' ]);
2011-09-28 14:30:24 +00:00
if ( $remote_device_id )
{
$int = ifNameDescr ( $interface );
2012-05-16 13:25:50 +00:00
log_event ( " Device autodiscovered through FDP on " . $device [ 'hostname' ] . " (port " . $int [ 'label' ] . " ) " , $remote_device_id , 'interface' , $int [ 'port_id' ]);
2011-09-28 14:30:24 +00:00
}
2011-09-14 17:26:59 +00:00
}
2011-09-20 14:22:34 +00:00
if ( $remote_device_id )
{
$if = $fdp [ 'snFdpCacheDevicePort' ];
2014-06-24 02:43:05 +01:00
$remote_port_id = dbFetchCell ( " SELECT port_id FROM `ports` WHERE (`ifDescr` = ? OR `ifName` = ?) AND `device_id` = ? " , array ( $if , $if , $remote_device_id ));
2012-05-16 13:25:50 +00:00
} else { $remote_port_id = " 0 " ; }
2010-02-15 23:56:30 +00:00
2015-03-28 14:05:40 +00:00
discover_link ( $interface [ 'port_id' ], $fdp [ 'snFdpCacheVendorId' ], $remote_port_id , $fdp [ 'snFdpCacheDeviceId' ], $fdp [ 'snFdpCacheDevicePort' ], $fdp [ 'snFdpCachePlatform' ], $fdp [ 'snFdpCacheVersion' ], $device [ 'device_id' ], $remote_device_id );
2010-07-05 19:21:36 +00:00
}
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 " );
2015-05-18 20:32:11 +10:00
if ( $cdp_array && $config [ 'autodiscovery' ][ 'xdp' ] === TRUE )
2011-03-15 11:24:35 +00:00
{
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-12-16 14:42:37 +00:00
$interface = dbFetchRow ( " SELECT * FROM `ports` WHERE device_id = ? AND `ifIndex` = ? " , array ( $device [ 'device_id' ], $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 ];
2011-10-06 13:13:15 +00:00
if ( is_valid_hostname ( $cdp [ 'cdpCacheDeviceId' ]))
2011-09-28 14:30:24 +00:00
{
2011-12-16 14:42:37 +00:00
$remote_device_id = dbFetchCell ( " SELECT `device_id` FROM `devices` WHERE `sysName` = ? OR `hostname` = ? " , array ( $cdp [ 'cdpCacheDeviceId' ], $cdp [ 'cdpCacheDeviceId' ]));
2011-10-05 13:46:16 +00:00
if ( ! $remote_device_id )
2011-09-14 17:26:59 +00:00
{
2011-10-05 13:46:16 +00:00
$remote_device_id = discover_new_device ( $cdp [ 'cdpCacheDeviceId' ]);
if ( $remote_device_id )
{
$int = ifNameDescr ( $interface );
2012-05-16 13:25:50 +00:00
log_event ( " Device autodiscovered through CDP on " . $device [ 'hostname' ] . " (port " . $int [ 'label' ] . " ) " , $remote_device_id , 'interface' , $int [ 'port_id' ]);
2011-10-05 13:46:16 +00:00
}
2011-09-14 17:26:59 +00:00
}
2011-10-05 13:46:16 +00:00
if ( $remote_device_id )
{
$if = $cdp [ 'cdpCacheDevicePort' ];
2012-05-16 13:25:50 +00:00
$remote_port_id = dbFetchCell ( " SELECT port_id FROM `ports` WHERE (`ifDescr` = ? OR `ifName` = ?) AND `device_id` = ? " , array ( $if , $if , $remote_device_id ));
} else { $remote_port_id = " 0 " ; }
2010-08-03 15:33:20 +00:00
2012-05-16 13:25:50 +00:00
if ( $interface [ 'port_id' ] && $cdp [ 'cdpCacheDeviceId' ] && $cdp [ 'cdpCacheDevicePort' ])
2011-10-05 13:46:16 +00:00
{
2015-03-28 14:05:40 +00:00
discover_link ( $interface [ 'port_id' ], 'cdp' , $remote_port_id , $cdp [ 'cdpCacheDeviceId' ], $cdp [ 'cdpCacheDevicePort' ], $cdp [ 'cdpCachePlatform' ], $cdp [ 'cdpCacheVersion' ], $device [ 'device_id' ], $remote_device_id );
2011-10-05 13:46:16 +00:00
}
2010-08-03 15:33:20 +00:00
}
2011-10-06 13:13:15 +00:00
else
{
echo ( " X " );
}
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 " );
2015-05-18 20:32:11 +10:00
if ( $lldp_array && $config [ 'autodiscovery' ][ 'xdp' ] === TRUE )
2011-03-15 11:24:35 +00:00
{
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
}
2014-01-13 17:43:58 +00:00
$interface = dbFetchRow ( " SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ? " , array ( $device [ 'device_id' ], $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
{
2011-09-20 14:22:34 +00:00
$lldp = $lldp_instance [ $entry_instance ];
2014-01-13 17:43:58 +00:00
$remote_device_id = dbFetchCell ( " SELECT `device_id` FROM `devices` WHERE `sysName` = ? OR `hostname` = ? " , array ( $lldp [ 'lldpRemSysName' ], $lldp [ 'lldpRemSysName' ]));
2011-09-14 17:26:59 +00:00
2012-01-20 13:15:05 +00:00
if ( ! $remote_device_id && is_valid_hostname ( $lldp [ 'lldpRemSysName' ]))
2011-09-14 17:26:59 +00:00
{
$remote_device_id = discover_new_device ( $lldp [ 'lldpRemSysName' ]);
2011-09-28 14:30:24 +00:00
if ( $remote_device_id )
{
$int = ifNameDescr ( $interface );
2012-05-16 13:25:50 +00:00
log_event ( " Device autodiscovered through LLDP on " . $device [ 'hostname' ] . " (port " . $int [ 'label' ] . " ) " , $remote_device_id , 'interface' , $int [ 'port_id' ]);
2011-09-28 14:30:24 +00:00
}
2011-09-14 17:26:59 +00:00
}
2011-09-20 14:22:34 +00:00
if ( $remote_device_id )
{
$if = $lldp [ 'lldpRemPortDesc' ]; $id = $lldp [ 'lldpRemPortId' ];
2014-01-13 17:43:58 +00:00
$remote_port_id = dbFetchCell ( " SELECT `port_id` FROM `ports` WHERE (`ifDescr` = ? OR `ifName` = ? OR `ifDescr` = ? OR `ifName` = ?) AND `device_id` = ? " , array ( $if , $if , $id , $id , $remote_device_id ));
2011-09-20 14:22:34 +00:00
} else {
2012-05-16 13:25:50 +00:00
$remote_port_id = " 0 " ;
2011-09-14 17:26:59 +00:00
}
2012-05-16 13:25:50 +00:00
if ( is_numeric ( $interface [ 'port_id' ]) && isset ( $lldp [ 'lldpRemSysName' ]) && isset ( $lldp [ 'lldpRemPortId' ]))
2011-09-28 14:30:24 +00:00
{
2015-03-28 14:05:40 +00:00
discover_link ( $interface [ 'port_id' ], 'lldp' , $remote_port_id , $lldp [ 'lldpRemSysName' ], $lldp [ 'lldpRemPortId' ], NULL , $lldp [ 'lldpRemSysDesc' ], $device [ 'device_id' ], $remote_device_id );
2011-09-20 14:22:34 +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
}
}
2015-04-11 15:01:14 +01:00
echo ( " OSPF Discovery: " );
if ( $config [ 'autodiscovery' ][ 'ospf' ] === TRUE ) {
echo " enabled \n " ;
2015-05-20 13:41:23 +01:00
foreach ( dbFetchRows ( " SELECT DISTINCT(`ospfNbrIpAddr`),`device_id` FROM `ospf_nbrs` WHERE `device_id`=? " , array ( $device [ 'device_id' ])) as $nbr ) {
2015-04-11 15:01:14 +01:00
$ip = $nbr [ 'ospfNbrIpAddr' ];
if ( match_network ( $config [ 'autodiscovery' ][ 'nets-exclude' ], $ip )) {
echo ( " x " );
continue ;
}
if ( ! match_network ( $config [ 'nets' ], $ip )) {
echo ( " i " );
continue ;
}
$name = gethostbyaddr ( $ip );
$remote_device_id = discover_new_device ( $name );
if ( isset ( $remote_device_id ) && $remote_device_id > 0 ) {
log_event ( " Device $name ( $ip ) autodiscovered through OSPF " , $remote_device_id , 'system' );
} else {
2015-05-20 13:41:23 +01:00
log_event ( " OSPF discovery of $name ( $ip ) failed - check ping and SNMP access " , $device [ 'device_id' ], 'system' );
2015-04-11 15:01:14 +01:00
}
}
} else {
echo " disabled \n " ;
}
2011-03-15 11:24:35 +00:00
if ( $debug ) { print_r ( $link_exists ); }
2010-02-15 23:56:30 +00:00
2012-05-16 13:25:50 +00:00
$sql = " SELECT * FROM `links` AS L, `ports` AS I WHERE L.local_port_id = I.port_id AND I.device_id = ' " . $device [ 'device_id' ] . " ' " ;
2014-01-13 17:43:58 +00:00
foreach ( dbFetchRows ( $sql ) as $test )
2010-02-15 23:56:30 +00:00
{
2012-05-16 13:25:50 +00:00
$local_port_id = $test [ 'local_port_id' ];
2010-02-15 23:56:30 +00:00
$remote_hostname = $test [ 'remote_hostname' ];
$remote_port = $test [ 'remote_port' ];
2012-05-16 13:25:50 +00:00
if ( $debug ) { echo ( " $local_port_id -> $remote_hostname -> $remote_port \n " ); }
if ( ! $link_exists [ $local_port_id ][ $remote_hostname ][ $remote_port ])
2011-03-15 11:24:35 +00:00
{
2010-02-15 23:56:30 +00:00
echo ( " - " );
2014-01-13 17:43:58 +00:00
$rows = dbDelete ( 'links' , '`id` = ?' , array ( $test [ 'id' ]));
if ( $debug ) { echo ( " $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
?>