diff --git a/cleanup.php b/cleanup.php index 867267f66..045fb9c97 100755 --- a/cleanup.php +++ b/cleanup.php @@ -7,7 +7,7 @@ include("config.php"); include("includes/functions.php"); $query = "SELECT *,A.id as id FROM ipaddr AS A, interfaces as I, devices as D - WHERE A.interface_id = I.id AND I.host = D.id AND D.status = '1' AND I.id LIKE '%$argv[1]'"; + WHERE A.interface_id = I.interface_id AND I.device_id = D.id AND D.status = '1'"; $data = mysql_query($query); while($row = mysql_fetch_array($data)) { @@ -22,29 +22,28 @@ while($row = mysql_fetch_array($data)) { } } -$query = "SELECT *, I.id as id FROM interfaces AS I, devices as D +$query = "SELECT * FROM interfaces AS I, devices as D WHERE I.host = D.id AND D.status = '1'"; $data = mysql_query($query); while($row = mysql_fetch_array($data)) { - $id = $row['id']; $index = $row[ifIndex]; $hostname = $row['hostname']; $community = $row['community']; $response = trim(`snmpget -v2c -Osq -c $community $hostname ifIndex.$index | cut -d " " -f 2`); if($response != $index) { - mysql_query("delete from interfaces where id = '$id'"); - echo("Deleted $row[if] from $hostname\n"); + mysql_query("delete from interfaces where id = '" . $row['interface_id'] . "'"); + echo("Deleted $row[ifDescr] from $hostname\n"); } } echo(mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces`"), 0) . " interfaces at start\n"); -$interface_query = mysql_query("SELECT id,host FROM `interfaces`"); +$interface_query = mysql_query("SELECT interface_id,device_id FROM `interfaces`"); while ($interface = mysql_fetch_array($interface_query)) { - $host = $interface['host']; - $id = $interface['id']; - if(mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `id` = '$host'"), 0) == '0') { - mysql_query("delete from interfaces where `id` = '$id'"); - echo("Deleting if $id \n"); + $device_id = $interface['device_id']; + $interface_id = $interface['interface_id']; + if(mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `id` = '$device_id'"), 0) == '0') { + mysql_query("delete from interfaces where `interface_id` = '$interface_id'"); + echo("Deleting if $interface_id \n"); } } echo(mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces`"), 0) . " interfaces at end\n"); @@ -55,7 +54,7 @@ while ($link = mysql_fetch_array($link_query)) { $id = $link['id']; $src = $link['src_if']; $dst = $link['dst_if']; - if(mysql_result(mysql_query("SELECT COUNT(id) FROM `interfaces` WHERE `id` = '$src'"), 0) == '0' || mysql_result(mysql_query("SELECT COUNT(id) FROM `interfaces` WHERE `id` = '$dst'"), 0) == '0') { + if(mysql_result(mysql_query("SELECT COUNT(interface_id) FROM `interfaces` WHERE `interface_id` = '$src'"), 0) == '0' || mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces` WHERE `interface_id` = '$dst'"), 0) == '0') { mysql_query("delete from links where `id` = '$id'"); echo("Deleting link $id \n"); } @@ -63,12 +62,12 @@ while ($link = mysql_fetch_array($link_query)) { echo(mysql_result(mysql_query("SELECT COUNT(id) FROM `links`"), 0) . " links at end\n"); echo(mysql_result(mysql_query("SELECT COUNT(adj_id) FROM `adjacencies`"), 0) . " adjacencies at start\n"); -$link_query = mysql_query("SELECT * FROM `adjacencies` AS A, `interfaces` AS I, `devices` AS D, networks AS N WHERE I.id = A.interface_id AND D.id = I.host AND N.id = A.network_id;"); +$link_query = mysql_query("SELECT * FROM `adjacencies` AS A, `interfaces` AS I, `devices` AS D, networks AS N WHERE I.interface_id = A.interface_id AND D.id = I.device_id AND N.id = A.network_id;"); while ($link = mysql_fetch_array($link_query)) { $id = $link['adj_id']; $netid = $link['network_id']; $ifid = $link['interface_id']; - if(mysql_result(mysql_query("SELECT COUNT(id) FROM `interfaces` WHERE `id` = '$ifid'"), 0) == '0' || mysql_result(mysql_query("SELECT COUNT(id) FROM `networks` WHERE `id` = '$netid'"), 0) == '0') { + if(mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces` WHERE `interface_id` = '$ifid'"), 0) == '0' || mysql_result(mysql_query("SELECT COUNT(id) FROM `networks` WHERE `id` = '$netid'"), 0) == '0') { $remove = 1; echo("Removed Interface!\n"); } diff --git a/discover-ifs.php b/discover-ifs.php index 982174f15..63136d036 100755 --- a/discover-ifs.php +++ b/discover-ifs.php @@ -30,9 +30,9 @@ while ($device = mysql_fetch_row($device_query)) { if (preg_match('/serial[0-9]:/', $if)) { $nullintf = '1'; } if (preg_match('/ng[0-9]+$/', $if)) { } if ($nullintf == 0) { - if(mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces` WHERE `host` = '$id' AND `ifIndex` = '$ifIndex'"), 0) == '0') { + if(mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces` WHERE `device_id` = '$id' AND `ifIndex` = '$ifIndex'"), 0) == '0') { echo "Adding port $ifName \n"; - mysql_query("INSERT INTO `interfaces` (`host`,`ifIndex`,`if`) VALUES ('$id','$ifIndex','$ifName')"); + mysql_query("INSERT INTO `interfaces` (`device_id`,`ifIndex`,`ifDescr`) VALUES ('$id','$ifIndex','$ifName')"); } else { # echo("Already have $ifName \n"); } diff --git a/html/includes/print-event.inc b/html/includes/print-event.inc index 483ad95e4..abe75b430 100644 --- a/html/includes/print-event.inc +++ b/html/includes/print-event.inc @@ -27,12 +27,12 @@ if($bg == $list_colour_a) { $bg = $list_colour_b; } else { $bg=$list_colour_a; } echo(""); - if($if['id']) { - $if['id'] = $entry['interface']; - $if['if'] = $interface; + if($interface) { + $if['interface_id'] = $entry['interface']; + $if['ifDescr'] = $interface; echo(generateiflink($if)); } - echo(""); + echo(" $icon " . $entry['message'] . " diff --git a/html/includes/print-interface.inc b/html/includes/print-interface.inc index 924971bd2..2820ff96d 100644 --- a/html/includes/print-interface.inc +++ b/html/includes/print-interface.inc @@ -2,61 +2,62 @@ # This file prints a table row for each interface - $if_id = $interface['id']; - $inf = fixifName($interface['if']); + $if_id = $interface['interface_id']; + $ifDescr = fixifName($interface['ifDescr']); $ifIndex = $interface['ifIndex']; - $ifclass = ifclass($interface['up'], $interface['up_admin']); - $ifname = $interface['name']; - $speed = humanspeed($interface['ifSpeed']); - $mac = $interface['ifPhysAddress']; - if($ifname) {$ifname = $ifname . "
";} + $ifAlias = $interface['ifAlias']; + $ifSpeed = humanspeed($interface['ifSpeed']); + $ifPhysAddress = $interface['ifPhysAddress']; + $ifType = fixiftype($interface['ifType']); + + if($ifAlias) {$ifAlias = $ifAlias . "
";} if($bg == "#ffffff") { $bg = "#e5e5e5"; } else { $bg="#ffffff"; } + $graph_url = "graph.php?if=$if_id&from=$twoday&to=$now&width=400&height=120&type=bits"; + echo(" - ');\" onmouseout=\"return nd();\" - class='$ifclass' href='?page=interface&id=$interface[id]'> - $i. $inf -
$ifname"); + + " . generateiflink($interface, "$i. $ifDescr") . " +
$ifAlias"); unset ($break); - $iftype = fixiftype($interface[ifType]); if(!$dographs) { - $ipdata = mysql_query("SELECT * FROM `ipaddr` WHERE `interface_id` = '$interface[id]'"); + $ipdata = mysql_query("SELECT * FROM `ipaddr` WHERE `interface_id` = '$interface[interface_id]'"); while($ip = mysql_fetch_Array($ipdata)) { echo("$break $ip[addr]/$ip[cidr]"); $break = " "; } echo(""); echo(""); - if($speed && $speed != "") { echo("$speed"); } + if($ifSpeed && $ifSpeed != "") { echo("$ifSpeed"); } echo(""); - if($iftype && $iftype != "") { echo("$iftype"); } else { echo("-"); } + if($ifType && $iftype != "") { echo("" . $ifType . ""); } else { echo("-"); } echo(""); - if($mac && $mac != "") { echo("$mac"); } else { echo("-"); } + if($interface['ifPhysAddress'] && $interface['ifPhysAddress'] != "") { echo("" . $interface['ifPhysAddress'] . ""); } else { echo("-"); } echo(""); - if($interface[ifMtu] && $interface[ifMtu] != "") { echo("MTU $interface[ifMtu]"); } else { echo("-"); } + if($interface['ifMtu'] && $interface['ifMtu'] != "") { echo("MTU " . $interface['ifMtu'] . ""); } else { echo("-"); } -# if($interface[ifDuplex] != unknown) { echo("Duplex $interface[ifDuplex]"); } else { echo("-"); } +# if($interface[ifDuplex] != unknown) { echo("Duplex " . $interface['ifDuplex'] . ""); } else { echo("-"); } } echo(""); echo(""); - if ( strpos($inf, "oopback") === false && !$dographs) { - $link_query = mysql_query("select I.if, D.hostname, D.id AS dev_id, I.id from links AS L, interfaces AS I, devices AS D WHERE L.src_if = '$if_id' AND L.dst_if = I.id AND I.host = D.id"); + if ( strpos($ifDescr, "oopback") === false && !$dographs) { + $link_query = mysql_query("select I.ifDescr, D.hostname, D.id, I.interface_id from links AS L, interfaces AS I, devices AS D WHERE L.src_if = '$if_id' AND L.dst_if = I.interface_id AND I.device_id = D.id"); while($link = mysql_fetch_array($link_query)) { echo("Directly Connected " . generateiflink($link) . " on " . generatedevicelink($link) . "
"); $br = "
"; } unset($br); $adj_sql = "SELECT * FROM networks AS N, interfaces AS I, adjacencies AS A "; - $adj_sql = $adj_sql . "WHERE I.id = A.interface_id AND A.network_id = N.id "; - $adj_sql = $adj_sql . "AND I.id = '$if_id'"; + $adj_sql = $adj_sql . "WHERE I.interface_id = A.interface_id AND A.network_id = N.id "; + $adj_sql = $adj_sql . "AND I.interface_id = '$if_id'"; $adj_query = mysql_query("$adj_sql"); while($adjs = mysql_fetch_array($adj_query)) { $network_id = $adjs['network_id']; - $newsql = "SELECT *, I.id AS iid, D.id AS did FROM adjacencies AS A, networks as N, interfaces as I, devices as D "; - $newsql = $newsql . "WHERE N.id = '$network_id' AND A.network_id = N.id AND I.id = A.interface_id AND D.id = I.host "; - $newsql = $newsql . "AND D.id != '$device[id]' AND I.if NOT LIKE '%loopback%' GROUP BY D.id ORDER BY D.hostname"; + $newsql = "SELECT *, I.interface_id AS iid, D.id AS did FROM adjacencies AS A, networks as N, interfaces as I, devices as D "; + $newsql = $newsql . "WHERE N.id = '$network_id' AND A.network_id = N.id AND I.interface_id = A.interface_id AND D.id = I.device_id "; + $newsql = $newsql . "AND D.id != '$device[id]' AND I.ifDescr NOT LIKE '%loopback%' GROUP BY D.id ORDER BY D.hostname"; $new_query = mysql_query($newsql); while($new = mysql_fetch_array($new_query)) { if ($new['status'] == '0') { $class = "red"; } else { $class = "blue"; } @@ -67,7 +68,7 @@ echo(""); $this_ifid = $new['iid']; $this_hostid = $new['did']; $this_hostname = $new['hostname']; - $this_ifname = fixifName($new['if']); + $this_ifname = fixifName($new['ifDescr']); $wq = mysql_query("select count(*) FROM links WHERE dst_if = '$this_ifid' AND src_if = $if_id;"); if (@mysql_result($wq, 0) == '0' && $this_hostname != $hostname) { $graph_url = "graph.php?if=$this_ifid&from=$twoday&to=$now&width=400&height=120&type=bits"; diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index 6e5947512..f7698d3e3 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -1,7 +1,7 @@ Overview "); -if(mysql_result(mysql_query("select count(id) from interfaces WHERE host = '$device[id]'"), 0) > '0') { +if(@mysql_result(mysql_query("select count(interface_id) from interfaces WHERE device_id = '$device[id]'"), 0) > '0') { echo("
  • diff --git a/html/pages/device/dev-ifs.inc b/html/pages/device/dev-ifs.inc index ba0f2cf85..5d9fe9447 100644 --- a/html/pages/device/dev-ifs.inc +++ b/html/pages/device/dev-ifs.inc @@ -4,7 +4,7 @@ $hostname = gethostbyid($_GET[id]); echo("
    "); $i = "1"; - $interface_query = mysql_query("select * from interfaces WHERE host = '$_GET[id]' ORDER BY 'ifIndex'"); + $interface_query = mysql_query("select * from interfaces WHERE device_id = '$_GET[id]' ORDER BY 'ifIndex'"); while($interface = mysql_fetch_array($interface_query)) { include("includes/print-interface.inc"); } diff --git a/html/pages/device/dev-overview.inc b/html/pages/device/dev-overview.inc index dd4126acd..e69005302 100644 --- a/html/pages/device/dev-overview.inc +++ b/html/pages/device/dev-overview.inc @@ -6,10 +6,10 @@ $id = $_GET[id]; $device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE id = '$_GET[id]'")); -$interfaces['total'] = mysql_result(mysql_query("SELECT count(id) FROM interfaces WHERE host = '$id'"),0); -$interfaces['up'] = mysql_result(mysql_query("SELECT count(id) FROM interfaces WHERE host = '$id' AND up = 'up'"),0); -$interfaces['down'] = mysql_result(mysql_query("SELECT count(id) FROM interfaces WHERE host = '$id' AND up = 'down' AND up_admin = 'up'"),0); -$interfaces['disabled'] = mysql_result(mysql_query("SELECT count(id) FROM interfaces WHERE host = '$id' AND up_admin = 'down'"),0); +$interfaces['total'] = mysql_result(mysql_query("SELECT count(*) FROM interfaces WHERE device_id = '$id'"),0); +$interfaces['up'] = mysql_result(mysql_query("SELECT count(*) FROM interfaces WHERE device_id = '$id' AND ifOperStatus = 'up'"),0); +$interfaces['down'] = mysql_result(mysql_query("SELECT count(*) FROM interfaces WHERE device_id = '$id' AND ifOperStatus = 'down' AND ifAdminStatus = 'up'"),0); +$interfaces['disabled'] = mysql_result(mysql_query("SELECT count(*) FROM interfaces WHERE device_id = '$id' AND ifAdminStatus = 'down'"),0); $services['total'] = mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_host = '$id'"),0); $services['up'] = mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_host = '$id' AND service_status = '1' AND service_ignore ='0'"),0); @@ -69,7 +69,7 @@ echo(" echo("
    "); - $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("
    \n"); + echo("\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'"); ?> + +
    DeviceInterfaceSpe $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]
    $dev_link$if_link$speed$type" . $interface[ifAlias] . "