2007-04-03 14:10:23 +00:00
#!/usr/bin/php
< ?
include ( " config.php " );
include ( " includes/functions.php " );
# Discover interfaces
2007-04-11 20:57:56 +00:00
$device_query = mysql_query ( " SELECT device_id,hostname,community,snmpver FROM `devices` WHERE `device_id` LIKE '% " . $argv [ 1 ] . " ' AND status = '1' AND os != 'Snom' ORDER BY device_id DESC " );
2007-04-03 14:10:23 +00:00
while ( $device = mysql_fetch_row ( $device_query )) {
$id = $device [ '0' ];
$hostname = $device [ '1' ];
$community = $device [ '2' ];
$snmpver = $device [ '3' ];
$interfaces = `snmpwalk -O nsq -v2c -c $community $hostname ".1.3.6.1.2.1.2.2.1.2" | sed s/ifDescr.//g | sed s/\ \"/\|\|\"/g | sed s/\ /\|\|/g` ;
$interfaces = trim ( $interfaces );
echo ( " Polling $hostname\n " );
foreach ( explode ( " \n " , $interfaces ) as $entry ){
$entry = trim ( $entry );
list ( $ifIndex , $ifName ) = explode ( " || " , $entry );
if ( ! strstr ( $entry , " irtual " )) {
$ifName = trim ( str_replace ( " \" " , " " , $ifName ));
$if = trim ( strtolower ( $ifName ));
$nullintf = 0 ;
foreach ( $bif as $bi ) {
2007-11-23 11:37:28 +00:00
# echo("'$bi' -> '$if'\n");
2007-04-03 14:10:23 +00:00
if ( strstr ( $if , $bi )) {
2007-11-23 11:37:28 +00:00
echo ( " ' $bi ' -> ' $if ' MATCH! \n " );
2007-04-03 14:10:23 +00:00
$nullintf = 1 ;
}
}
if ( preg_match ( '/serial[0-9]:/' , $if )) { $nullintf = '1' ; }
2007-11-23 11:37:28 +00:00
if ( preg_match ( '/ng[0-9]+$/' , $if )) { $nullintf = '1' ; }
2007-04-03 14:10:23 +00:00
if ( $nullintf == 0 ) {
2007-04-07 21:15:23 +00:00
if ( mysql_result ( mysql_query ( " SELECT COUNT(*) FROM `interfaces` WHERE `device_id` = ' $id ' AND `ifIndex` = ' $ifIndex ' " ), 0 ) == '0' ) {
2007-04-03 14:10:23 +00:00
echo " Adding port $ifName \n " ;
2007-04-07 21:15:23 +00:00
mysql_query ( " INSERT INTO `interfaces` (`device_id`,`ifIndex`,`ifDescr`) VALUES (' $id ',' $ifIndex ',' $ifName ') " );
2007-04-03 14:10:23 +00:00
} else {
# echo("Already have $ifName \n");
}
} else {
# echo("Invalid $ifName\n");
}
}
}
}
?>