2009-09-07 11:07:59 +00:00
|
|
|
<?php
|
2008-03-22 23:09:35 +00:00
|
|
|
|
2010-02-20 17:22:22 +00:00
|
|
|
# Discover ports
|
2008-03-22 23:09:35 +00:00
|
|
|
|
2010-07-05 19:21:36 +00:00
|
|
|
echo("Ports : ");
|
2008-03-22 23:09:35 +00:00
|
|
|
|
2012-05-11 17:43:30 +00:00
|
|
|
/// Loop database and build a little cache to reduce db hits.
|
|
|
|
foreach(dbFetchRows("SELECT * FROM `ports` WHERE `device_id` = ?", array($device['device_id'])) as $port)
|
|
|
|
{
|
|
|
|
$ports_db[$port['ifIndex']] = $port;
|
|
|
|
$ports_l[$port['ifIndex']] = $port['interface_id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
#print_r($ports_db);
|
|
|
|
|
2012-05-11 18:01:28 +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");
|
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-11 17:43:30 +00:00
|
|
|
$interface_id = dbInsert(array('device_id' => $device['device_id'], 'ifIndex' => $ifIndex), 'ports');
|
|
|
|
echo("Adding: ".$port['ifName']."(".$ifIndex.")(".$ports_db[$port['ifIndex']]['interface_id'].")");
|
|
|
|
} elseif ($ports_db[$ifIndex]['deleted'] == "1") {
|
|
|
|
dbUpdate(array('deleted' => '0'), 'ports', '`interface_id` = ?', array($ports_db[$ifIndex]['interface_id']));
|
|
|
|
$ports_db[$ifIndex]['deleted'] = "0";
|
|
|
|
echo("U");
|
2011-05-18 23:08:45 +00:00
|
|
|
} else {
|
2012-05-11 17:43:30 +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")
|
|
|
|
{
|
|
|
|
dbUpdate(array('deleted' => '1'), 'ports', '`interface_id` = ?', array($ports_db[$ifIndex]['interface_id']));
|
|
|
|
$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-11 17:43:30 +00:00
|
|
|
foreach($ports_l as $ifIndex => $port_id)
|
2011-03-26 19:12:24 +00:00
|
|
|
{
|
2012-05-11 17:43:30 +00:00
|
|
|
if($ports_db[$ifIndex]['deleted'] == "0")
|
2011-03-26 19:12:24 +00:00
|
|
|
{
|
2012-05-11 17:43:30 +00:00
|
|
|
dbUpdate(array('deleted' => '1'), 'ports', '`interface_id` = ?', array($port_id));
|
|
|
|
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
|
2008-04-03 21:52:59 +00:00
|
|
|
|
2010-07-05 19:21:36 +00:00
|
|
|
echo("\n");
|
2008-03-22 23:09:35 +00:00
|
|
|
|
2011-05-18 23:08:45 +00:00
|
|
|
?>
|