@@ -119,7 +119,7 @@ if ($_SESSION['userlevel'] >= '5')
$query = mysql_query($sql);
unset ($seperator);
while ($interface = mysql_fetch_assoc($query)) {
- $ports['transit'] .= $seperator . $interface['interface_id'];
+ $ports['transit'] .= $seperator . $interface['port_id'];
$seperator = ",";
}
@@ -127,7 +127,7 @@ if ($_SESSION['userlevel'] >= '5')
$query = mysql_query($sql);
unset ($seperator);
while ($interface = mysql_fetch_assoc($query)) {
- $ports['peering'] .= $seperator . $interface['interface_id'];
+ $ports['peering'] .= $seperator . $interface['port_id'];
$seperator = ",";
}
@@ -135,7 +135,7 @@ if ($_SESSION['userlevel'] >= '5')
$query = mysql_query($sql);
unset ($seperator);
while ($interface = mysql_fetch_assoc($query)) {
- $ports['core'] .= $seperator . $interface['interface_id'];
+ $ports['core'] .= $seperator . $interface['port_id'];
$seperator = ",";
}
diff --git a/html/pages/iftype.inc.php b/html/pages/iftype.inc.php
index bdc7ba56a..346a46436 100644
--- a/html/pages/iftype.inc.php
+++ b/html/pages/iftype.inc.php
@@ -17,7 +17,7 @@ $ports = dbFetchRows("SELECT * FROM `ports` as I, `devices` AS D WHERE $type_whe
foreach ($ports as $port)
{
- $if_list .= $seperator . $port['interface_id'];
+ $if_list .= $seperator . $port['port_id'];
$seperator = ",";
}
unset($seperator);
@@ -32,7 +32,7 @@ echo("
if ($if_list)
{
$graph_type = "multiport_bits_separate";
- $port['interface_id'] = $if_list;
+ $port['port_id'] = $if_list;
include("includes/print-interface-graphs.inc.php");
@@ -50,9 +50,9 @@ if ($if_list)
" . generate_port_link($port,$port['port_descr_descr']) . "
".generate_device_link($port)." ".generate_port_link($port)." ");
- if (dbFetchCell("SELECT count(*) FROM mac_accounting WHERE interface_id = ?", array($port['interface_id'])))
+ if (dbFetchCell("SELECT count(*) FROM mac_accounting WHERE port_id = ?", array($port['port_id'])))
{
- echo(" MAC Accounting");
+ echo(" MAC Accounting");
}
echo(' ');
diff --git a/html/pages/ports/graph.inc.php b/html/pages/ports/graph.inc.php
index 768aeca8b..90455b2d1 100644
--- a/html/pages/ports/graph.inc.php
+++ b/html/pages/ports/graph.inc.php
@@ -15,7 +15,7 @@ foreach ($ports as $port)
$error_img = generate_port_link($port," ",errors);
} else { $error_img = ""; }
- if (port_permitted($port['interface_id'], $port['device_id']))
+ if (port_permitted($port['port_id'], $port['device_id']))
{
$port = ifLabel($port, $device);
@@ -28,7 +28,7 @@ foreach ($ports as $port)
$graph_array['height'] = 100;
$graph_array['width'] = 210;
$graph_array['to'] = $config['time']['now'];
- $graph_array['id'] = $port['interface_id'];
+ $graph_array['id'] = $port['port_id'];
$graph_array['type'] = $graph_type;
$graph_array['from'] = $config['time']['day'];
$graph_array['legend'] = "no";
@@ -49,9 +49,9 @@ foreach ($ports as $port)
# echo("\
-# \
+# \
# ', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\" >".
-# "
+# "
#
# ");
}
diff --git a/html/pages/ports/list.inc.php b/html/pages/ports/list.inc.php
index 42534e512..375fabc0c 100644
--- a/html/pages/ports/list.inc.php
+++ b/html/pages/ports/list.inc.php
@@ -35,7 +35,7 @@ foreach ($ports as $port)
} elseif ($port['ifAdminStatus'] == "up" && $port['ifOperStatus']== "up") { $ports_up++; }
$ports_total++;
- if (port_permitted($port['interface_id'], $port['device_id']))
+ if (port_permitted($port['port_id'], $port['device_id']))
{
$speed = humanspeed($port['ifSpeed']);
$type = humanmedia($port['ifType']);
diff --git a/html/pages/pseudowires.inc.php b/html/pages/pseudowires.inc.php
index 4d8649ff7..b506e0efc 100644
--- a/html/pages/pseudowires.inc.php
+++ b/html/pages/pseudowires.inc.php
@@ -24,21 +24,21 @@ print_optionbar_end();
echo("");
-foreach (dbFetchRows("SELECT * FROM pseudowires AS P, ports AS I, devices AS D WHERE P.interface_id = I.interface_id AND I.device_id = D.device_id ORDER BY D.hostname,I.ifDescr") as $pw_a)
+foreach (dbFetchRows("SELECT * FROM pseudowires AS P, ports AS I, devices AS D WHERE P.port_id = I.port_id AND I.device_id = D.device_id ORDER BY D.hostname,I.ifDescr") as $pw_a)
{
$i = 0;
while ($i < count($linkdone))
{
- $thislink = $pw_a['device_id'] . $pw_a['interface_id'];
+ $thislink = $pw_a['device_id'] . $pw_a['port_id'];
if ($linkdone[$i] == $thislink) { $skip = "yes"; }
$i++;
}
$pw_b = dbFetchRow("SELECT * from `devices` AS D, `ports` AS I, `pseudowires` AS P WHERE D.device_id = ? AND D.device_id = I.device_id
- AND P.cpwVcID = ? AND P.interface_id = I.interface_id", array($pw_a['peer_device_id'], $pw_a['cpwVcID']));
+ AND P.cpwVcID = ? AND P.port_id = I.port_id", array($pw_a['peer_device_id'], $pw_a['cpwVcID']));
- if (!port_permitted($pw_a['interface_id'])) { $skip = "yes"; }
- if (!port_permitted($pw_b['interface_id'])) { $skip = "yes"; }
+ if (!port_permitted($pw_a['port_id'])) { $skip = "yes"; }
+ if (!port_permitted($pw_b['port_id'])) { $skip = "yes"; }
if ($skip)
{
@@ -88,7 +88,7 @@ foreach (dbFetchRows("SELECT * FROM pseudowires AS P, ports AS I, devices AS D W
echo("");
}
- $linkdone[] = $pw_b['device_id'] . $pw_b['interface_id'];
+ $linkdone[] = $pw_b['device_id'] . $pw_b['port_id'];
}
}
diff --git a/html/pages/purgeports.inc.php b/html/pages/purgeports.inc.php
index 200bfd8db..3bd98e20e 100644
--- a/html/pages/purgeports.inc.php
+++ b/html/pages/purgeports.inc.php
@@ -2,8 +2,8 @@
foreach (dbFetchRows("SELECT * FROM `ports` WHERE `deleted` = '1'") as $port)
{
- echo("Deleting port " . $port['interface_id'] . " - " . $port['ifDescr']);
- delete_port($port['interface_id']);
+ echo(" Deleting port " . $port['port_id'] . " - " . $port['ifDescr']);
+ delete_port($port['port_id']);
echo(" ");
}
diff --git a/html/pages/routing/bgp.inc.php b/html/pages/routing/bgp.inc.php
index 89c589dba..719930bd7 100644
--- a/html/pages/routing/bgp.inc.php
+++ b/html/pages/routing/bgp.inc.php
@@ -160,7 +160,7 @@ else
if ($peer['bgpPeerRemoteAS'] >= '64512' && $peer['bgpPeerRemoteAS'] <= '65535') { $peer_type = " Priv eBGP"; }
}
- $peerhost = dbFetchRow("SELECT * FROM ipaddr AS A, ports AS I, devices AS D WHERE A.addr = ? AND I.interface_id = A.interface_id AND D.device_id = I.device_id", array($peer['bgpPeerIdentifier']));
+ $peerhost = dbFetchRow("SELECT * FROM ipaddr AS A, ports AS I, devices AS D WHERE A.addr = ? AND I.port_id = A.port_id AND D.device_id = I.device_id", array($peer['bgpPeerIdentifier']));
if ($peerhost) { $peername = generate_device_link($peerhost, shorthost($peerhost['hostname'])); } else { unset($peername); }
@@ -219,7 +219,7 @@ else
{
case 'macaccounting_bits':
case 'macaccounting_pkts':
- $acc = dbFetchRow("SELECT * FROM `ipv4_mac` AS I, `mac_accounting` AS M, `ports` AS P, `devices` AS D WHERE I.ipv4_address = ? AND M.mac = I.mac_address AND P.interface_id = M.interface_id AND D.device_id = P.device_id", array($peer['bgpPeerIdentifier']));
+ $acc = dbFetchRow("SELECT * FROM `ipv4_mac` AS I, `mac_accounting` AS M, `ports` AS P, `devices` AS D WHERE I.ipv4_address = ? AND M.mac = I.mac_address AND P.port_id = M.port_id AND D.device_id = P.device_id", array($peer['bgpPeerIdentifier']));
$database = $config['rrd_dir'] . "/" . $device['hostname'] . "/cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd";
if (is_array($acc) && is_file($database))
{
diff --git a/html/pages/routing/ospf.inc.php b/html/pages/routing/ospf.inc.php
index b8b8c4023..dacf7362e 100644
--- a/html/pages/routing/ospf.inc.php
+++ b/html/pages/routing/ospf.inc.php
@@ -19,7 +19,7 @@ foreach (dbFetchRows("SELECT * FROM `ospf_instances` WHERE `ospfAdminStat` = 'en
$neighbour_count = dbFetchCell("SELECT COUNT(*) FROM `ospf_nbrs` WHERE `device_id` = '".$device['device_id']."'");
$ip_query = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE ";
- $ip_query .= "(A.ipv4_address = ? AND I.interface_id = A.interface_id)";
+ $ip_query .= "(A.ipv4_address = ? AND I.port_id = A.port_id)";
$ip_query .= " AND I.device_id = ?";
$ipv4_host = dbFetchRow($ip_query, array($peer['bgpPeerIdentifier'], $device['device_id']));
diff --git a/html/pages/routing/vrf.inc.php b/html/pages/routing/vrf.inc.php
index 3adfca948..5d0e10a67 100644
--- a/html/pages/routing/vrf.inc.php
+++ b/html/pages/routing/vrf.inc.php
@@ -49,7 +49,7 @@ if($_GET['optb'] == "all" ) {
// Specifying the fields reduces a lot the RAM used (1:4) .
$vrf_fields = "vrf_id, mplsVpnVrfRouteDistinguisher, mplsVpnVrfDescription, vrf_name";
$dev_fields = "D.device_id as device_id, hostname, os, hardware, version, features, location, status, `ignore`, disabled";
- $port_fields = "interface_id, ifvrf, device_id, ifDescr, ifAlias, ifName";
+ $port_fields = "port_id, ifvrf, device_id, ifDescr, ifAlias, ifName";
foreach (dbFetchRows("SELECT $vrf_fields, $dev_fields FROM `vrfs` AS V, `devices` AS D WHERE D.device_id = V.device_id") as $vrf_device)
{
diff --git a/html/pages/search/arp.inc.php b/html/pages/search/arp.inc.php
index 38b64e504..29649df74 100644
--- a/html/pages/search/arp.inc.php
+++ b/html/pages/search/arp.inc.php
@@ -9,7 +9,7 @@
');
-$query = "SELECT * FROM `ipv4_mac` AS M, `ports` AS P, `devices` AS D WHERE M.interface_id = P.interface_id AND P.device_id = D.device_id ";
+$query = "SELECT * FROM `ipv4_mac` AS M, `ports` AS P, `devices` AS D WHERE M.port_id = P.port_id AND P.device_id = D.device_id ";
if (isset($_POST['searchby']) && $_POST['searchby'] == "ip")
{
$query .= " AND `ipv4_address` LIKE ?";
@@ -71,11 +71,11 @@ foreach (dbFetchRows($query, $param) as $entry)
$error_img = generate_port_link($entry,"  ",errors);
} else { $error_img = ""; }
- $arp_host = dbFetchRow("SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE A.ipv4_address = ? AND I.interface_id = A.interface_id AND D.device_id = I.device_id", array($entry['ipv4_address']));
+ $arp_host = dbFetchRow("SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id", array($entry['ipv4_address']));
if ($arp_host) { $arp_name = generate_device_link($arp_host); } else { unset($arp_name); }
if ($arp_host) { $arp_if = generate_port_link($arp_host); } else { unset($arp_if); }
if ($arp_host['device_id'] == $entry['device_id']) { $arp_name = "Localhost"; }
- if ($arp_host['interface_id'] == $entry['interface_id']) { $arp_if = "Local port"; }
+ if ($arp_host['port_id'] == $entry['port_id']) { $arp_if = "Local port"; }
echo('
| ' . formatMac($entry['mac_address']) . ' |
diff --git a/html/pages/search/ipv4.inc.php b/html/pages/search/ipv4.inc.php
index e8db87fda..ff9cdd87d 100644
--- a/html/pages/search/ipv4.inc.php
+++ b/html/pages/search/ipv4.inc.php
@@ -39,7 +39,7 @@ print_optionbar_end();
echo('');
-$query = "SELECT * FROM `ipv4_addresses` AS A, `ports` AS I, `devices` AS D, `ipv4_networks` AS N WHERE I.interface_id = A.interface_id AND I.device_id = D.device_id AND N.ipv4_network_id = A.ipv4_network_id ";
+$query = "SELECT * FROM `ipv4_addresses` AS A, `ports` AS I, `devices` AS D, `ipv4_networks` AS N WHERE I.port_id = A.port_id AND I.device_id = D.device_id AND N.ipv4_network_id = A.ipv4_network_id ";
if (is_numeric($_POST['device_id']))
{
@@ -76,7 +76,7 @@ foreach (dbFetchRows($query, $param) as $interface)
$error_img = generate_port_link($interface," ",errors);
} else { $error_img = ""; }
- if (port_permitted($interface['interface_id']))
+ if (port_permitted($interface['port_id']))
{
$interface = ifLabel ($interface, $interface);
diff --git a/html/pages/search/ipv6.inc.php b/html/pages/search/ipv6.inc.php
index 60ec16c4d..1c58dec9e 100644
--- a/html/pages/search/ipv6.inc.php
+++ b/html/pages/search/ipv6.inc.php
@@ -39,7 +39,7 @@ print_optionbar_end();
echo('');
-$query = "SELECT * FROM `ipv6_addresses` AS A, `ports` AS I, `devices` AS D, `ipv6_networks` AS N WHERE I.interface_id = A.interface_id AND I.device_id = D.device_id AND N.ipv6_network_id = A.ipv6_network_id ";
+$query = "SELECT * FROM `ipv6_addresses` AS A, `ports` AS I, `devices` AS D, `ipv6_networks` AS N WHERE I.port_id = A.port_id AND I.device_id = D.device_id AND N.ipv6_network_id = A.ipv6_network_id ";
if (is_numeric($_POST['device_id']))
{
@@ -76,7 +76,7 @@ foreach (dbFetchRows($query, $param) as $interface)
$error_img = generate_port_link($interface," ",errors);
} else { $error_img = ""; }
- if (port_permitted($interface['interface_id']))
+ if (port_permitted($interface['port_id']))
{
$interface = ifLabel ($interface, $interface);
diff --git a/html/pages/search/mac.inc.php b/html/pages/search/mac.inc.php
index 367186e03..0b696c221 100644
--- a/html/pages/search/mac.inc.php
+++ b/html/pages/search/mac.inc.php
@@ -68,7 +68,7 @@ foreach (dbFetchRows($query, $param) as $entry)
$error_img = generate_port_link($entry," ",errors);
} else { $error_img = ""; }
- if (port_permitted($entry['interface_id']))
+ if (port_permitted($entry['port_id']))
{
$interface = ifLabel ($interface, $interface);
diff --git a/includes/common.php b/includes/common.php
index bb039913a..1a049d4c7 100644
--- a/includes/common.php
+++ b/includes/common.php
@@ -77,17 +77,17 @@ function delete_port($int_id)
{
global $config;
- $interface = dbFetchRow("SELECT * FROM `ports` AS P, `devices` AS D WHERE P.interface_id = ? AND D.device_id = P.device_id", array($int_id));
+ $interface = dbFetchRow("SELECT * FROM `ports` AS P, `devices` AS D WHERE P.port_id = ? AND D.device_id = P.device_id", array($int_id));
$interface_tables = array('adjacencies', 'ipaddr', 'ip6adjacencies', 'ip6addr', 'mac_accounting', 'bill_ports', 'pseudowires', 'ports');
foreach ($interface_tables as $table)
{
- dbDelete($table, "`interface_id` = ?", array($int_id));
+ dbDelete($table, "`port_id` = ?", array($int_id));
}
- dbDelete('links', "`local_interface_id` = ?", array($int_id));
- dbDelete('links', "`remote_interface_id` = ?", array($int_id));
+ dbDelete('links', "`local_port_id` = ?", array($int_id));
+ dbDelete('links', "`remote_port_id` = ?", array($int_id));
dbDelete('bill_ports', "`port_id` = ?", array($int_id));
unlink(trim($config['rrd_dir'])."/".trim($interface['hostname'])."/port-".$interface['ifIndex'].".rrd");
@@ -164,23 +164,41 @@ function get_all_devices($device, $type = "")
function port_by_id_cache($port_id)
{
- global $port_cache;
+ return get_port_by_id_cache('port', $port_id);
+}
- if (isset($port_cache[$port_id]) && is_array($port_cache[$device_id]))
+function table_from_entity_type($type)
+{
+ /// Fuck you, english pluralisation.
+ if($type == "storage")
{
- $port = $port_cache[$port_id];
+ return $type;
} else {
- $port = dbFetchRow("SELECT * FROM `ports` WHERE `interface_id` = ?", array($port_id));
- $port_cache[$port_id] = $port;
+ return $type."s";
}
- return $port;
+}
+
+function get_entity_by_id_cache($type, $id)
+{
+ global $entity_cache;
+
+ $table = table_from_entity_type($type);
+
+ if (is_array($entity_cache[$type][$id]))
+ {
+ $entity = $entity_cache[$type][$id];
+ } else {
+ $entity = dbFetchRow("SELECT * FROM `".$table."` WHERE `".$type."_id` = ?", array($port_id));
+ $entity_cache[$type][$id] = $entity;
+ }
+ return $entity;
}
function get_port_by_id($port_id)
{
if (is_numeric($port_id))
{
- $port = dbFetchRow("SELECT * FROM `ports` WHERE `interface_id` = ?", array($port_id));
+ $port = dbFetchRow("SELECT * FROM `ports` WHERE `port_id` = ?", array($port_id));
}
if (is_array($port))
{
@@ -218,11 +236,11 @@ function get_sensor_by_id($sensor_id)
}
}
-function get_device_id_by_interface_id($interface_id)
+function get_device_id_by_port_id($port_id)
{
- if (is_numeric($interface_id))
+ if (is_numeric($port_id))
{
- $device_id = dbFetchCell("SELECT `device_id` FROM `ports` WHERE `interface_id` = ?", array($interface_id));
+ $device_id = dbFetchCell("SELECT `device_id` FROM `ports` WHERE `port_id` = ?", array($port_id));
}
if (is_numeric($device_id))
{
@@ -294,7 +312,7 @@ function mres($string)
function getifhost($id)
{
- return dbFetchCell("SELECT `device_id` from `ports` WHERE `interface_id` = ?", array($id));
+ return dbFetchCell("SELECT `device_id` from `ports` WHERE `port_id` = ?", array($id));
}
function gethostbyid($id)
@@ -337,17 +355,17 @@ function getpeerhost($id)
function getifindexbyid($id)
{
- return dbFetchCell("SELECT `ifIndex` FROM `ports` WHERE `interface_id` = ?", array($id));
+ return dbFetchCell("SELECT `ifIndex` FROM `ports` WHERE `port_id` = ?", array($id));
}
function getifbyid($id)
{
- return dbFetchRow("SELECT * FROM `ports` WHERE `interface_id` = ?", array($id));
+ return dbFetchRow("SELECT * FROM `ports` WHERE `port_id` = ?", array($id));
}
function getifdescrbyid($id)
{
- return dbFetchCell("SELECT `ifDescr` FROM `ports` WHERE `interface_id` = ?", array($id));
+ return dbFetchCell("SELECT `ifDescr` FROM `ports` WHERE `port_id` = ?", array($id));
}
function getidbyname($hostname)
diff --git a/includes/discovery/arp-table.inc.php b/includes/discovery/arp-table.inc.php
index 014f0c0d1..82048d7f9 100644
--- a/includes/discovery/arp-table.inc.php
+++ b/includes/discovery/arp-table.inc.php
@@ -26,18 +26,18 @@ foreach (explode("\n", $ipNetToMedia_data) as $data)
$mac_table[$if][$mac]['ciscomac'] = "$m_a$m_b.$m_c$m_d.$m_e$m_f";
$clean_mac = $m_a . $m_b . $m_c . $m_d . $m_e . $m_f;
$mac_table[$if][$mac]['cleanmac'] = $clean_mac;
- $interface_id = $interface['interface_id'];
- $mac_table[$interface_id][$clean_mac] = 1;
+ $port_id = $interface['port_id'];
+ $mac_table[$port_id][$clean_mac] = 1;
- if (mysql_result(mysql_query("SELECT COUNT(*) from ipv4_mac WHERE interface_id = '".$interface['interface_id']."' AND ipv4_address = '$ip'"),0))
+ if (mysql_result(mysql_query("SELECT COUNT(*) from ipv4_mac WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'"),0))
{
- $sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE interface_id = '".$interface['interface_id']."' AND ipv4_address = '$ip'";
- $old_mac = mysql_fetch_row(mysql_query("SELECT mac_address from ipv4_mac WHERE ipv4_address='$ip' AND interface_id = '".$interface['interface_id']."'"));
+ $sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'";
+ $old_mac = mysql_fetch_row(mysql_query("SELECT mac_address from ipv4_mac WHERE ipv4_address='$ip' AND port_id = '".$interface['port_id']."'"));
if ($clean_mac != $old_mac[0] && $clean_mac != '' && $old_mac[0] != '')
{
if ($debug) { echo("Changed mac address for $ip from $old_mac[0] to $clean_mac\n"); }
- log_event("MAC change: $ip : " . mac_clean_to_readable($old_mac[0]) . " -> " . mac_clean_to_readable($clean_mac), $device, "interface", $interface['interface_id']);
+ log_event("MAC change: $ip : " . mac_clean_to_readable($old_mac[0]) . " -> " . mac_clean_to_readable($clean_mac), $device, "interface", $interface['port_id']);
}
mysql_query($sql);
echo(".");
@@ -46,20 +46,20 @@ foreach (explode("\n", $ipNetToMedia_data) as $data)
{
echo("+");
#echo("Add MAC $mac\n");
- mysql_query("INSERT INTO `ipv4_mac` (interface_id, mac_address, ipv4_address) VALUES ('".$interface['interface_id']."','$clean_mac','$ip')");
+ mysql_query("INSERT INTO `ipv4_mac` (port_id, mac_address, ipv4_address) VALUES ('".$interface['port_id']."','$clean_mac','$ip')");
}
}
}
-$sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.interface_id = I.interface_id and I.device_id = '".$device['device_id']."'";
+$sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = '".$device['device_id']."'";
$query = mysql_query($sql);
while ($entry = mysql_fetch_assoc($query))
{
$entry_mac = $entry['mac_address'];
- $entry_if = $entry['interface_id'];
+ $entry_if = $entry['port_id'];
if (!$mac_table[$entry_if][$entry_mac])
{
- mysql_query("DELETE FROM ipv4_mac WHERE interface_id = '".$entry_if."' AND mac_address = '".$entry_mac."'");
+ mysql_query("DELETE FROM ipv4_mac WHERE port_id = '".$entry_if."' AND mac_address = '".$entry_mac."'");
if ($debug) { echo("Removing MAC $entry_mac from interface ".$interface['ifName']); }
echo("-");
}
diff --git a/includes/discovery/cisco-mac-accounting.inc.php b/includes/discovery/cisco-mac-accounting.inc.php
index dd4a13d19..4298d6a2e 100755
--- a/includes/discovery/cisco-mac-accounting.inc.php
+++ b/includes/discovery/cisco-mac-accounting.inc.php
@@ -28,15 +28,15 @@ if ($device['os_group'] == "cisco")
if ($ip && $interface) {
$new_mac = str_replace(":", "", $mac);
#echo($interface['ifDescr'] . " ($if) -> $mac ($oid) -> $ip");
- if (mysql_result(mysql_query("SELECT COUNT(*) from mac_accounting WHERE interface_id = '".$interface['interface_id']."' AND mac = '$clean_mac'"),0)) {
- #$sql = "UPDATE `mac_accounting` SET `mac` = '$clean_mac' WHERE interface_id = '".$interface['interface_id']."' AND `mac` = '$clean_mac'";
+ if (mysql_result(mysql_query("SELECT COUNT(*) from mac_accounting WHERE port_id = '".$interface['port_id']."' AND mac = '$clean_mac'"),0)) {
+ #$sql = "UPDATE `mac_accounting` SET `mac` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND `mac` = '$clean_mac'";
#mysql_query($sql);
#if (mysql_affected_rows()) { echo(" UPDATED!"); }
#echo($sql);
echo(".");
} else {
#echo(" Not Exists!");
- mysql_query("INSERT INTO `mac_accounting` (interface_id, mac) VALUES ('".$interface['interface_id']."','$clean_mac')");
+ mysql_query("INSERT INTO `mac_accounting` (port_id, mac) VALUES ('".$interface['port_id']."','$clean_mac')");
echo("+");
}
#echo("\n");
diff --git a/includes/discovery/cisco-pw.inc.php b/includes/discovery/cisco-pw.inc.php
index 72f9f2381..07cce92ab 100755
--- a/includes/discovery/cisco-pw.inc.php
+++ b/includes/discovery/cisco-pw.inc.php
@@ -27,8 +27,8 @@ if ($config['enable_pseudowires'] && $device['os_group'] == "cisco")
foreach ($pws as $pw_id => $pw)
{
list($cpw_remote_id) = explode(":", $pw['cpwVcMplsPeerLdpID']);
- $cpw_remote_device = @mysql_result(mysql_query("SELECT device_id FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = '".$cpw_remote_id."' AND A.interface_id = I.interface_id"),0);
- $if_id = @mysql_result(mysql_query("SELECT `interface_id` FROM `ports` WHERE `ifDescr` = '".$pw['cpwVcName']."' AND `device_id` = '".$device['device_id']."'"),0);
+ $cpw_remote_device = @mysql_result(mysql_query("SELECT device_id FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = '".$cpw_remote_id."' AND A.port_id = I.port_id"),0);
+ $if_id = @mysql_result(mysql_query("SELECT `port_id` FROM `ports` WHERE `ifDescr` = '".$pw['cpwVcName']."' AND `device_id` = '".$device['device_id']."'"),0);
if (!empty($device['pws_db'][$pw['cpwVcID']]))
{
@@ -37,7 +37,7 @@ if ($config['enable_pseudowires'] && $device['os_group'] == "cisco")
}
else
{
- $pseudowire_id = dbInsert(array('device_id' => $device['device_id'], 'interface_id' => $if_id, 'peer_device_id' => $cpw_remote_device, 'peer_ldp_id' => $cpw_remote_id,
+ $pseudowire_id = dbInsert(array('device_id' => $device['device_id'], 'port_id' => $if_id, 'peer_device_id' => $cpw_remote_device, 'peer_ldp_id' => $cpw_remote_id,
'cpwVcID' => $pw['cpwVcID'], 'cpwOid' => $pw_id, 'pw_type' => $pw['cpwVcType'], 'pw_descr' => $pw['cpwVcDescr'], 'pw_psntype' => $pw['cpwVcPsnType']), 'pseudowires');
echo("+");
}
diff --git a/includes/discovery/cisco-vrf.inc.php b/includes/discovery/cisco-vrf.inc.php
index 36113c491..f4e191ba8 100755
--- a/includes/discovery/cisco-vrf.inc.php
+++ b/includes/discovery/cisco-vrf.inc.php
@@ -112,8 +112,8 @@ if ($config['enable_vrfs'])
{
$interface = mysql_fetch_assoc(mysql_query("SELECT * FROM ports WHERE ifIndex = '$if_id' AND device_id = '" . $device['device_id'] . "'"));
echo(makeshortif($interface['ifDescr']) . " ");
- mysql_query("UPDATE ports SET ifVrf = '$vrf_id' WHERE interface_id = '".$interface['interface_id']."'");
- $if = $interface['interface_id'];
+ mysql_query("UPDATE ports SET ifVrf = '$vrf_id' WHERE port_id = '".$interface['port_id']."'");
+ $if = $interface['port_id'];
$valid_vrf_if[$vrf_id][$if] = 1;
}
}
@@ -125,14 +125,14 @@ if ($config['enable_vrfs'])
$data = mysql_query($sql);
while ($row = mysql_fetch_assoc($data))
{
- $if = $row['interface_id'];
+ $if = $row['port_id'];
$vrf_id = $row['ifVrf'];
if ($row['ifVrf'])
{
if (!$valid_vrf_if[$vrf_id][$if])
{
echo("-");
- $query = @mysql_query("UPDATE ports SET `ifVrf` = NULL WHERE interface_id = '$if'");
+ $query = @mysql_query("UPDATE ports SET `ifVrf` = NULL WHERE port_id = '$if'");
}
else
{
diff --git a/includes/discovery/discovery-protocols.inc.php b/includes/discovery/discovery-protocols.inc.php
index 870e98c09..194eb15d7 100755
--- a/includes/discovery/discovery-protocols.inc.php
+++ b/includes/discovery/discovery-protocols.inc.php
@@ -28,17 +28,17 @@ if ($device['os'] == "ironware")
if ($remote_device_id)
{
$int = ifNameDescr($interface);
- log_event("Device autodiscovered through FDP on " . $device['hostname'] . " (port " . $int['label'] . ")", $remote_device_id, 'interface', $int['interface_id']);
+ log_event("Device autodiscovered through FDP on " . $device['hostname'] . " (port " . $int['label'] . ")", $remote_device_id, 'interface', $int['port_id']);
}
}
if ($remote_device_id)
{
$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"; }
+ $remote_port_id = @mysql_result(mysql_query("SELECT port_id FROM `ports` WHERE (`ifDescr` = '$if' OR `ifName`='$if') AND `device_id` = '".$remote_device_id."'"),0);
+ } else { $remote_port_id = "0"; }
- discover_link($interface['interface_id'], $fdp['snFdpCacheVendorId'], $remote_interface_id, $fdp['snFdpCacheDeviceId'], $fdp['snFdpCacheDevicePort'], $fdp['snFdpCachePlatform'], $fdp['snFdpCacheVersion']);
+ discover_link($interface['port_id'], $fdp['snFdpCacheVendorId'], $remote_port_id, $fdp['snFdpCacheDeviceId'], $fdp['snFdpCacheDevicePort'], $fdp['snFdpCachePlatform'], $fdp['snFdpCacheVersion']);
}
}
}
@@ -67,19 +67,19 @@ if ($cdp_array)
if ($remote_device_id)
{
$int = ifNameDescr($interface);
- log_event("Device autodiscovered through CDP on " . $device['hostname'] . " (port " . $int['label'] . ")", $remote_device_id, 'interface', $int['interface_id']);
+ log_event("Device autodiscovered through CDP on " . $device['hostname'] . " (port " . $int['label'] . ")", $remote_device_id, 'interface', $int['port_id']);
}
}
if ($remote_device_id)
{
$if = $cdp['cdpCacheDevicePort'];
- $remote_interface_id = dbFetchCell("SELECT interface_id FROM `ports` WHERE (`ifDescr` = ? OR `ifName` = ?) AND `device_id` = ?", array($if, $if, $remote_device_id));
- } else { $remote_interface_id = "0"; }
+ $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"; }
- if ($interface['interface_id'] && $cdp['cdpCacheDeviceId'] && $cdp['cdpCacheDevicePort'])
+ if ($interface['port_id'] && $cdp['cdpCacheDeviceId'] && $cdp['cdpCacheDevicePort'])
{
- discover_link($interface['interface_id'], 'cdp', $remote_interface_id, $cdp['cdpCacheDeviceId'], $cdp['cdpCacheDevicePort'], $cdp['cdpCachePlatform'], $cdp['cdpCacheVersion']);
+ discover_link($interface['port_id'], 'cdp', $remote_port_id, $cdp['cdpCacheDeviceId'], $cdp['cdpCacheDevicePort'], $cdp['cdpCachePlatform'], $cdp['cdpCacheVersion']);
}
}
else
@@ -123,21 +123,21 @@ if ($lldp_array)
if ($remote_device_id)
{
$int = ifNameDescr($interface);
- log_event("Device autodiscovered through LLDP on " . $device['hostname'] . " (port " . $int['label'] . ")", $remote_device_id, 'interface', $int['interface_id']);
+ log_event("Device autodiscovered through LLDP on " . $device['hostname'] . " (port " . $int['label'] . ")", $remote_device_id, 'interface', $int['port_id']);
}
}
if ($remote_device_id)
{
$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);
+ $remote_port_id = @mysql_result(mysql_query("SELECT port_id FROM `ports` WHERE (`ifDescr` = '$if' OR `ifName`='$if' OR `ifDescr`= '$id' OR `ifName`='$id') AND `device_id` = '".$remote_device_id."'"),0);
} else {
- $remote_interface_id = "0";
+ $remote_port_id = "0";
}
- if (is_numeric($interface['interface_id']) && isset($lldp['lldpRemSysName']) && isset($lldp['lldpRemPortId']))
+ if (is_numeric($interface['port_id']) && isset($lldp['lldpRemSysName']) && isset($lldp['lldpRemPortId']))
{
- discover_link($interface['interface_id'], 'lldp', $remote_interface_id, $lldp['lldpRemSysName'], $lldp['lldpRemPortId'], NULL, $lldp['lldpRemSysDesc']);
+ discover_link($interface['port_id'], 'lldp', $remote_port_id, $lldp['lldpRemSysName'], $lldp['lldpRemPortId'], NULL, $lldp['lldpRemSysDesc']);
}
}
}
@@ -146,16 +146,16 @@ if ($lldp_array)
if ($debug) { print_r($link_exists); }
-$sql = "SELECT * FROM `links` AS L, `ports` AS I WHERE L.local_interface_id = I.interface_id AND I.device_id = '".$device['device_id']."'";
+$sql = "SELECT * FROM `links` AS L, `ports` AS I WHERE L.local_port_id = I.port_id AND I.device_id = '".$device['device_id']."'";
if ($query = mysql_query($sql))
{
while ($test = mysql_fetch_assoc($query))
{
- $local_interface_id = $test['local_interface_id'];
+ $local_port_id = $test['local_port_id'];
$remote_hostname = $test['remote_hostname'];
$remote_port = $test['remote_port'];
- if ($debug) { echo("$local_interface_id -> $remote_hostname -> $remote_port \n"); }
- if (!$link_exists[$local_interface_id][$remote_hostname][$remote_port])
+ if ($debug) { echo("$local_port_id -> $remote_hostname -> $remote_port \n"); }
+ if (!$link_exists[$local_port_id][$remote_hostname][$remote_port])
{
echo("-");
mysql_query("DELETE FROM `links` WHERE id = '" . $test['id'] . "'");
diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php
index 7c07c4359..e176d864f 100644
--- a/includes/discovery/functions.inc.php
+++ b/includes/discovery/functions.inc.php
@@ -336,51 +336,51 @@ function check_valid_sensors($device, $class, $valid)
}
}
-function discover_juniAtmVp(&$valid, $interface_id, $vp_id, $vp_descr)
+function discover_juniAtmVp(&$valid, $port_id, $vp_id, $vp_descr)
{
global $config, $debug;
- if (dbFetchCell("SELECT COUNT(*) FROM `juniAtmVp` WHERE `interface_id` = ? AND `vp_id` = ?", array($interface_id, $vp_id)) == "0")
+ if (dbFetchCell("SELECT COUNT(*) FROM `juniAtmVp` WHERE `port_id` = ? AND `vp_id` = ?", array($port_id, $vp_id)) == "0")
{
- $inserted = dbInsert(array('interface_id' => $interface_id,'vp_id' => $vp_id,'vp_descr' => $vp_descr), 'juniAtmVp');
+ $inserted = dbInsert(array('port_id' => $port_id,'vp_id' => $vp_id,'vp_descr' => $vp_descr), 'juniAtmVp');
if ($debug) { echo("( $inserted inserted )\n"); }
#FIXME vv no $device!
- log_event("Juniper ATM VP Added: port ".mres($interface_id)." vp ".mres($vp_id)." descr". mres($vp_descr), 'juniAtmVp', mysql_insert_id());
+ log_event("Juniper ATM VP Added: port ".mres($port_id)." vp ".mres($vp_id)." descr". mres($vp_descr), 'juniAtmVp', mysql_insert_id());
}
else
{
echo(".");
}
- $valid[$interface_id][$vp_id] = 1;
+ $valid[$port_id][$vp_id] = 1;
}
-function discover_link($local_interface_id, $protocol, $remote_interface_id, $remote_hostname, $remote_port, $remote_platform, $remote_version)
+function discover_link($local_port_id, $protocol, $remote_port_id, $remote_hostname, $remote_port, $remote_platform, $remote_version)
{
global $config, $debug, $link_exists;
- if (dbFetchCell("SELECT COUNT(*) FROM `links` WHERE `remote_hostname` = ? AND `local_interface_id` = ? AND `protocol` = ? AND `remote_port` = ?",
- array($remote_hostname, $local_interface_id, $protocol, $remote_port)) == "0")
+ if (dbFetchCell("SELECT COUNT(*) FROM `links` WHERE `remote_hostname` = ? AND `local_port_id` = ? AND `protocol` = ? AND `remote_port` = ?",
+ array($remote_hostname, $local_port_id, $protocol, $remote_port)) == "0")
{
- $inserted = dbInsert(array('local_interface_id' => $local_interface_id,'protocol' => $protocol,'remote_interface_id' => $remote_interface_id,'remote_hostname' => $remote_hostname,
+ $inserted = dbInsert(array('local_port_id' => $local_port_id,'protocol' => $protocol,'remote_port_id' => $remote_port_id,'remote_hostname' => $remote_hostname,
'remote_port' => $remote_port,'remote_platform' => $remote_platform,'remote_version' => $remote_version), 'links');
echo("+"); if ($debug) { echo("( $inserted inserted )"); }
}
else
{
- $data = dbFetchRow("SELECT * FROM `links` WHERE `remote_hostname` = ? AND `local_interface_id` = ? AND `protocol` = ? AND `remote_port` = ?", array($remote_hostname, $local_interface_id, $protocol, $remote_port));
- if ($data['remote_interface_id'] == $remote_interface_id && $data['remote_platform'] == $remote_platform && $remote_version == $remote_version)
+ $data = dbFetchRow("SELECT * FROM `links` WHERE `remote_hostname` = ? AND `local_port_id` = ? AND `protocol` = ? AND `remote_port` = ?", array($remote_hostname, $local_port_id, $protocol, $remote_port));
+ if ($data['remote_port_id'] == $remote_port_id && $data['remote_platform'] == $remote_platform && $remote_version == $remote_version)
{
echo(".");
}
else
{
- $updated = dbUpdate(array('remote_interface_id' => $remote_interface_id, 'remote_platform' => $remote_platform, 'remote_version' => $remote_version), 'links', '`id` = ?', array($data['id']));
+ $updated = dbUpdate(array('remote_port_id' => $remote_port_id, 'remote_platform' => $remote_platform, 'remote_version' => $remote_version), 'links', '`id` = ?', array($data['id']));
echo("U"); if ($debug) { echo("( $updated updated )"); }
}
}
- $link_exists[$local_interface_id][$remote_hostname][$remote_port] = 1;
+ $link_exists[$local_port_id][$remote_hostname][$remote_port] = 1;
}
function discover_storage(&$valid, $device, $index, $type, $mib, $descr, $size, $units, $used = NULL)
@@ -511,8 +511,8 @@ function discover_process_ipv6(&$valid, $ifIndex,$ipv6_address,$ipv6_prefixlen,$
if (mysql_result(mysql_query("SELECT count(*) FROM `ports`
WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1')
{
- $i_query = "SELECT interface_id FROM `ports` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'";
- $interface_id = mysql_result(mysql_query($i_query), 0);
+ $i_query = "SELECT port_id FROM `ports` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'";
+ $port_id = mysql_result(mysql_query($i_query), 0);
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0) < '1')
{
mysql_query("INSERT INTO `ipv6_networks` (`ipv6_network`) VALUES ('$ipv6_network')");
@@ -527,10 +527,10 @@ function discover_process_ipv6(&$valid, $ifIndex,$ipv6_address,$ipv6_prefixlen,$
$ipv6_network_id = @mysql_result(mysql_query("SELECT `ipv6_network_id` from `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0);
- if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = '$ipv6_address' AND `ipv6_prefixlen` = '$ipv6_prefixlen' AND `interface_id` = '$interface_id'"), 0) == '0')
+ if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = '$ipv6_address' AND `ipv6_prefixlen` = '$ipv6_prefixlen' AND `port_id` = '$port_id'"), 0) == '0')
{
- mysql_query("INSERT INTO `ipv6_addresses` (`ipv6_address`, `ipv6_compressed`, `ipv6_prefixlen`, `ipv6_origin`, `ipv6_network_id`, `interface_id`)
- VALUES ('$ipv6_address', '$ipv6_compressed', '$ipv6_prefixlen', '$ipv6_origin', '$ipv6_network_id', '$interface_id')");
+ mysql_query("INSERT INTO `ipv6_addresses` (`ipv6_address`, `ipv6_compressed`, `ipv6_prefixlen`, `ipv6_origin`, `ipv6_network_id`, `port_id`)
+ VALUES ('$ipv6_address', '$ipv6_compressed', '$ipv6_prefixlen', '$ipv6_origin', '$ipv6_network_id', '$port_id')");
echo("+");
}
else
@@ -538,7 +538,7 @@ function discover_process_ipv6(&$valid, $ifIndex,$ipv6_address,$ipv6_prefixlen,$
echo(".");
}
$full_address = "$ipv6_address/$ipv6_prefixlen";
- $valid_address = $full_address . "-" . $interface_id;
+ $valid_address = $full_address . "-" . $port_id;
$valid['ipv6'][$valid_address] = 1;
}
}
diff --git a/includes/discovery/ipv4-addresses.inc.php b/includes/discovery/ipv4-addresses.inc.php
index 887b082cc..5f66b350a 100755
--- a/includes/discovery/ipv4-addresses.inc.php
+++ b/includes/discovery/ipv4-addresses.inc.php
@@ -15,8 +15,8 @@ foreach (explode("\n", $oids) as $data)
if (mysql_result(mysql_query("SELECT count(*) FROM `ports` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0' && $oid != "0.0.0.0" && $oid != 'ipAdEntIfIndex')
{
- $i_query = "SELECT interface_id FROM `ports` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'";
- $interface_id = mysql_result(mysql_query($i_query), 0);
+ $i_query = "SELECT port_id FROM `ports` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'";
+ $port_id = mysql_result(mysql_query($i_query), 0);
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv4_networks` WHERE `ipv4_network` = '$network'"), 0) < '1')
{
@@ -27,10 +27,10 @@ foreach (explode("\n", $oids) as $data)
$ipv4_network_id = @mysql_result(mysql_query("SELECT `ipv4_network_id` from `ipv4_networks` WHERE `ipv4_network` = '$network'"), 0);
- if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = '$oid' AND `ipv4_prefixlen` = '$cidr' AND `interface_id` = '$interface_id'"), 0) == '0')
+ if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = '$oid' AND `ipv4_prefixlen` = '$cidr' AND `port_id` = '$port_id'"), 0) == '0')
{
- mysql_query("INSERT INTO `ipv4_addresses` (`ipv4_address`, `ipv4_prefixlen`, `ipv4_network_id`, `interface_id`) VALUES ('$oid', '$cidr', '$ipv4_network_id', '$interface_id')");
- #echo("Added $oid/$cidr to $interface_id ( $hostname $ifIndex )\n $i_query\n");
+ mysql_query("INSERT INTO `ipv4_addresses` (`ipv4_address`, `ipv4_prefixlen`, `ipv4_network_id`, `port_id`) VALUES ('$oid', '$cidr', '$ipv4_network_id', '$port_id')");
+ #echo("Added $oid/$cidr to $port_id ( $hostname $ifIndex )\n $i_query\n");
echo("+");
} else { echo("."); }
@@ -39,7 +39,7 @@ foreach (explode("\n", $oids) as $data)
} else { echo("!"); }
}
-$sql = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.interface_id = I.interface_id";
+$sql = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id";
$data = mysql_query($sql);
while ($row = mysql_fetch_assoc($data))
diff --git a/includes/discovery/ipv6-addresses.inc.php b/includes/discovery/ipv6-addresses.inc.php
index df59c6a73..21af273de 100644
--- a/includes/discovery/ipv6-addresses.inc.php
+++ b/includes/discovery/ipv6-addresses.inc.php
@@ -58,14 +58,14 @@ if (!$oids)
} // foreach
} // if $oids
-$sql = "SELECT * FROM ipv6_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.interface_id = I.interface_id";
+$sql = "SELECT * FROM ipv6_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id";
$data = mysql_query($sql);
while ($row = mysql_fetch_assoc($data))
{
$full_address = $row['ipv6_address'] . "/" . $row['ipv6_prefixlen'];
- $interface_id = $row['interface_id'];
- $valid_address = $full_address . "-" . $interface_id;
+ $port_id = $row['port_id'];
+ $valid_address = $full_address . "-" . $port_id;
if (!$valid['ipv6'][$valid_address])
{
echo("-");
diff --git a/includes/discovery/junose-atm-vp.inc.php b/includes/discovery/junose-atm-vp.inc.php
index 3d11e2efe..e6fd07277 100755
--- a/includes/discovery/junose-atm-vp.inc.php
+++ b/includes/discovery/junose-atm-vp.inc.php
@@ -17,11 +17,11 @@ if ($device['os'] == "junose" && $config['enable_ports_junoseatmvp'])
{
list($ifIndex,$vp_id)= explode('.', $index);
- $interface_id = mysql_result(mysql_query("SELECT `interface_id` FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '".$ifIndex."'"),0);
+ $port_id = mysql_result(mysql_query("SELECT `port_id` FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '".$ifIndex."'"),0);
- if (is_numeric($interface_id) && is_numeric($vp_id))
+ if (is_numeric($port_id) && is_numeric($vp_id))
{
- discover_juniAtmvp($valid_vp, $interface_id, $vp_id, NULL);
+ discover_juniAtmvp($valid_vp, $port_id, $vp_id, NULL);
}
} ## End Foreach
} ## End if array
@@ -30,23 +30,23 @@ if ($device['os'] == "junose" && $config['enable_ports_junoseatmvp'])
## Remove ATM vps which weren't redetected here
- $sql = "SELECT * FROM `ports` AS P, `juniAtmVp` AS J WHERE P.`device_id` = '".$device['device_id']."' AND J.interface_id = P.interface_id";
+ $sql = "SELECT * FROM `ports` AS P, `juniAtmVp` AS J WHERE P.`device_id` = '".$device['device_id']."' AND J.port_id = P.port_id";
$query = mysql_query($sql);
if ($debug) { print_r ($valid_vp); }
while ($test = mysql_fetch_assoc($query))
{
- $interface_id = $test['interface_id'];
+ $port_id = $test['port_id'];
$vp_id = $test['vp_id'];
- if ($debug) { echo($interface_id . " -> " . $vp_id . "\n"); }
- if (!$valid_vp[$interface_id][$vp_id])
+ if ($debug) { echo($port_id . " -> " . $vp_id . "\n"); }
+ if (!$valid_vp[$port_id][$vp_id])
{
echo("-");
mysql_query("DELETE FROM `juniAtmvp` WHERE `juniAtmVp` = '" . $test['juniAtmvp'] . "'");
}
- unset($interface_id); unset($vp_id);
+ unset($port_id); unset($vp_id);
}
unset($valid_vp);
diff --git a/includes/discovery/ports-stack.inc.php b/includes/discovery/ports-stack.inc.php
index dd5323943..572c63ec6 100644
--- a/includes/discovery/ports-stack.inc.php
+++ b/includes/discovery/ports-stack.inc.php
@@ -6,41 +6,41 @@ $sql = "SELECT * FROM `ports_stack` WHERE `device_id` = '".$device['device_id'].
$query = mysql_query($sql);
while ($entry = mysql_fetch_assoc($query))
{
- $stack_db_array[$entry['interface_id_high']][$entry['interface_id_low']]['ifStackStatus'] = $entry['ifStackStatus'];
+ $stack_db_array[$entry['port_id_high']][$entry['port_id_low']]['ifStackStatus'] = $entry['ifStackStatus'];
}
$stack_poll_array = snmpwalk_cache_twopart_oid($device, "ifStackStatus", array());
-foreach ($stack_poll_array as $interface_id_high => $entry_high)
+foreach ($stack_poll_array as $port_id_high => $entry_high)
{
- foreach ($entry_high as $interface_id_low => $entry_low)
+ foreach ($entry_high as $port_id_low => $entry_low)
{
$ifStackStatus = $entry_low['ifStackStatus'];
- if (isset($stack_db_array[$interface_id_high][$interface_id_low]))
+ if (isset($stack_db_array[$port_id_high][$port_id_low]))
{
- if ($stack_db_array[$interface_id_high][$interface_id_low]['ifStackStatus'] == $ifStackStatus)
+ if ($stack_db_array[$port_id_high][$port_id_low]['ifStackStatus'] == $ifStackStatus)
{
echo(".");
} else {
- mysql_query("UPDATE `ports_stack` SET `ifStackStatus` = '".$ifStackStatus."' WHERE `device_id` = '".$device['device_id']."' AND `interface_id_high` = '".$interface_id_high."' AND `interface_id_low` = '".$interface_id_low."'");
+ mysql_query("UPDATE `ports_stack` SET `ifStackStatus` = '".$ifStackStatus."' WHERE `device_id` = '".$device['device_id']."' AND `port_id_high` = '".$port_id_high."' AND `port_id_low` = '".$port_id_low."'");
echo("U");
if ($debug) { echo(mysql_error()); }
}
- unset($stack_db_array[$interface_id_high][$interface_id_low]);
+ unset($stack_db_array[$port_id_high][$port_id_low]);
} else {
- mysql_query("INSERT INTO `ports_stack` (`device_id`,`interface_id_high`,`interface_id_low`,`ifStackStatus`) VALUES ('".$device['device_id']."','".$interface_id_high."','".$interface_id_low."','".$ifStackStatus."')");
+ mysql_query("INSERT INTO `ports_stack` (`device_id`,`port_id_high`,`port_id_low`,`ifStackStatus`) VALUES ('".$device['device_id']."','".$port_id_high."','".$port_id_low."','".$ifStackStatus."')");
echo("+");
if ($debug) { echo(mysql_error()); }
}
}
}
-foreach ($stack_db_array AS $interface_id_high => $array)
+foreach ($stack_db_array AS $port_id_high => $array)
{
- foreach ($array AS $interface_id_low => $blah)
+ foreach ($array AS $port_id_low => $blah)
{
- echo($device['device_id']." ".$interface_id_low." ".$interface_id_high. "\n");
- dbDelete('ports_stack', "`device_id` = ? AND interface_id_high = ? AND interface_id_low = ?", array($device['device_id'], $interface_id_high, $interface_id_low));
+ echo($device['device_id']." ".$port_id_low." ".$port_id_high. "\n");
+ dbDelete('ports_stack', "`device_id` = ? AND port_id_high = ? AND port_id_low = ?", array($device['device_id'], $port_id_high, $port_id_low));
echo("-");
}
}
diff --git a/includes/discovery/ports.inc.php b/includes/discovery/ports.inc.php
index d86b4385a..c940194dc 100755
--- a/includes/discovery/ports.inc.php
+++ b/includes/discovery/ports.inc.php
@@ -1,118 +1,11 @@
"0")
-{
- echo("ADSL ");
- $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.1.1", $port_stats, "ADSL-LINE-MIB");
- $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.2.1", $port_stats, "ADSL-LINE-MIB");
- $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.3.1", $port_stats, "ADSL-LINE-MIB");
- $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.4.1", $port_stats, "ADSL-LINE-MIB");
- $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.5.1", $port_stats, "ADSL-LINE-MIB");
- $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.1", $port_stats, "ADSL-LINE-MIB");
- $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.2", $port_stats, "ADSL-LINE-MIB");
- $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.3", $port_stats, "ADSL-LINE-MIB");
- $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.4", $port_stats, "ADSL-LINE-MIB");
- $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.5", $port_stats, "ADSL-LINE-MIB");
- $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.6", $port_stats, "ADSL-LINE-MIB");
- $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.7", $port_stats, "ADSL-LINE-MIB");
- $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.8", $port_stats, "ADSL-LINE-MIB");
- $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.1", $port_stats, "ADSL-LINE-MIB");
- $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.2", $port_stats, "ADSL-LINE-MIB");
- $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.3", $port_stats, "ADSL-LINE-MIB");
- $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.4", $port_stats, "ADSL-LINE-MIB");
- $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.5", $port_stats, "ADSL-LINE-MIB");
- $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.6", $port_stats, "ADSL-LINE-MIB");
- $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.7", $port_stats, "ADSL-LINE-MIB");
-}
-
-/// FIXME This probably needs re-enabled. We need to clear these things when they get unset, too.
-#foreach ($etherlike_oids as $oid) { $port_stats = snmpwalk_cache_oid($device, $oid, $port_stats, "EtherLike-MIB"); }
-#foreach ($cisco_oids as $oid) { $port_stats = snmpwalk_cache_oid($device, $oid, $port_stats, "OLD-CISCO-INTERFACES-MIB"); }
-#foreach ($pagp_oids as $oid) { $port_stats = snmpwalk_cache_oid($device, $oid, $port_stats, "CISCO-PAGP-MIB"); }
-
-if ($device['os_group'] == "cisco")
-{
- $port_stats = snmp_cache_portIfIndex ($device, $port_stats);
- $port_stats = snmp_cache_portName ($device, $port_stats);
- foreach ($pagp_oids as $oid) { $port_stats = snmpwalk_cache_oid($device, $oid, $port_stats, "CISCO-PAGP-MIB"); }
- $data_oids[] = "portName";
-
- /// Grab data to put ports into vlans or make them trunks
- /// FIXME we probably shouldn't be doing this from the VTP MIB, right?
- $port_stats = snmpwalk_cache_oid($device, "vmVlan", $port_stats, "CISCO-VLAN-MEMBERSHIP-MIB");
- $port_stats = snmpwalk_cache_oid($device, "vlanTrunkPortEncapsulationOperType", $port_stats, "CISCO-VTP-MIB");
- $port_stats = snmpwalk_cache_oid($device, "vlanTrunkPortNativeVlan", $port_stats, "CISCO-VTP-MIB");
-
-} else {
- $port_stats = snmpwalk_cache_oid($device, "dot1qPortVlanTable", $port_stats, "Q-BRIDGE-MIB");
-
- $vlan_ports = snmpwalk_cache_twopart_oid($device, "dot1qVlanCurrentEgressPorts", $vlan_stats, "Q-BRIDGE-MIB");
- $vlan_ifindex_map = snmpwalk_cache_oid($device, "dot1dBasePortIfIndex", $vlan_stats, "Q-BRIDGE-MIB");
-
- foreach ($vlan_ports as $instance)
- {
- foreach (array_keys($instance) as $vlan_id)
- {
- $parts = explode(' ',$instance[$vlan_id]['dot1qVlanCurrentEgressPorts']);
- $binary = '';
- foreach ($parts as $part)
- {
- $binary .= zeropad(decbin($part),8);
- }
- for ($i = 0; $i < strlen($binary); $i++)
- {
- if ($binary[$i])
- {
- $ifindex = $i; // FIXME $vlan_ifindex_map[$i]
- $q_bridge_mib[$ifindex][] = $vlan_id;
- }
- }
- }
- }
-}
-
-$polled = time();
+$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");
/// End Building SNMP Cache Array
@@ -127,7 +20,7 @@ if ($debug) { print_r($port_stats); }
foreach (dbFetchRows("SELECT * FROM `ports` WHERE `device_id` = ?", array($device['device_id'])) as $port)
{
$ports_db[$port['ifIndex']] = $port;
- $ports_db_l[$port['ifIndex']] = $port['interface_id'];
+ $ports_db_l[$port['ifIndex']] = $port['port_id'];
}
/// New interface detection
@@ -138,11 +31,11 @@ foreach ($port_stats as $ifIndex => $port)
{
if (!is_array($ports_db[$ifIndex]))
{
- $interface_id = dbInsert(array('device_id' => $device['device_id'], 'ifIndex' => $ifIndex), 'ports');
+ $port_id = dbInsert(array('device_id' => $device['device_id'], 'ifIndex' => $ifIndex), 'ports');
$ports_db[$ifIndex] = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?", array($device['device_id'], $ifIndex));
- echo("Adding: ".$port['ifName']."(".$ifIndex.")(".$ports_db[$port['ifIndex']]['interface_id'].")");
+ echo("Adding: ".$port['ifName']."(".$ifIndex.")(".$ports_db[$port['ifIndex']]['port_id'].")");
} elseif ($ports_db[$ifIndex]['deleted'] == "1") {
- dbUpdate(array('deleted' => '0'), 'ports', '`interface_id` = ?', array($ports_db[$ifIndex]['interface_id']));
+ dbUpdate(array('deleted' => '0'), 'ports', '`port_id` = ?', array($ports_db[$ifIndex]['port_id']));
$ports_db[$ifIndex]['deleted'] = "0";
echo("U");
} else {
@@ -154,7 +47,7 @@ foreach ($port_stats as $ifIndex => $port)
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']));
+ dbUpdate(array('deleted' => '1'), 'ports', '`port_id` = ?', array($ports_db[$ifIndex]['port_id']));
$ports_db[$ifIndex]['deleted'] = "1";
echo("-");
}
@@ -170,313 +63,16 @@ foreach ($ports_l as $ifIndex => $port_id)
{
if ($ports_db[$ifIndex]['deleted'] == "0")
{
- dbUpdate(array('deleted' => '1'), 'ports', '`interface_id` = ?', array($port_id));
+ dbUpdate(array('deleted' => '1'), 'ports', '`port_id` = ?', array($port_id));
echo("-".$ifIndex);
}
}
/// End interface deletion
-
echo("\n");
-/// Loop ports in the DB and update where necessary
-foreach ($ports_db as $port)
-{
- echo("Port " . $port['ifDescr'] . "(".$port['ifIndex'].") ");
- if ($port_stats[$port['ifIndex']] && $port['disabled'] != "1")
- { /// Check to make sure Port data is cached.
- $this_port = &$port_stats[$port['ifIndex']];
-
- if ($device['os'] == "vmware" && preg_match("/Device ([a-z0-9]+) at .*/", $this_port['ifDescr'], $matches)) { $this_port['ifDescr'] = $matches[1]; }
-
- if ($config['memcached']['enable'])
- {
- $port['poll_time'] = $memcache->get('port-'.$port['interface_id'].'-poll_time');
-# echo("time".$port['poll_time']);
- }
-
- $polled_period = $polled - $port['poll_time'];
-
- $port['update'] = array();
- if ($config['slow_statistics'] == TRUE)
- {
- $port['update']['poll_time'] = $polled;
- $port['update']['poll_prev'] = $port['poll_time'];
- $port['update']['poll_period'] = $polled_period;
- }
-
- if ($config['memcached']['enable'])
- {
- $memcache->set('port-'.$port['interface_id'].'-poll_time', $polled);
- $memcache->set('port-'.$port['interface_id'].'-poll_prev', $port['poll_time']);
- $memcache->set('port-'.$port['interface_id'].'-poll_period', $polled_period);
- }
-
- /// Copy ifHC[In|Out]Octets values to non-HC if they exist
- if ($this_port['ifHCInOctets'] > 0 && is_numeric($this_port['ifHCInOctets']) && $this_port['ifHCOutOctets'] > 0 && is_numeric($this_port['ifHCOutOctets']))
- {
- echo("HC ");
- $this_port['ifInOctets'] = $this_port['ifHCInOctets'];
- $this_port['ifOutOctets'] = $this_port['ifHCOutOctets'];
- }
-
- /// rewrite the ifPhysAddress
- if (strpos($this_port['ifPhysAddress'], ":"))
- {
- list($a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode(":", $this_port['ifPhysAddress']);
- $this_port['ifPhysAddress'] = zeropad($a_a).zeropad($a_b).zeropad($a_c).zeropad($a_d).zeropad($a_e).zeropad($a_f);
- }
-
- if (is_numeric($this_port['ifHCInBroadcastPkts']) && is_numeric($this_port['ifHCOutBroadcastPkts']) && is_numeric($this_port['ifHCInMulticastPkts']) && is_numeric($this_port['ifHCOutMulticastPkts']))
- {
- echo("HC ");
- $this_port['ifInBroadcastPkts'] = $this_port['ifHCInBroadcastPkts'];
- $this_port['ifOutBroadcastPkts'] = $this_port['ifHCOutBroadcastPkts'];
- $this_port['ifInMulticastPkts'] = $this_port['ifHCInMulticastPkts'];
- $this_port['ifOutMulticastPkts'] = $this_port['ifHCOutMulticastPkts'];
- }
-
- /// Overwrite ifSpeed with ifHighSpeed if it's over 10G
- if (is_numeric($this_port['ifHighSpeed']) && $this_port['ifSpeed'] > "1000000000")
- {
- echo("HighSpeed ");
- $this_port['ifSpeed'] = $this_port['ifHighSpeed'] * 1000000;
- }
-
- /// Overwrite ifDuplex with dot3StatsDuplexStatus if it exists
- if (isset($this_port['dot3StatsDuplexStatus']))
- {
- echo("dot3Duplex ");
- $this_port['ifDuplex'] = $this_port['dot3StatsDuplexStatus'];
- }
-
- /// Set VLAN and Trunk from Cisco
- if (isset($this_port['vlanTrunkPortEncapsulationOperType']) && $this_port['vlanTrunkPortEncapsulationOperType'] != "notApplicable")
- {
- $this_port['ifTrunk'] = $this_port['vlanTrunkPortEncapsulationOperType'];
- if (isset($this_port['vlanTrunkPortNativeVlan'])) { $this_port['ifVlan'] = $this_port['vlanTrunkPortNativeVlan']; }
- }
-
- if (isset($this_port['vmVlan']))
- {
- $this_port['ifVlan'] = $this_port['vmVlan'];
- }
-
- /// Set VLAN and Trunk from Q-BRIDGE-MIB
- if (!isset($this_port['ifVlan']) && isset($this_port['dot1qPvid']))
- {
- $this_port['ifVlan'] = $this_port['dot1qPvid'];
- }
- # FIXME use $q_bridge_mib[$this_port['ifIndex'] to see if it is a trunk (>1 array count)
-
- echo("VLAN == ".$this_port['ifVlan']);
-
- /// Update IF-MIB data
- foreach ($data_oids as $oid)
- {
- if ($port[$oid] != $this_port[$oid] && !isset($this_port[$oid]))
- {
- $port['update'][$oid] = NULL;
- log_event($oid . ": ".$port[$oid]." -> NULL", $device, 'interface', $port['interface_id']);
- if ($debug) { echo($oid . ": ".$port[$oid]." -> NULL "); } else { echo($oid . " "); }
- } elseif ($port[$oid] != $this_port[$oid]) {
- $port['update'][$oid] = $this_port[$oid];
- log_event($oid . ": ".$port[$oid]." -> " . $this_port[$oid], $device, 'interface', $port['interface_id']);
- if ($debug) { echo($oid . ": ".$port[$oid]." -> " . $this_port[$oid]." "); } else { echo($oid . " "); }
- }
- }
-
- /// Parse description (usually ifAlias) if config option set
- if (isset($config['port_descr_parser']) && is_file($config['install_dir'] . "/" . $config['port_descr_parser']))
- {
- $port_attribs = array('type','descr','circuit','speed','notes');
-
- include($config['install_dir'] . "/" . $config['port_descr_parser']);
-
- foreach ($port_attribs as $attrib)
- {
- $attrib_key = "port_descr_".$attrib;
- if ($port_ifAlias[$attrib] != $port[$attrib_key])
- {
- $port['update'][$attrib_key] = $port_ifAlias[$attrib];
- log_event($attrib . ": ".$port[$attrib_key]." -> " . $port_ifAlias[$attrib], $device, 'interface', $port['interface_id']);
- }
- }
- }
- /// End parse ifAlias
-
- /// Update IF-MIB metrics
- foreach ($stat_oids_db as $oid)
- {
-# echo("\n".$oid.":");
-
- if ($config['slow_statistics'] == TRUE) {
- $port['update'][$oid] = $this_port[$oid];
- $port['update'][$oid.'_prev'] = $port[$oid];
- }
-
- if ($config['memcached']['enable'])
- {
- $port[$oid] = $memcache->get('port-'.$port['interface_id'].'-'.$oid);
- $memcache->set('port-'.$port['interface_id'].'-'.$oid, $this_port[$oid]);
- $memcache->set('port-'.$port['interface_id'].'-'.$oid.'_prev', $port[$oid]);
-# echo("MEMCACHE!");
- }
-
-# echo(" old[".$port[$oid]."]");
-# echo(" new[".$this_port[$oid]."]");
-
- $oid_prev = $oid . "_prev";
- if (isset($port[$oid]))
- {
- $oid_diff = $this_port[$oid] - $port[$oid];
-# echo(" diff[".$oid_diff."]");
- $oid_rate = $oid_diff / $polled_period;
-# echo(" rate[".$oid_rate."]");
- if ($oid_rate < 0) { $oid_rate = "0"; echo("negative $oid"); }
- $port['stats'][$oid.'_rate'] = $oid_rate;
- $port['stats'][$oid.'_diff'] = $oid_diff;
-
- if ($config['slow_statistics'] == TRUE) {
- $port['update'][$oid.'_rate'] = $oid_rate;
- $port['update'][$oid.'_delta'] = $oid_diff;
- }
-
- if ($config['memcached']['enable'])
- {
- $memcache->set('port-'.$port['interface_id'].'-'.$oid.'_rate', $oid_rate);
- $memcache->set('port-'.$port['interface_id'].'-'.$oid.'_delta', $oid_diff);
-# echo($oid."[".$oid_rate."]");
- }
-
- if ($debug) { echo("\n $oid ($oid_diff B) $oid_rate Bps $polled_period secs\n"); }
- }
- }
-
- $port['stats']['ifInBits_rate'] = $port['stats']['ifInOctets_rate'] * 8;
- $port['stats']['ifOutBits_rate'] = $port['stats']['ifOutOctets_rate'] * 8;
- echo('bps('.formatRates($port['stats']['ifInBits_rate']).'/'.formatRates($port['stats']['ifOutBits_rate']).')');
- echo('bytes('.formatStorage($port['stats']['ifInOctets_diff']).'/'.formatStorage($port['stats']['ifOutOctets_diff']).')');
- echo('pkts('.format_si($port['stats']['ifInUcastPkts_rate']).'pps/'.format_si($port['stats']['ifOutUcastPkts_rate']).'pps)');
-
- /// Port utilisation % threshold alerting. ## FIXME allow setting threshold per-port. probably 90% of ports we don't care about.
- if ($config['alerts']['port_util_alert'])
- {
- // Check for port saturation of $config['alerts']['port_util_perc'] or higher. Alert if we see this.
- // Check both inbound and outbound rates
- $saturation_threshold = $this_port['ifSpeed'] * ( $config['alerts']['port_util_perc'] / 100 );
- echo("IN: " . $port['stats']['ifInBits_rate'] . " OUT: " . $port['stats']['ifOutBits_rate'] . " THRESH: " . $saturation_threshold);
- if (($port['stats']['ifInBits_rate'] >= $saturation_threshold || $port['stats']['ifOutBits_rate'] >= $saturation_threshold) && $saturation_threshold > 0)
- {
- log_event('Port reached saturation threshold: ' . formatRates($port['stats']['ifInBits_rate']) . '/' . formatRates($port['stats']['ifOutBits_rate']) . ' - ifspeed: ' . formatRates( $this_port['stats']['ifSpeed']) , $device, 'interface', $port['interface_id']);
- notify($device, 'Port saturation threshold reached on ' . $device['hostname'] , 'Port saturation threshold alarm: ' . $device['hostname'] . ' on ' . $port['ifDescr'] . "\nRates:" . formatRates($port['stats']['ifInBits_rate']) . '/' . formatRates($port['stats']['ifOutBits_rate']) . ' - ifspeed: ' . formatRates( $this_port['ifSpeed']));
- }
- }
-
- /// Update RRDs
- $rrdfile = $host_rrd . "/port-" . safename($port['ifIndex'] . ".rrd");
- if (!is_file($rrdfile))
- {
- rrdtool_create($rrdfile," --step 300 \
- DS:INOCTETS:DERIVE:600:0:12500000000 \
- DS:OUTOCTETS:DERIVE:600:0:12500000000 \
- DS:INERRORS:DERIVE:600:0:12500000000 \
- DS:OUTERRORS:DERIVE:600:0:12500000000 \
- DS:INUCASTPKTS:DERIVE:600:0:12500000000 \
- DS:OUTUCASTPKTS:DERIVE:600:0:12500000000 \
- DS:INNUCASTPKTS:DERIVE:600:0:12500000000 \
- DS:OUTNUCASTPKTS:DERIVE:600:0:12500000000 \
- DS:INDISCARDS:DERIVE:600:0:12500000000 \
- DS:OUTDISCARDS:DERIVE:600:0:12500000000 \
- DS:INUNKNOWNPROTOS:DERIVE:600:0:12500000000 \
- DS:INBROADCASTPKTS:DERIVE:600:0:12500000000 \
- DS:OUTBROADCASTPKTS:DERIVE:600:0:12500000000 \
- DS:INMULTICASTPKTS:DERIVE:600:0:12500000000 \
- DS:OUTMULTICASTPKTS:DERIVE:600:0:12500000000 ".$config['rrd_rra']);
- }
-
- foreach ($stat_oids as $oid)
- { /// Copy values from array to global variables and force numeric.
- $$oid = $this_port[$oid];
- if (!is_numeric($$oid)) { $$oid = "U"; }
- }
-
- $if_rrd_update = "$polled:$ifInOctets:$ifOutOctets:$ifInErrors:$ifOutErrors:$ifInUcastPkts:$ifOutUcastPkts:$ifInNUcastPkts:$ifOutNUcastPkts:$ifInDiscards:$ifOutDiscards:$ifInUnknownProtos";
- $if_rrd_update .= ":$ifInBroadcastPkts:$ifOutBroadcastPkts:$ifInMulticastPkts:$ifOutMulticastPkts";
- $ret = rrdtool_update("$rrdfile", $if_rrd_update);
- /// End Update IF-MIB
-
- /// Update PAgP
- if ($this_port['pagpOperationMode'] || $port['pagpOperationMode'])
- {
- foreach ($pagp_oids as $oid)
- { /// Loop the OIDs
- if ($this_port[$oid] != $port[$oid])
- { /// If data has changed, build a query
- $port['update'][$oid] = $this_port[$oid];
- echo("PAgP ");
- log_event("$oid -> ".$this_port[$oid], $device, 'interface', $port['interface_id']);
- }
- }
- }
- /// End Update PAgP
-
- /// Do EtherLike-MIB
- if ($config['enable_ports_etherlike']) { include("port-etherlike.inc.php"); }
-
- /// Do ADSL MIB
- if ($config['enable_ports_adsl']) { include("port-adsl.inc.php"); }
-
- /// Do PoE MIBs
- if ($config['enable_ports_poe']) { include("port-poe.inc.php"); }
-
- /// Do Alcatel Detailed Stats
- if ($device['os'] == "aos") { include("port-alcatel.inc.php"); }
-
- /// Update Database
- if (count($port['update']))
- {
- $updated = dbUpdate($port['update'], 'ports', '`interface_id` = ?', array($port['interface_id']));
- if ($debug) { echo("$updated updated"); }
- }
- /// End Update Database
-
- /// Send alerts for interface flaps.
- if ($config['alerts']['port']['ifdown'] && ($port['ifOperStatus'] != $this_port['ifOperStatus']) && $port['ignore'] == 0)
- {
- if ($this_port['ifAlias'])
- {
- $falias = preg_replace('/^"/', '', $this_port['ifAlias']); $falias = preg_replace('/"$/', '', $falias); $full = $this_port['ifDescr'] . " (" . $falias . ")";
- } else {
- $full = $this_port['ifDescr'];
- }
- switch ($this_port['ifOperStatus'])
- {
- case "up":
- notify($device, "Interface UP - " . $device['hostname'] . " - " . $full, "Device: " . $device['hostname'] . "\nInterface: " . $full);
- break;
- case "down":
- notify($device, "Interface DOWN - " . $device['hostname'] . " - " . $full, "Device: " . $device['hostname'] . "\nInterface: " . $full);
- break;
- }
- }
- }
- elseif ($port['disabled'] != "1")
- {
- echo("Port Deleted"); /// Port missing from SNMP cache.
- if ($port['deleted'] != "1")
- {
- dbUpdate(array('deleted' => '1'), 'ports', '`device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $port['ifIndex']));
- }
- } else {
- echo("Port Disabled.");
- }
-
- echo("\n");
-
- /// Clear Per-Port Variables Here
- unset($this_port);
-}
/// Clear Variables Here
unset($port_stats);
+unset($ports_db);
+unset($ports_db_db);
?>
diff --git a/includes/discovery/vlans.inc.php b/includes/discovery/vlans.inc.php
index 0b5ceb4ed..ee51ed96b 100644
--- a/includes/discovery/vlans.inc.php
+++ b/includes/discovery/vlans.inc.php
@@ -52,7 +52,7 @@ foreach ($device['vlans'] as $domain_id => $vlans)
str_pad($vlan_port['dot1dStpPortState'], 15).str_pad($vlan_port['dot1dStpPortPathCost'], 10));
$db_w = array('device_id' => $device['device_id'],
- 'interface_id' => $port['interface_id'],
+ 'port_id' => $port['port_id'],
'vlan' => $vlan_id);
$db_a = array('baseport' => $vlan_port_id,
@@ -60,7 +60,7 @@ foreach ($device['vlans'] as $domain_id => $vlans)
'state' => $vlan_port['dot1dStpPortState'],
'cost' => $vlan_port['dot1dStpPortPathCost']);
- $from_db = dbFetchRow("SELECT * FROM `ports_vlans` WHERE device_id = ? AND interface_id = ? AND `vlan` = ?", array($device['device_id'], $port['interface_id'], $vlan_id));
+ $from_db = dbFetchRow("SELECT * FROM `ports_vlans` WHERE device_id = ? AND port_id = ? AND `vlan` = ?", array($device['device_id'], $port['port_id'], $vlan_id));
if ($from_db['port_vlan_id'])
{
diff --git a/includes/functions.php b/includes/functions.php
index ac296eaaa..337ebbca3 100755
--- a/includes/functions.php
+++ b/includes/functions.php
@@ -170,7 +170,7 @@ function delete_device($id)
foreach (dbFetch("SELECT * FROM `ports` WHERE `device_id` = ?", array($id)) as $int_data)
{
$int_if = $int_data['ifDescr'];
- $int_id = $int_data['interface_id'];
+ $int_id = $int_data['port_id'];
delete_port($int_id);
$ret .= "Removed interface $int_id ($int_if)\n";
}
diff --git a/includes/polling/cisco-cef.inc.php b/includes/polling/cisco-cef.inc.php
index eb789f3d3..ab139dee2 100755
--- a/includes/polling/cisco-cef.inc.php
+++ b/includes/polling/cisco-cef.inc.php
@@ -68,6 +68,8 @@ if ($device['os_group'] == "cisco")
if (is_numeric($cef_stat['cefSwitchingHCPunt'])) { $cef_stat['cefSwitchingPunt'] = $cef_stat['cefSwitchingHCPunt']; }
if (is_numeric($cef_stat['cefSwitchingHCPunt2Host'])) { $cef_stat['cefSwitchingPunt2Host'] = $cef_stat['cefSwitchingHCPunt2Host']; }
+ ## FIXME -- memcached
+
$cef_stat['update']['drop'] = $cef_stat['cefSwitchingDrop'];
$cef_stat['update']['punt'] = $cef_stat['cefSwitchingPunt'];
$cef_stat['update']['punt2host'] = $cef_stat['cefSwitchingPunt2Host'];
@@ -79,10 +81,7 @@ if ($device['os_group'] == "cisco")
dbUpdate($cef_stat['update'], 'cef_switching', '`device_id` = ? AND `entPhysicalIndex` = ? AND `afi` = ? AND `cef_index` = ?', array($device['device_id'], $entity, $afi, $path));
- $rrd_update = "N:".$cef_stat['cefSwitchingDrop'].":".$cef_stat['cefSwitchingPunt'].":".$cef_stat['cefSwitchingPunt2Host'];
- $ret = rrdtool_update("$filename", $rrd_update);
-
- if ($debug) { echo(" Values: ".$cef_stat['cefSwitchingDrop'].":".$cef_stat['cefSwitchingPunt'].":".$cef_stat['cefSwitchingPunt2Host']); }
+ $ret = rrdtool_update("$filename", array($cef_stat['cefSwitchingDrop'], $cef_stat['cefSwitchingPunt'], $cef_stat['cefSwitchingPunt2Host']));
echo("\n");
diff --git a/includes/polling/cisco-ipsec-flow-monitor.inc.php b/includes/polling/cisco-ipsec-flow-monitor.inc.php
index 26ead9189..7c33cfea8 100755
--- a/includes/polling/cisco-ipsec-flow-monitor.inc.php
+++ b/includes/polling/cisco-ipsec-flow-monitor.inc.php
@@ -74,28 +74,28 @@ if ($device['os_group'] == "cisco")
rrdtool_create($rrd_filename, $rrd_create);
}
- $rrd_update = "N";
- $rrd_update .= ":".$data['cipSecGlobalActiveTunnels'];
- $rrd_update .= ":".$data['cipSecGlobalInOctets'];
- $rrd_update .= ":".$data['cipSecGlobalOutOctets'];
- $rrd_update .= ":".$data['cipSecGlobalInDecompOctets'];
- $rrd_update .= ":".$data['cipSecGlobalOutUncompOctets'];
- $rrd_update .= ":".$data['cipSecGlobalInPkts'];
- $rrd_update .= ":".$data['cipSecGlobalOutPkts'];
- $rrd_update .= ":".$data['cipSecGlobalInDrops'];
- $rrd_update .= ":".$data['cipSecGlobalInReplayDrops'];
- $rrd_update .= ":".$data['cipSecGlobalOutDrops'];
- $rrd_update .= ":".$data['cipSecGlobalInAuths'];
- $rrd_update .= ":".$data['cipSecGlobalOutAuths'];
- $rrd_update .= ":".$data['cipSecGlobalInAuthFails'];
- $rrd_update .= ":".$data['cipSecGlobalOutAuthFails'];
- $rrd_update .= ":".$data['cipSecGlobalInDecrypts'];
- $rrd_update .= ":".$data['cipSecGlobalOutEncrypts'];
- $rrd_update .= ":".$data['cipSecGlobalInDecryptFails'];
- $rrd_update .= ":".$data['cipSecGlobalOutEncryptFails'];
- $rrd_update .= ":".$data['cipSecGlobalProtocolUseFails'];
- $rrd_update .= ":".$data['cipSecGlobalNoSaFails'];
- $rrd_update .= ":".$data['cipSecGlobalSysCapFails'];
+ $rrd_update = array();
+ $rrd_update[] = $data['cipSecGlobalActiveTunnels'];
+ $rrd_update[] = $data['cipSecGlobalInOctets'];
+ $rrd_update[] = $data['cipSecGlobalOutOctets'];
+ $rrd_update[] = $data['cipSecGlobalInDecompOctets'];
+ $rrd_update[] = $data['cipSecGlobalOutUncompOctets'];
+ $rrd_update[] = $data['cipSecGlobalInPkts'];
+ $rrd_update[] = $data['cipSecGlobalOutPkts'];
+ $rrd_update[] = $data['cipSecGlobalInDrops'];
+ $rrd_update[] = $data['cipSecGlobalInReplayDrops'];
+ $rrd_update[] = $data['cipSecGlobalOutDrops'];
+ $rrd_update[] = $data['cipSecGlobalInAuths'];
+ $rrd_update[] = $data['cipSecGlobalOutAuths'];
+ $rrd_update[] = $data['cipSecGlobalInAuthFails'];
+ $rrd_update[] = $data['cipSecGlobalOutAuthFails'];
+ $rrd_update[] = $data['cipSecGlobalInDecrypts'];
+ $rrd_update[] = $data['cipSecGlobalOutEncrypts'];
+ $rrd_update[] = $data['cipSecGlobalInDecryptFails'];
+ $rrd_update[] = $data['cipSecGlobalOutEncryptFails'];
+ $rrd_update[] = $data['cipSecGlobalProtocolUseFails'];
+ $rrd_update[] = $data['cipSecGlobalNoSaFails'];
+ $rrd_update[] = $data['cipSecGlobalSysCapFails'];
rrdtool_update($rrd_filename, $rrd_update);
diff --git a/includes/polling/cisco-mac-accounting.inc.php b/includes/polling/cisco-mac-accounting.inc.php
index 05bf065f8..633d95054 100755
--- a/includes/polling/cisco-mac-accounting.inc.php
+++ b/includes/polling/cisco-mac-accounting.inc.php
@@ -18,7 +18,7 @@ if ($device['os_group'] == "cisco")
$mac_entries = 0;
- $acc_rows = dbFetchRows("SELECT *, A.poll_time AS poll_time FROM `mac_accounting` as A, `ports` AS I where A.interface_id = I.interface_id AND I.device_id = ?", array($device['device_id']));
+ $acc_rows = dbFetchRows("SELECT *, A.poll_time AS poll_time FROM `mac_accounting` as A, `ports` AS I where A.port_id = I.port_id AND I.device_id = ?", array($device['device_id']));
foreach ($acc_rows as $acc)
{
diff --git a/includes/polling/cisco-vpdn.inc.php b/includes/polling/cisco-vpdn.inc.php
index 50aeeee75..47a74bd63 100755
--- a/includes/polling/cisco-vpdn.inc.php
+++ b/includes/polling/cisco-vpdn.inc.php
@@ -16,24 +16,15 @@ if ($device['os_group'] == "cisco")
{
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("vpdn-".$type.".rrd");
- $rrd_create = " DS:tunnels:GAUGE:600:0:U";
- $rrd_create .= " DS:sessions:GAUGE:600:0:U";
- $rrd_create .= " DS:denied:COUNTER:600:0:100000";
- $rrd_create .= $config['rrd_rra'];
if (is_file($rrd_filename) || $vpdn['cvpdnSystemTunnelTotal'] || $vpdn['cvpdnSystemSessionTotal'])
{
if (!file_exists($rrd_filename))
{
- rrdtool_create($rrd_filename, $rrd_create);
+ rrdtool_create($rrd_filename, " DS:tunnels:GAUGE:600:0:U DS:sessions:GAUGE:600:0:U DS:denied:COUNTER:600:0:100000" . $config['rrd_rra']);
}
- $rrd_update = "N";
- $rrd_update .= ":".$vpdn['cvpdnSystemTunnelTotal'];
- $rrd_update .= ":".$vpdn['cvpdnSystemSessionTotal'];
- $rrd_update .= ":".$vpdn['cvpdnSystemDeniedUsersTotal'];
-
- rrdtool_update($rrd_filename, $rrd_update);
+ rrdtool_update($rrd_filename, array($vpdn['cvpdnSystemTunnelTotal'], $vpdn['cvpdnSystemSessionTotal'], $vpdn['cvpdnSystemDeniedUsersTotal']));
$graphs['vpdn_sessions_'.$type] = TRUE;
$graphs['vpdn_tunnels_'.$type] = TRUE;
@@ -41,7 +32,7 @@ if ($device['os_group'] == "cisco")
echo(" Cisco VPDN ($type) ");
}
}
- unset($data, $vpdn, $type, $rrd_filename, $rrd_create, $rrd_update);
+ unset($data, $vpdn, $type, $rrd_filename);
}
?>
diff --git a/includes/polling/junose-atm-vp.inc.php b/includes/polling/junose-atm-vp.inc.php
index c247e2901..22830ed05 100755
--- a/includes/polling/junose-atm-vp.inc.php
+++ b/includes/polling/junose-atm-vp.inc.php
@@ -1,6 +1,6 @@
".$this_port[$oid], $device, 'ospf', $port['interface_id']); ## FIXME
+ #log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); ## FIXME
}
}
if ($ospf_instance_update)
@@ -120,7 +120,7 @@ if (is_array($ospf_areas_db))
if ($ospf_area_db[$oid] != $ospf_area_poll[$oid])
{ ## If data has changed, build a query
$ospf_area_update[$oid] = $ospf_area_poll[$oid];
- #log_event("$oid -> ".$this_port[$oid], $device, 'interface', $port['interface_id']); ## FIXME
+ #log_event("$oid -> ".$this_port[$oid], $device, 'interface', $port['port_id']); ## FIXME
}
}
if ($ospf_area_update)
@@ -148,7 +148,7 @@ unset($ospf_areas_poll);
echo(" Ports: ");
-$ospf_port_oids = array('ospfIfIpAddress','interface_id','ospfAddressLessIf','ospfIfAreaId','ospfIfType','ospfIfAdminStat','ospfIfRtrPriority','ospfIfTransitDelay','ospfIfRetransInterval','ospfIfHelloInterval','ospfIfRtrDeadInterval','ospfIfPollInterval','ospfIfState','ospfIfDesignatedRouter','ospfIfBackupDesignatedRouter','ospfIfEvents','ospfIfAuthKey','ospfIfStatus','ospfIfMulticastForwarding','ospfIfDemand','ospfIfAuthType');
+$ospf_port_oids = array('ospfIfIpAddress','port_id','ospfAddressLessIf','ospfIfAreaId','ospfIfType','ospfIfAdminStat','ospfIfRtrPriority','ospfIfTransitDelay','ospfIfRetransInterval','ospfIfHelloInterval','ospfIfRtrDeadInterval','ospfIfPollInterval','ospfIfState','ospfIfDesignatedRouter','ospfIfBackupDesignatedRouter','ospfIfEvents','ospfIfAuthKey','ospfIfStatus','ospfIfMulticastForwarding','ospfIfDemand','ospfIfAuthType');
### Build array of existing entries
foreach (dbFetchRows("SELECT * FROM `ospf_ports` WHERE `device_id` = ?", array($device['device_id'])) as $entry)
@@ -190,9 +190,9 @@ if (is_array($ospf_ports_db))
if ($ospf_port_poll['ospfAddressLessIf'])
{
- $ospf_port_poll['interface_id'] = @dbFetchCell("SELECT `interface_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?", array($device['device_id'], $ospf_port_poll['ospfAddressLessIf']));
+ $ospf_port_poll['port_id'] = @dbFetchCell("SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?", array($device['device_id'], $ospf_port_poll['ospfAddressLessIf']));
} else {
- $ospf_port_poll['interface_id'] = @dbFetchCell("SELECT A.`interface_id` FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = ? AND I.interface_id = A.interface_id AND I.device_id = ?", array($ospf_port_poll['ospfIfIpAddress'], $device['device_id']));
+ $ospf_port_poll['port_id'] = @dbFetchCell("SELECT A.`port_id` FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ?", array($ospf_port_poll['ospfIfIpAddress'], $device['device_id']));
}
foreach ($ospf_port_oids as $oid)
@@ -200,7 +200,7 @@ if (is_array($ospf_ports_db))
if ($ospf_port_db[$oid] != $ospf_port_poll[$oid])
{ // If data has changed, build a query
$ospf_port_update[$oid] = $ospf_port_poll[$oid];
- #log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['interface_id']); ## FIXME
+ #log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); ## FIXME
}
}
if ($ospf_port_update)
@@ -279,14 +279,14 @@ if (is_array($ospf_nbrs_db))
{
$ospf_nbr_poll = $ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']];
- $ospf_nbr_poll['interface_id'] = @dbFetchCell("SELECT A.`interface_id` FROM ipv4_addresses AS A, nbrs AS I WHERE A.ipv4_address = ? AND I.interface_id = A.interface_id AND I.device_id = ?", array($ospf_nbr_poll['ospfNbrIpAddr'], $device['device_id']));
+ $ospf_nbr_poll['port_id'] = @dbFetchCell("SELECT A.`port_id` FROM ipv4_addresses AS A, nbrs AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ?", array($ospf_nbr_poll['ospfNbrIpAddr'], $device['device_id']));
- if ($ospf_nbr_db['interface_id'] != $ospf_nbr_poll['interface_id'])
+ if ($ospf_nbr_db['port_id'] != $ospf_nbr_poll['port_id'])
{
- if ($ospf_nbr_poll['interface_id']) {
- $ospf_nbr_update = array('interface_id' => $ospf_nbr_poll['interface_id']);
+ if ($ospf_nbr_poll['port_id']) {
+ $ospf_nbr_update = array('port_id' => $ospf_nbr_poll['port_id']);
} else {
- $ospf_nbr_update = array('interface_id' => array('NULL'));
+ $ospf_nbr_update = array('port_id' => array('NULL'));
}
}
@@ -296,7 +296,7 @@ if (is_array($ospf_nbrs_db))
if ($ospf_nbr_db[$oid] != $ospf_nbr_poll[$oid])
{ // If data has changed, build a query
$ospf_nbr_update[$oid] = $ospf_nbr_poll[$oid];
- #log_event("$oid -> ".$this_nbr[$oid], $device, 'ospf', $nbr['interface_id']); ## FIXME
+ #log_event("$oid -> ".$this_nbr[$oid], $device, 'ospf', $nbr['port_id']); ## FIXME
}
}
if ($ospf_nbr_update)
diff --git a/includes/polling/port-adsl.inc.php b/includes/polling/port-adsl.inc.php
index c49064fda..b054f186b 100755
--- a/includes/polling/port-adsl.inc.php
+++ b/includes/polling/port-adsl.inc.php
@@ -86,9 +86,9 @@ if (isset($port_stats[$port['ifIndex']]['adslLineCoding']))
$this_port[$oid] = $this_port[$oid] / 10;
}
- if (dbFetchCell("SELECT COUNT(*) FROM `ports_adsl` WHERE `interface_id` = ?", array($port['interface_id'])) == "0")
+ if (dbFetchCell("SELECT COUNT(*) FROM `ports_adsl` WHERE `port_id` = ?", array($port['port_id'])) == "0")
{
- dbInsert(array('interface_id' => $port['interface_id']), 'ports_adsl');
+ dbInsert(array('port_id' => $port['port_id']), 'ports_adsl');
}
$port['adsl_update'] = array('port_adsl_updated' => array('NOW()'));
@@ -97,7 +97,7 @@ if (isset($port_stats[$port['ifIndex']]['adslLineCoding']))
$data = str_replace("\"", "", $this_port[$oid]); ## FIXME - do we need this?
$port['adsl_update'][$oid] = $data;
}
- dbUpdate($port['adsl_update'], 'ports_adsl', '`interface_id` = ?', array($port['interface_id']));
+ dbUpdate($port['adsl_update'], 'ports_adsl', '`port_id` = ?', array($port['port_id']));
if ($this_port['adslAtucCurrSnrMgn'] > "1280") { $this_port['adslAtucCurrSnrMgn'] = "U"; }
if ($this_port['adslAturCurrSnrMgn'] > "1280") { $this_port['adslAturCurrSnrMgn'] = "U"; }
diff --git a/includes/polling/ports.inc.php b/includes/polling/ports.inc.php
index 071642f11..bfa3adf5b 100755
--- a/includes/polling/ports.inc.php
+++ b/includes/polling/ports.inc.php
@@ -135,18 +135,18 @@ foreach ($port_stats as $ifIndex => $port)
echo("valid");
if (!is_array($ports[$port['ifIndex']]))
{
- $interface_id = dbInsert(array('device_id' => $device['device_id'], 'ifIndex' => $ifIndex), 'ports');
- $ports[$port['ifIndex']] = dbFetchRow("SELECT * FROM `ports` WHERE `interface_id` = ?", array($interface_id));
- echo("Adding: ".$port['ifName']."(".$ifIndex.")(".$ports[$port['ifIndex']]['interface_id'].")");
+ $port_id = dbInsert(array('device_id' => $device['device_id'], 'ifIndex' => $ifIndex), 'ports');
+ $ports[$port['ifIndex']] = dbFetchRow("SELECT * FROM `ports` WHERE `port_id` = ?", array($port_id));
+ echo("Adding: ".$port['ifName']."(".$ifIndex.")(".$ports[$port['ifIndex']]['port_id'].")");
#print_r($ports);
} elseif ($ports[$ifIndex]['deleted'] == "1") {
- dbUpdate(array('deleted' => '0'), 'ports', '`interface_id` = ?', array($ports[$ifIndex]['interface_id']));
+ dbUpdate(array('deleted' => '0'), 'ports', '`port_id` = ?', array($ports[$ifIndex]['port_id']));
$ports[$ifIndex]['deleted'] = "0";
}
} else {
if ($ports[$port['ifIndex']]['deleted'] != "1")
{
- dbUpdate(array('deleted' => '1'), 'ports', '`interface_id` = ?', array($ports[$ifIndex]['interface_id']));
+ dbUpdate(array('deleted' => '1'), 'ports', '`port_id` = ?', array($ports[$ifIndex]['port_id']));
$ports[$ifIndex]['deleted'] = "1";
}
}
@@ -166,7 +166,7 @@ foreach ($ports as $port)
if ($config['memcached']['enable'])
{
- $port['poll_time'] = $memcache->get('port-'.$port['interface_id'].'-poll_time');
+ $port['poll_time'] = $memcache->get('port-'.$port['port_id'].'-poll_time');
# echo("time".$port['poll_time']);
}
@@ -182,9 +182,9 @@ foreach ($ports as $port)
if ($config['memcached']['enable'])
{
- $memcache->set('port-'.$port['interface_id'].'-poll_time', $polled);
- $memcache->set('port-'.$port['interface_id'].'-poll_prev', $port['poll_time']);
- $memcache->set('port-'.$port['interface_id'].'-poll_period', $polled_period);
+ $memcache->set('port-'.$port['port_id'].'-poll_time', $polled);
+ $memcache->set('port-'.$port['port_id'].'-poll_prev', $port['poll_time']);
+ $memcache->set('port-'.$port['port_id'].'-poll_period', $polled_period);
}
### Copy ifHC[In|Out]Octets values to non-HC if they exist
@@ -252,11 +252,11 @@ foreach ($ports as $port)
if ($port[$oid] != $this_port[$oid] && !isset($this_port[$oid]))
{
$port['update'][$oid] = NULL;
- log_event($oid . ": ".$port[$oid]." -> NULL", $device, 'interface', $port['interface_id']);
+ log_event($oid . ": ".$port[$oid]." -> NULL", $device, 'interface', $port['port_id']);
if ($debug) { echo($oid . ": ".$port[$oid]." -> NULL "); } else { echo($oid . " "); }
} elseif ($port[$oid] != $this_port[$oid]) {
$port['update'][$oid] = $this_port[$oid];
- log_event($oid . ": ".$port[$oid]." -> " . $this_port[$oid], $device, 'interface', $port['interface_id']);
+ log_event($oid . ": ".$port[$oid]." -> " . $this_port[$oid], $device, 'interface', $port['port_id']);
if ($debug) { echo($oid . ": ".$port[$oid]." -> " . $this_port[$oid]." "); } else { echo($oid . " "); }
}
}
@@ -274,7 +274,7 @@ foreach ($ports as $port)
if ($port_ifAlias[$attrib] != $port[$attrib_key])
{
$port['update'][$attrib_key] = $port_ifAlias[$attrib];
- log_event($attrib . ": ".$port[$attrib_key]." -> " . $port_ifAlias[$attrib], $device, 'interface', $port['interface_id']);
+ log_event($attrib . ": ".$port[$attrib_key]." -> " . $port_ifAlias[$attrib], $device, 'interface', $port['port_id']);
}
}
}
@@ -283,7 +283,6 @@ foreach ($ports as $port)
### Update IF-MIB metrics
foreach ($stat_oids_db as $oid)
{
-# echo("\n".$oid.":");
if ($config['slow_statistics'] == TRUE) {
$port['update'][$oid] = $this_port[$oid];
@@ -292,22 +291,16 @@ foreach ($ports as $port)
if ($config['memcached']['enable'])
{
- $port[$oid] = $memcache->get('port-'.$port['interface_id'].'-'.$oid);
- $memcache->set('port-'.$port['interface_id'].'-'.$oid, $this_port[$oid]);
- $memcache->set('port-'.$port['interface_id'].'-'.$oid.'_prev', $port[$oid]);
-# echo("MEMCACHE!");
+ $port[$oid] = $memcache->get('port-'.$port['port_id'].'-'.$oid);
+ $memcache->set('port-'.$port['port_id'].'-'.$oid, $this_port[$oid]);
+ $memcache->set('port-'.$port['port_id'].'-'.$oid.'_prev', $port[$oid]);
}
-# echo(" old[".$port[$oid]."]");
-# echo(" new[".$this_port[$oid]."]");
-
$oid_prev = $oid . "_prev";
if (isset($port[$oid]))
{
$oid_diff = $this_port[$oid] - $port[$oid];
-# echo(" diff[".$oid_diff."]");
$oid_rate = $oid_diff / $polled_period;
-# echo(" rate[".$oid_rate."]");
if ($oid_rate < 0) { $oid_rate = "0"; echo("negative $oid"); }
$port['stats'][$oid.'_rate'] = $oid_rate;
$port['stats'][$oid.'_diff'] = $oid_diff;
@@ -319,17 +312,24 @@ foreach ($ports as $port)
if ($config['memcached']['enable'])
{
- $memcache->set('port-'.$port['interface_id'].'-'.$oid.'_rate', $oid_rate);
- $memcache->set('port-'.$port['interface_id'].'-'.$oid.'_delta', $oid_diff);
-# echo($oid."[".$oid_rate."]");
+ $memcache->set('port-'.$port['port_id'].'-'.$oid.'_rate', $oid_rate);
+ $memcache->set('port-'.$port['port_id'].'-'.$oid.'_delta', $oid_diff);
}
if ($debug) { echo("\n $oid ($oid_diff B) $oid_rate Bps $polled_period secs\n"); }
}
}
- $port['stats']['ifInBits_rate'] = $port['stats']['ifInOctets_rate'] * 8;
- $port['stats']['ifOutBits_rate'] = $port['stats']['ifOutOctets_rate'] * 8;
+ $port['stats']['ifInBits_rate'] = round($port['stats']['ifInOctets_rate'] * 8);
+ $port['stats']['ifOutBits_rate'] = round($port['stats']['ifOutOctets_rate'] * 8);
+
+ // If we have a valid ifSpeed we should populate the stats for checking.
+ if(is_numeric($this_port['ifSpeed']))
+ {
+ $port['stats']['ifInBits_perc'] = round($port['stats']['ifInBits_rate'] / $this_port['ifSpeed'] * 100);
+ $port['stats']['ifOutBits_perc'] = round($port['stats']['ifOutBits_rate'] / $this_port['ifSpeed'] * 100);
+ }
+
echo('bps('.formatRates($port['stats']['ifInBits_rate']).'/'.formatRates($port['stats']['ifOutBits_rate']).')');
echo('bytes('.formatStorage($port['stats']['ifInOctets_diff']).'/'.formatStorage($port['stats']['ifOutOctets_diff']).')');
echo('pkts('.format_si($port['stats']['ifInUcastPkts_rate']).'pps/'.format_si($port['stats']['ifOutUcastPkts_rate']).'pps)');
@@ -343,11 +343,14 @@ foreach ($ports as $port)
echo("IN: " . $port['stats']['ifInBits_rate'] . " OUT: " . $port['stats']['ifOutBits_rate'] . " THRESH: " . $saturation_threshold);
if (($port['stats']['ifInBits_rate'] >= $saturation_threshold || $port['stats']['ifOutBits_rate'] >= $saturation_threshold) && $saturation_threshold > 0)
{
- log_event('Port reached saturation threshold: ' . formatRates($port['stats']['ifInBits_rate']) . '/' . formatRates($port['stats']['ifOutBits_rate']) . ' - ifspeed: ' . formatRates( $this_port['stats']['ifSpeed']) , $device, 'interface', $port['interface_id']);
+ log_event('Port reached saturation threshold: ' . formatRates($port['stats']['ifInBits_rate']) . '/' . formatRates($port['stats']['ifOutBits_rate']) . ' - ifspeed: ' . formatRates( $this_port['stats']['ifSpeed']) , $device, 'interface', $port['port_id']);
notify($device, 'Port saturation threshold reached on ' . $device['hostname'] , 'Port saturation threshold alarm: ' . $device['hostname'] . ' on ' . $port['ifDescr'] . "\nRates:" . formatRates($port['stats']['ifInBits_rate']) . '/' . formatRates($port['stats']['ifOutBits_rate']) . ' - ifspeed: ' . formatRates( $this_port['ifSpeed']));
}
}
+ print_r($port['stats']);
+
+
### Update RRDs
$rrdfile = $host_rrd . "/port-" . safename($port['ifIndex'] . ".rrd");
if (!is_file($rrdfile))
@@ -370,15 +373,11 @@ foreach ($ports as $port)
DS:OUTMULTICASTPKTS:DERIVE:600:0:12500000000 ".$config['rrd_rra']);
}
- foreach ($stat_oids as $oid)
- { ### Copy values from array to global variables and force numeric.
- $$oid = $this_port[$oid];
- if (!is_numeric($$oid)) { $$oid = "U"; }
- }
+ $this_port['rrd_update'] = array($this_port['ifInOctets'], $this_port['ifOutOctets'], $this_port['ifInErrors'], $this_port['ifOutErrors'], $this_port['ifInUcastPkts'], $this_port['ifOutUcastPkts'],
+ $this_port['ifInNUcastPkts'], $this_port['ifOutNUcastPkts'], $this_port['ifInDiscards'], $this_port['ifOutDiscards'], $this_port['ifInUnknownProtos'],
+ $this_port['ifInBroadcastPkts'], $this_port['ifOutBroadcastPkts'], $this_port['ifInMulticastPkts'], $this_port['ifOutMulticastPkts']);
- $if_rrd_update = "$polled:$ifInOctets:$ifOutOctets:$ifInErrors:$ifOutErrors:$ifInUcastPkts:$ifOutUcastPkts:$ifInNUcastPkts:$ifOutNUcastPkts:$ifInDiscards:$ifOutDiscards:$ifInUnknownProtos";
- $if_rrd_update .= ":$ifInBroadcastPkts:$ifOutBroadcastPkts:$ifInMulticastPkts:$ifOutMulticastPkts";
- $ret = rrdtool_update("$rrdfile", $if_rrd_update);
+ rrdtool_update("$rrdfile", $this_port['rrd_update']);
### End Update IF-MIB
### Update PAgP
@@ -390,7 +389,7 @@ foreach ($ports as $port)
{ ### If data has changed, build a query
$port['update'][$oid] = $this_port[$oid];
echo("PAgP ");
- log_event("$oid -> ".$this_port[$oid], $device, 'interface', $port['interface_id']);
+ log_event("$oid -> ".$this_port[$oid], $device, 'interface', $port['port_id']);
}
}
}
@@ -411,7 +410,7 @@ foreach ($ports as $port)
### Update Database
if (count($port['update']))
{
- $updated = dbUpdate($port['update'], 'ports', '`interface_id` = ?', array($port['interface_id']));
+ $updated = dbUpdate($port['update'], 'ports', '`port_id` = ?', array($port['port_id']));
if ($debug) { echo("$updated updated"); }
}
### End Update Database
diff --git a/includes/polling/ucd-diskio.inc.php b/includes/polling/ucd-diskio.inc.php
index 321b98948..92a3af276 100644
--- a/includes/polling/ucd-diskio.inc.php
+++ b/includes/polling/ucd-diskio.inc.php
@@ -19,9 +19,6 @@ if (count($diskio_data))
if ($debug) { print_r($entry); }
- $rrd_update = $entry['diskIONReadX'].":".$entry['diskIONWrittenX'];
- $rrd_update .= ":".$entry['diskIOReads'].":".$entry['diskIOWrites'];
-
$rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("ucd_diskio-" . $diskio['diskio_descr'] .".rrd");
if ($debug) { echo("$rrd "); }
@@ -35,8 +32,7 @@ if (count($diskio_data))
DS:writes:DERIVE:600:0:125000000000 ".$config['rrd_rra']);
}
- rrdtool_update($rrd,"N:$rrd_update");
- unset($rrd_update);
+ rrdtool_update($rrd, array($entry['diskIONReadX'], $entry['diskIONWrittenX'], $entry['diskIOReads'], $entry['diskIOWrites']));
}
echo("\n");
diff --git a/includes/rrdtool.inc.php b/includes/rrdtool.inc.php
index e1ec9f8c6..4c455ad69 100644
--- a/includes/rrdtool.inc.php
+++ b/includes/rrdtool.inc.php
@@ -2,14 +2,7 @@
/**
* Observium Network Management and Monitoring System
- * Copyright (C) 2006-2011, Observium Developers - http://www.observium.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * See COPYING for more details.
+ * Copyright (C) 2006-2012, Adam Armstrong - http://www.observium.org
*
* @package rrdtool
* @author Adam Armstrong
diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php
index fe7552223..fd1aac692 100644
--- a/includes/snmp.inc.php
+++ b/includes/snmp.inc.php
@@ -2,6 +2,8 @@
// If anybody has again the idea to implement the PHP internal library calls,
// be aware that it was tried and banned by lead dev Adam
+//
+// TRUE STORY. THAT SHIT IS WHACK. -- adama.
function string_to_oid($string)
{
diff --git a/includes/snmptrap/linkDown.inc.php b/includes/snmptrap/linkDown.inc.php
index c6e6bb994..6093597df 100644
--- a/includes/snmptrap/linkDown.inc.php
+++ b/includes/snmptrap/linkDown.inc.php
@@ -7,16 +7,16 @@ if (!$interface) { exit; }
$ifOperStatus = "down";
#$ifAdminStatus = "down";
-log_event("SNMP Trap: linkDown " . $interface['ifDescr'], $device, "interface", $interface['interface_id']);
+log_event("SNMP Trap: linkDown " . $interface['ifDescr'], $device, "interface", $interface['port_id']);
#if ($ifAdminStatus != $interface['ifAdminStatus'])
#{
-# log_event("Interface Disabled : " . $interface['ifDescr'] . " (TRAP)", $device, "interface", $interface['interface_id']);
+# log_event("Interface Disabled : " . $interface['ifDescr'] . " (TRAP)", $device, "interface", $interface['port_id']);
#}
if ($ifOperStatus != $interface['ifOperStatus'])
{
- log_event("Interface went Down : " . $interface['ifDescr'] . " (TRAP)", $device, "interface", $interface['interface_id']);
- mysql_query("UPDATE `ports` SET ifOperStatus = 'down' WHERE `interface_id` = '".$interface['interface_id']."'");
+ log_event("Interface went Down : " . $interface['ifDescr'] . " (TRAP)", $device, "interface", $interface['port_id']);
+ mysql_query("UPDATE `ports` SET ifOperStatus = 'down' WHERE `port_id` = '".$interface['port_id']."'");
}
?>
\ No newline at end of file
diff --git a/includes/snmptrap/linkUp.inc.php b/includes/snmptrap/linkUp.inc.php
index 8974852df..f4d1cbd63 100644
--- a/includes/snmptrap/linkUp.inc.php
+++ b/includes/snmptrap/linkUp.inc.php
@@ -7,18 +7,18 @@ if (!$interface) { exit; }
$ifOperStatus = "up";
$ifAdminStatus = "up";
-log_event("SNMP Trap: linkUp $ifAdminStatus/$ifOperStatus " . $interface['ifDescr'], $device, "interface", $interface['interface_id']);
+log_event("SNMP Trap: linkUp $ifAdminStatus/$ifOperStatus " . $interface['ifDescr'], $device, "interface", $interface['port_id']);
if ($ifAdminStatus != $interface['ifAdminStatus'])
{
- log_event("Interface Enabled : " . $interface['ifDescr'] . " (TRAP)", $device, "interface", $interface['interface_id']);
- mysql_query("UPDATE `ports` SET ifAdminStatus = 'up' WHERE `interface_id` = '".$interface['interface_id']."'");
+ log_event("Interface Enabled : " . $interface['ifDescr'] . " (TRAP)", $device, "interface", $interface['port_id']);
+ mysql_query("UPDATE `ports` SET ifAdminStatus = 'up' WHERE `port_id` = '".$interface['port_id']."'");
}
if ($ifOperStatus != $interface['ifOperStatus'])
{
- log_event("Interface went Up : " . $interface['ifDescr'] . " (TRAP)", $device, "interface", $interface['interface_id']);
- mysql_query("UPDATE `ports` SET ifOperStatus = 'up' WHERE `interface_id` = '".$interface['interface_id']."'");
+ log_event("Interface went Up : " . $interface['ifDescr'] . " (TRAP)", $device, "interface", $interface['port_id']);
+ mysql_query("UPDATE `ports` SET ifOperStatus = 'up' WHERE `port_id` = '".$interface['port_id']."'");
}
diff --git a/includes/syslog.php b/includes/syslog.php
index adf50ac09..f685107ae 100755
--- a/includes/syslog.php
+++ b/includes/syslog.php
@@ -4,7 +4,7 @@
# $device_id_host = @dbFetchCell("SELECT device_id FROM devices WHERE `hostname` = '".mres($entry['host'])."' OR `sysName` = '".mres($entry['host'])."'");
-# $device_id_ip = @dbFetchCell("SELECT device_id FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = '" . $entry['host']."' AND I.interface_id = A.interface_id");
+# $device_id_ip = @dbFetchCell("SELECT device_id FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = '" . $entry['host']."' AND I.port_id = A.port_id");
function get_cache($host, $value)
{
@@ -20,7 +20,7 @@ function get_cache($host, $value)
// If failed, try by IP
if (!is_numeric($dev_cache[$host]['device_id']))
{
- $dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM `ipv4_addresses` AS A, `ports` AS I WHERE A.ipv4_address = ? AND I.interface_id = A.interface_id', array($host));
+ $dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM `ipv4_addresses` AS A, `ports` AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id', array($host));
}
break;
case 'os':
diff --git a/poll-billing.php b/poll-billing.php
index bac05c94e..453a823c1 100755
--- a/poll-billing.php
+++ b/poll-billing.php
@@ -45,7 +45,7 @@ foreach (dbFetchRows("SELECT * FROM `bills`") as $bill_data)
function CollectData($bill_id)
{
- foreach (dbFetchRows("SELECT * FROM `bill_ports` as P, `ports` as I, `devices` as D WHERE P.bill_id=? AND I.interface_id = P.port_id AND D.device_id = I.device_id", array($bill_id)) as $port_data)
+ foreach (dbFetchRows("SELECT * FROM `bill_ports` as P, `ports` as I, `devices` as D WHERE P.bill_id=? AND I.port_id = P.port_id AND D.device_id = I.device_id", array($bill_id)) as $port_data)
{
$port_id = $port_data['port_id'];
$host = $port_data['hostname'];
diff --git a/poller.php b/poller.php
index 362ad1a2a..c2f21cc66 100755
--- a/poller.php
+++ b/poller.php
@@ -24,7 +24,7 @@ include("includes/polling/functions.inc.php");
$poller_start = utime();
echo("Observium Poller v".$config['version']."\n\n");
-$options = getopt("h:m:i:n:r:d::a::");
+$options = getopt("h:m:i:n:r::d::a::");
if ($options['h'] == "odd") { $options['n'] = "1"; $options['i'] = "2"; }
elseif ($options['h'] == "even") { $options['n'] = "0"; $options['i'] = "2"; }
diff --git a/snmptrap.php b/snmptrap.php
index 4ebefd5a6..049da4c7c 100755
--- a/snmptrap.php
+++ b/snmptrap.php
@@ -33,7 +33,7 @@ $device = @dbFetchRow("SELECT * FROM devices WHERE `hostname` = ?", array($entry
if (!$device['device_id'])
{
- $device = @dbFetchRow("SELECT * FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = ? AND I.interface_id = A.interface_id", array($entry['0']));
+ $device = @dbFetchRow("SELECT * FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id", array($entry['0']));
}
if (!$device['device_id']) { exit; } else { }
diff --git a/sql-schema/022.sql b/sql-schema/022.sql
new file mode 100644
index 000000000..d4cbc003c
--- /dev/null
+++ b/sql-schema/022.sql
@@ -0,0 +1 @@
+ALTER TABLE `ports` CHANGE `interface_id` `port_id` INT( 11 ) NOT NULL AUTO_INCREMENT;
|