");
- $sql = "SELECT * FROM interfaces WHERE host = '$id'";
+ $sql = "SELECT * FROM interfaces WHERE `device_id` = '$id'";
$query = mysql_query($sql);
while($data = mysql_fetch_array($query)) {
echo("$ifsep" . generateiflink($data, makeshortif(strtolower($data['if']))));
diff --git a/html/pages/interfaces.php b/html/pages/interfaces.php
index ff487b985..6c607c0d5 100644
--- a/html/pages/interfaces.php
+++ b/html/pages/interfaces.php
@@ -1,6 +1,6 @@
");
@@ -9,16 +9,16 @@ echo("
| Device | Interface | Spe
$row = 1;
-while($iface = mysql_fetch_array($query)) {
+while($interface = mysql_fetch_array($query)) {
if(is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
- $speed = humanspeed($iface['ifSpeed']);
- $if_link = generateiflink($iface);
- $dev_link = generatedevicelink($iface);
- $type = humanmedia($iface['ifType']);
+ $speed = humanspeed($interface['ifSpeed']);
+ $if_link = generateiflink($interface);
+ $dev_link = generatedevicelink($interface);
+ $type = humanmedia($interface['ifType']);
- echo(" |
|---|
| $dev_link | $if_link | $speed | $type | $iface[name] |
\n");
+ echo("
| $dev_link | $if_link | $speed | $type | " . $interface[ifAlias] . " |
\n");
$row++;
diff --git a/includes/functions.php b/includes/functions.php
index 3a19bcd31..f2d2c6741 100755
--- a/includes/functions.php
+++ b/includes/functions.php
@@ -47,13 +47,13 @@ function geteventicon ($message) {
}
-function generateiflink($iface, $text=0) {
+function generateiflink($interface, $text=0) {
global $twoday;
global $now;
- if(!$text) { $text = fixIfName($iface['if']); }
- $class = ifclass($iface['up'], $iface['up_admin']);
- $graph_url = "graph.php?if=$iface[id]&from=$twoday&to=$now&width=400&height=120&type=bits";
- $link = "
');\" onmouseout=\"return nd();\">$text";
+ if(!$text) { $text = fixIfName($interface['ifDescr']); }
+ $class = ifclass($interface['ifOperStatus'], $interface['ifAdminStatus']);
+ $graph_url = "graph.php?if=" . $interface['interface_id'] . "&from=$twoday&to=$now&width=400&height=120&type=bits";
+ $link = "
');\" onmouseout=\"return nd();\">$text";
return $link;
}
@@ -975,19 +975,19 @@ function gethostbyid($id) {
}
function getifhost($id) {
- $sql = mysql_query("SELECT `host` from `interfaces` WHERE `id` = '$id'");
+ $sql = mysql_query("SELECT `device_id` from `interfaces` WHERE `interface_id` = '$id'");
$result = @mysql_result($sql, 0);
return $result;
}
function getifindexbyid($id) {
- $sql = mysql_query("SELECT `ifIndex` FROM `interfaces` WHERE `id` = '$id'");
+ $sql = mysql_query("SELECT `ifIndex` FROM `interfaces` WHERE `interface_id` = '$id'");
$result = @mysql_result($sql, 0);
return $result;
}
function getifbyid($id) {
- $sql = mysql_query("SELECT `if` FROM `interfaces` WHERE `id` = '$id'");
+ $sql = mysql_query("SELECT `ifDescr` FROM `interfaces` WHERE `interface_id` = '$id'");
$result = @mysql_result($sql, 0);
return $result;
}
diff --git a/includes/graphing.php b/includes/graphing.php
index f8bf587c8..c96b79e75 100644
--- a/includes/graphing.php
+++ b/includes/graphing.php
@@ -52,7 +52,7 @@ function graph_device_bits ($device, $graph, $from, $to, $width, $height)
$hostname = gethostbyid($device);
- $query = mysql_query("SELECT `ifIndex` FROM `interfaces` WHERE `host` = '$device' AND `ifType` NOT LIKE '%oopback%' AND `ifType` NOT LIKE '%SVI%'");
+ $query = mysql_query("SELECT `ifIndex` FROM `interfaces` WHERE `device_id` = '$device' AND `ifType` NOT LIKE '%oopback%' AND `ifType` NOT LIKE '%SVI%'");
while($int = mysql_fetch_row($query)) {
diff --git a/ips.php b/ips.php
index 0e467ef58..f1859f36e 100755
--- a/ips.php
+++ b/ips.php
@@ -10,7 +10,7 @@ while ($device = mysql_fetch_array($q)) {
$hostid = $device['id'];
$community = $device['community'];
echo("$hostname\n");
- $oids = `snmpwalk -v2c -Osq -c $community $hostname ipAdEntIfIndex | sed s/ipAdEntIfIndex.//g`;
+ $oids = `snmpbulkwalk -v2c -Osq -c $community $hostname ipAdEntIfIndex | sed s/ipAdEntIfIndex.//g`;
$oids = trim($oids);
foreach(explode("\n", $oids) as $data) {
$data = trim($data);
@@ -22,8 +22,8 @@ while ($device = mysql_fetch_array($q)) {
list($net,$cidr) = explode("/", $network);
$cidr = trim($cidr);
if($mask == "255.255.255.255") { $cidr = "32"; $network = "$address/$cidr"; }
- if (mysql_result(mysql_query("SELECT count(id) FROM `interfaces` WHERE host = '$hostid' AND `ifIndex` = '$ifIndex'"), 0) != '0') {
- $i_query = "SELECT id FROM `interfaces` WHERE host = '$hostid' AND `ifIndex` = '$ifIndex'";
+ if (mysql_result(mysql_query("SELECT count(*) FROM `interfaces` WHERE device_id = '$hostid' AND `ifIndex` = '$ifIndex'"), 0) != '0') {
+ $i_query = "SELECT interface_id FROM `interfaces` WHERE device_id = '$hostid' AND `ifIndex` = '$ifIndex'";
$interface_id = mysql_result(mysql_query($i_query), 0);
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipaddr` WHERE `addr` = '$address' AND `cidr` = '$cidr' AND `interface_id` = '$interface_id'"), 0) == '0') {
mysql_query("INSERT INTO `ipaddr` (`addr`, `cidr`, `network`, `interface_id`) VALUES ('$address', '$cidr', '$net', '$interface_id')");
@@ -38,7 +38,6 @@ while ($device = mysql_fetch_array($q)) {
mysql_query("INSERT INTO `adjacencies` (`network_id`, `interface_id`) VALUES ('$network_id', '$interface_id')");
echo("Create Adjacency : $hostname, $interface_id, $network_id, $network, $ifIndex\n");
}
-
} else { }
}
}
diff --git a/poll-interface.php b/poll-interface.php
index 9d6d6d59a..0b80ef504 100755
--- a/poll-interface.php
+++ b/poll-interface.php
@@ -4,33 +4,24 @@
include("config.php");
include("includes/functions.php");
-$interface_query = mysql_query("SELECT *, I.id AS sqlid FROM `interfaces` AS I, `devices` AS D where I.host = D.id AND D.id LIKE '%" . $argv[1]. "' AND D.status = '1'");
+$interface_query = mysql_query("SELECT * FROM `interfaces`");
while ($interface = mysql_fetch_array($interface_query)) {
- $hostname = $interface['hostname'];
- $host = $interface['host'];
- $old_if = $interface['if'];
- $ifIndex = $interface['ifIndex'];
- $old_alias = $interface['name'];
- $id = $interface['sqlid'];
- $old_up = $interface['up'];
- $old_speed = $interface['ifSpeed'];
- $old_duplex = $interface['ifDuplex'];
- $old_physaddress = $interface['ifPhysAddress'];
- $old_type = $interface['ifType'];
- $old_mtu = $interface['ifMtu'];
- $old_up_admin = $interface['up_admin'];
- $community = $interface['community'];
- $os = $interface['os'];
- $snmp_cmd = "snmpget -O qv -v2c -c $community $hostname ifName.$ifIndex ifDescr.$ifIndex ifAdminStatus.$ifIndex ifOperStatus.$ifIndex ";
- $snmp_cmd .= "ifAlias.$ifIndex ifSpeed.$ifIndex 1.3.6.1.2.1.10.7.2.1.$ifIndex ifType.$ifIndex ifMtu.$ifIndex ifPhysAddress.$ifIndex";
- $snmp_output = `$snmp_cmd`;
- $snmp_output = trim($snmp_output);
+ $device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE id = '" . $interface['device_id'] . "'"));
+ if($device['status'] == '1') {
+
+ $snmp_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " ifName." . $interface['ifIndex'];
+ $snmp_cmd .= " ifDescr." . $interface['ifIndex'] . " ifAdminStatus." . $interface['ifIndex'] . " ifOperStatus." . $interface['ifIndex'] . " ";
+ $snmp_cmd .= "ifAlias." . $interface['ifIndex'] . " ifSpeed." . $interface['ifIndex'] . " 1.3.6.1.2.1.10.7.2.1." . $interface['ifIndex'];
+ $snmp_cmd .= " ifType." . $interface['ifIndex'] . " ifMtu." . $interface['ifIndex'] . " ifPhysAddress." . $interface['ifIndex'];
+
+ echo($snmp_cmd);
+
+ $snmp_output = trim(`$snmp_cmd`);
$snmp_output = str_replace("No Such Object available on this agent at this OID", "", $snmp_output);
$snmp_output = str_replace("No Such Instance currently exists at this OID", "", $snmp_output);
- $ifPhysAddress = strtolower(str_replace("\"", "", $ifPhysAddress));
- $ifPhysAddress = str_replace(" ", ":", $ifPhysAddress);
- echo("Looking at $old_if on $hostname \n");
+
+ echo("Looking at " . $interface['ifDescr'] . " on " . $device['hostname'] . "\n");
list($ifName, $ifDescr, $ifAdminStatus, $ifOperStatus, $ifAlias, $ifSpeed, $ifDuplex, $ifType, $ifMtu, $ifPhysAddress) = explode("\n", $snmp_output);
$ifDescr = trim(str_replace("\"", "", $ifDescr));
if ($ifDuplex == 3) { $ifDuplex = "half"; } elseif ($ifDuplex == 2) { $ifDuplex = "full"; } else { $ifDuplex = "unknown"; }
@@ -38,10 +29,16 @@ while ($interface = mysql_fetch_array($interface_query)) {
if ($ifAlias == " ") { $ifAlias = str_replace(" ", "", $ifAlias); }
$ifAlias = trim(str_replace("\"", "", $ifAlias));
$ifAlias = trim($ifAlias);
- if($interface['os'] == "IOS") { $ifType = trim(str_replace("\"", "", `snmpget -O qv -v2c -c $community $hostname 1.3.6.1.4.1.9.2.2.1.1.1.$ifIndex`)); }
+ $ifPhysAddress = strtolower(str_replace("\"", "", $ifPhysAddress));
+ $ifPhysAddress = str_replace(" ", ":", $ifPhysAddress);
- $rrdfile = "rrd/" . $hostname . ".". $ifIndex . ".rrd";
+ if($device['os'] == "IOS") {
+ $locIfHardType_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " 1.3.6.1.4.1.9.2.2.1.1.1." . $interface['ifIndex'];
+ $locIfHardType = trim(str_replace("\"", "", `$locIfHardType_cmd`));
+ }
+
+ $rrdfile = "rrd/" . $device['hostname'] . "." . $interface['ifIndex'] . ".rrd";
if(!is_file($rrdfile)) {
$woo = `rrdtool create $rrdfile \
DS:INOCTETS:COUNTER:600:U:100000000000 \
@@ -66,84 +63,94 @@ while ($interface = mysql_fetch_array($interface_query)) {
unset($update_query);
unset($seperator);
- if ( $old_if != $ifDescr && $ifDescr != "" ) {
+ if ( $interface['ifDescr'] != $ifDescr && $ifDescr != "" ) {
$update = "`if` = '$ifDescr'";
$seperator = ", ";
- mysql_query("INSERT INTO eventlog (host, interface, datetime, message) values ($interface[host], $interface[sqlid], NOW(), 'Name -> $ifDescr')");
+ mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Name -> " . $ifDescr . "')");
}
-
- if ( $old_alias != $ifAlias ) {
- $update .= $seperator . "`name` = \"$ifAlias\"";
+ if ( $interface['ifAlias'] != $ifAlias ) {
+ $update .= $seperator . "`name` = '$ifAlias'";
$seperator = ", ";
- mysql_query("INSERT INTO eventlog (host, interface, datetime, message) values ($interface[host], $interface[sqlid], NOW(), 'Desc -> $ifAlias')");
+ mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Desc -> $ifAlias')");
}
- if ( $old_up != $ifOperStatus && $ifOperStatus != "" ) {
+ if ( $interface['ifOperStatus'] != $ifOperStatus && $ifOperStatus != "" ) {
$update .= $seperator . "`up` = '$ifOperStatus'";
$seperator = ", ";
- mysql_query("INSERT INTO eventlog (host, interface, datetime, message) values ($interface[host], $interface[sqlid], NOW(), 'Interface went $ifOperStatus')");
+ mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Interface went $ifOperStatus')");
}
- if ( $old_up_admin != $ifAdminStatus && $ifAdminStatus != "" ) {
+ if ( $interface['ifAdminStatus'] != $ifAdminStatus && $ifAdminStatus != "" ) {
$update .= $seperator . "`up_admin` = '$ifAdminStatus'";
$seperator = ", ";
if($ifAdminStatus == "up") { $admin = "enabled"; } else { $admin = "disabled"; }
- mysql_query("INSERT INTO eventlog (host, interface, datetime, message) values ($interface[host], $interface[sqlid], NOW(), 'Interface $admin')");
+ mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Interface $admin')");
}
- if ( $old_duplex != $ifDuplex && $ifDuplex != "" ) {
+ if ( $interface['ifDuplex'] != $ifDuplex && $ifDuplex != "" ) {
$update .= $seperator . "`ifDuplex` = '$ifDuplex'";
$seperator = ", ";
- mysql_query("INSERT INTO eventlog (host, interface, datetime, message) values ($interface[host], $interface[sqlid], NOW(), 'Duplex -> $ifDuplex')");
+ mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Duplex -> $ifDuplex')");
}
- if ( $old_type != $ifType && $ifType != "" ) {
+ if ( $interface['ifType'] != $ifType && $ifType != "" ) {
$update .= $seperator . "`ifType` = '$ifType'";
$seperator = ", ";
- mysql_query("INSERT INTO eventlog (host, interface, datetime, message) values ($interface[host], $interface[sqlid], NOW(), 'Type -> $ifType')");
+ mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Type -> $ifType')");
}
- if ( $old_mtu != $ifMtu && $ifMtu != "" ) {
+ if ( $interface['ifMtu'] != $ifMtu && $ifMtu != "" ) {
$update .= $seperator . "`ifMtu` = '$ifMtu'";
$seperator = ", ";
- mysql_query("INSERT INTO eventlog (host, interface, datetime, message) values ($interface[host], $interface[sqlid], NOW(), 'MTU -> $ifMtu')");
+ mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'MTU -> $ifMtu')");
}
- if ( $old_physaddress != $ifPhysAddress && $ifPhysAddress != "" ) {
+ if ( $interface['ifPhysAddress'] != $ifPhysAddress && $ifPhysAddress != "" ) {
$update .= $seperator . "`ifPhysAddress` = '$ifPhysAddress'";
$seperator = ", ";
- mysql_query("INSERT INTO eventlog (host, interface, datetime, message) values ($interface[host], $interface[sqlid], NOW(), 'MAC -> $ifPhysAddress')");
+ mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'MAC -> $ifPhysAddress')");
}
- if ( $old_speed != $ifSpeed && $ifSpeed != "" ) {
+ if ( $interface['ifSpeed'] != $ifSpeed && $ifSpeed != "" ) {
$update .= $seperator . "`ifSpeed` = '$ifSpeed'";
$seperator = ", ";
- $prev = humanspeed($old_speed);
+ $prev = humanspeed($interface['ifSpeed']);
$now = humanspeed($ifSpeed);
- mysql_query("INSERT INTO eventlog (host, interface, datetime, message) values ($interface[host], $interface[sqlid], NOW(), 'Speed -> $now')");
+ mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Speed -> $now')");
}
if ($update) {
$update_query = "UPDATE `interfaces` SET ";
$update_query .= $update;
- $update_query .= " WHERE `id` = '$id'";
- echo("Updating : $hostname $ifDescr\n$update_query\n\n");
+ $update_query .= " WHERE `id` = '" . $interface['interface_id'] . "'";
+ echo("Updating : " . $device['hostname'] . " $ifDescr\nSQL :$update_query\n\n");
$update_result = mysql_query($update_query);
} else {
- echo("Not Updating : $hostname $ifDescr ( $old_if )\n\n");
+ echo("Not Updating : " . $device['hostname'] ." $ifDescr ( " . $interface['ifDescr'] . " )\n\n");
}
if($ifOperStatus == "up") {
- $snmp_data = `snmpget -O qv -v2c -c $community $hostname ifHCInOctets.$ifIndex ifHCOutOctets.$ifIndex ifInErrors.$ifIndex ifOutErrors.$ifIndex \
- ifInUcastPkts.$ifIndex ifOutUcastPkts.$ifIndex ifInNUcastPkts.$ifIndex ifOutNUcastPkts.$ifIndex`;
+ $snmp_data_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'];
+ $snmp_data_cmd .= " ifHCInOctets." . $interface['ifIndex'] . " ifHCOutOctets." . $interface['ifIndex'] . " ifInErrors." . $interface['ifIndex'];
+ $snmp_data_cmd .= " ifOutErrors." . $interface['ifIndex'] . " ifInUcastPkts." . $interface['ifIndex'] . " ifOutUcastPkts." . $interface['ifIndex'];
+ $snmp_data_cmd .= " ifInNUcastPkts." . $interface['ifIndex'] . " ifOutNUcastPkts." . $interface['ifIndex'];
+
+ $snmp_data = `$snmp_data_cmd`;
+
$snmp_data = str_replace("Wrong Type (should be Counter32): ","", $snmp_data);
$snmp_data = str_replace("No Such Instance currently exists at this OID","", $snmp_data);
list($ifHCInOctets, $ifHCOutOctets, $ifInErrors, $ifOutErrors, $ifInUcastPkts, $ifOutUcastPkts, $ifInNUcastPkts, $ifOutNUcastPkts) = explode("\n", $snmp_data);
if($ifHCInOctets == "" || strpos($ifHCInOctets, "No") !== FALSE ) {
- $fixit = `snmpget -O qv -v2c -c $community $hostname ifInOctets.$ifIndex ifOutOctets.$ifIndex`;
- list ($ifHCInOctets, $ifHCOutOctets) = explode("\n", $fixit);
+
+ $octets_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'];
+ $octets_cmd .= " ifInOctets." . $interface['ifIndex'] . " ifOutOctets." . $interface['ifIndex'];
+ $octets = `$octets_cmd`;
+ list ($ifHCInOctets, $ifHCOutOctets) = explode("\n", $octets);
}
$woo = "N:$ifHCInOctets:$ifHCOutOctets:$ifInErrors:$ifOutErrors:$ifInUcastPkts:$ifOutUcastPkts:$ifInNUcastPkts:$ifOutNUcastPkts";
$ret = rrd_update("$rrdfile", $woo);
} else {
- echo("Interface $hostname $old_if is down\n");
+ echo("Interface " . $device['hostname'] . " " . $interface['ifDescr'] . " is down\n");
}
+ }
}
mysql_query("UPDATE interfaces set ifPhysAddress = '' WHERE ifPhysAddress = 'No Such Instance currently exists at this OID'");
?>
+
+