2009-09-07 11:07:59 +00:00
|
|
|
<?php
|
2008-03-22 23:09:35 +00:00
|
|
|
|
2012-05-11 18:08:48 +00:00
|
|
|
/// Build SNMP Cache Array
|
2008-03-22 23:09:35 +00:00
|
|
|
|
2012-05-16 13:25:50 +00:00
|
|
|
$port_stats = array();
|
|
|
|
$port_stats = snmpwalk_cache_oid($device, "ifDescr", $port_stats, "IF-MIB");
|
|
|
|
$port_stats = snmpwalk_cache_oid($device, "ifName", $port_stats, "IF-MIB");
|
|
|
|
$port_stats = snmpwalk_cache_oid($device, "ifType", $port_stats, "IF-MIB");
|
2012-05-11 18:08:48 +00:00
|
|
|
|
|
|
|
/// End Building SNMP Cache Array
|
2012-05-11 17:43:30 +00:00
|
|
|
|
2012-05-11 18:08:48 +00:00
|
|
|
if ($debug) { print_r($port_stats); }
|
|
|
|
|
|
|
|
/// Build array of ports in the database
|
|
|
|
|
|
|
|
## FIXME -- this stuff is a little messy, looping the array to make an array just seems wrong. :>
|
|
|
|
## -- i can make it a function, so that you don't know what it's doing.
|
|
|
|
## -- $ports_db = adamasMagicFunction($ports_db); ?
|
|
|
|
|
2012-05-15 15:18:57 +00:00
|
|
|
foreach (dbFetchRows("SELECT * FROM `ports` WHERE `device_id` = ?", array($device['device_id'])) as $port)
|
2012-05-11 18:08:48 +00:00
|
|
|
{
|
|
|
|
$ports_db[$port['ifIndex']] = $port;
|
2012-05-16 13:25:50 +00:00
|
|
|
$ports_db_l[$port['ifIndex']] = $port['port_id'];
|
2012-05-11 18:08:48 +00:00
|
|
|
}
|
2008-03-22 23:09:35 +00:00
|
|
|
|
2012-05-11 18:01:28 +00:00
|
|
|
/// New interface detection
|
|
|
|
foreach ($port_stats as $ifIndex => $port)
|
2011-03-26 19:12:24 +00:00
|
|
|
{
|
2012-05-11 17:43:30 +00:00
|
|
|
/// Check the port against our filters.
|
2011-05-18 23:08:45 +00:00
|
|
|
if (is_port_valid($port, $device))
|
2011-03-26 19:12:24 +00:00
|
|
|
{
|
2012-05-11 17:43:30 +00:00
|
|
|
if (!is_array($ports_db[$ifIndex]))
|
2011-03-26 19:12:24 +00:00
|
|
|
{
|
2012-05-16 13:25:50 +00:00
|
|
|
$port_id = dbInsert(array('device_id' => $device['device_id'], 'ifIndex' => $ifIndex), 'ports');
|
2012-05-11 18:08:48 +00:00
|
|
|
$ports_db[$ifIndex] = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?", array($device['device_id'], $ifIndex));
|
2012-05-16 13:25:50 +00:00
|
|
|
echo("Adding: ".$port['ifName']."(".$ifIndex.")(".$ports_db[$port['ifIndex']]['port_id'].")");
|
2012-05-11 17:43:30 +00:00
|
|
|
} elseif ($ports_db[$ifIndex]['deleted'] == "1") {
|
2012-05-16 13:25:50 +00:00
|
|
|
dbUpdate(array('deleted' => '0'), 'ports', '`port_id` = ?', array($ports_db[$ifIndex]['port_id']));
|
2012-05-11 17:43:30 +00:00
|
|
|
$ports_db[$ifIndex]['deleted'] = "0";
|
|
|
|
echo("U");
|
2011-05-18 23:08:45 +00:00
|
|
|
} else {
|
2012-05-15 15:18:57 +00:00
|
|
|
echo(".");
|
2010-07-05 19:21:36 +00:00
|
|
|
}
|
2012-05-11 17:43:30 +00:00
|
|
|
/// We've seen it. Remove it from the cache.
|
|
|
|
unset($ports_l[$ifIndex]);
|
2011-05-18 23:08:45 +00:00
|
|
|
} else {
|
2012-05-11 17:43:30 +00:00
|
|
|
if (is_array($ports_db[$port['ifIndex']])) {
|
|
|
|
if ($ports_db[$port['ifIndex']]['deleted'] != "1")
|
|
|
|
{
|
2012-05-16 13:25:50 +00:00
|
|
|
dbUpdate(array('deleted' => '1'), 'ports', '`port_id` = ?', array($ports_db[$ifIndex]['port_id']));
|
2012-05-11 17:43:30 +00:00
|
|
|
$ports_db[$ifIndex]['deleted'] = "1";
|
2012-05-11 18:01:28 +00:00
|
|
|
echo("-");
|
2012-05-11 17:43:30 +00:00
|
|
|
}
|
2010-07-05 19:21:36 +00:00
|
|
|
}
|
2012-05-11 17:43:30 +00:00
|
|
|
echo("X");
|
2011-03-16 17:53:20 +00:00
|
|
|
}
|
2010-07-05 19:21:36 +00:00
|
|
|
}
|
2012-05-11 18:01:28 +00:00
|
|
|
/// End New interface detection
|
2008-04-03 21:52:59 +00:00
|
|
|
|
2012-05-11 18:01:28 +00:00
|
|
|
/// Interface Deletion
|
|
|
|
/// If it's in our $ports_l list, that means it's not been seen. Mark it deleted.
|
2012-05-15 15:18:57 +00:00
|
|
|
foreach ($ports_l as $ifIndex => $port_id)
|
2011-03-26 19:12:24 +00:00
|
|
|
{
|
2012-05-15 15:18:57 +00:00
|
|
|
if ($ports_db[$ifIndex]['deleted'] == "0")
|
2011-03-26 19:12:24 +00:00
|
|
|
{
|
2012-05-16 13:25:50 +00:00
|
|
|
dbUpdate(array('deleted' => '1'), 'ports', '`port_id` = ?', array($port_id));
|
2012-05-11 17:43:30 +00:00
|
|
|
echo("-".$ifIndex);
|
2008-04-03 21:52:59 +00:00
|
|
|
}
|
2010-07-05 19:21:36 +00:00
|
|
|
}
|
2012-05-11 18:01:28 +00:00
|
|
|
/// End interface deletion
|
2010-07-05 19:21:36 +00:00
|
|
|
echo("\n");
|
2012-05-11 18:08:48 +00:00
|
|
|
|
|
|
|
/// Clear Variables Here
|
|
|
|
unset($port_stats);
|
2012-05-16 13:25:50 +00:00
|
|
|
unset($ports_db);
|
|
|
|
unset($ports_db_db);
|
2008-03-22 23:09:35 +00:00
|
|
|
|
2011-05-18 23:08:45 +00:00
|
|
|
?>
|