From eca1805886c2914b1d181c1aa2c816a4d6440456 Mon Sep 17 00:00:00 2001 From: Adam Amstrong Date: Sun, 15 Apr 2007 14:38:26 +0000 Subject: [PATCH] Lots of bugfixes, some new features - VLANS git-svn-id: http://www.observium.org/svn/observer/trunk@95 61d68cd4-352d-0410-923a-c4978735b2b8 --- cron-hourly.sh | 3 +- discover-cdp.php | 2 +- discover-vlans.php | 10 ++++- html/includes/print-interface.inc | 10 ++++- html/pages/device.php | 11 +++++ includes/{cdp.php => cdp.inc.php} | 0 poll-interface.php | 70 +++++-------------------------- 7 files changed, 42 insertions(+), 64 deletions(-) rename includes/{cdp.php => cdp.inc.php} (100%) diff --git a/cron-hourly.sh b/cron-hourly.sh index b1080bd087..c61aa450f4 100755 --- a/cron-hourly.sh +++ b/cron-hourly.sh @@ -1,7 +1,5 @@ #!/bin/bash ./cdp.php -./poll-reachability.php -./poll-os.php ./discover-ifs.php ./discover-nets.php ./ips.php @@ -10,3 +8,4 @@ ./discover-temperatures.php ./generate-map.sh ./discover-cisco-temp.php +./update-interface.php diff --git a/discover-cdp.php b/discover-cdp.php index d426bd2214..675b38f63f 100755 --- a/discover-cdp.php +++ b/discover-cdp.php @@ -3,7 +3,7 @@ include("config.php"); include("includes/functions.php"); -include("includes/cdp.php"); +include("includes/cdp.inc.php"); $device_query = mysql_query("SELECT * FROM `devices` WHERE `status` = '1' AND `os` = 'IOS' ORDER BY `device_id` DESC"); diff --git a/discover-vlans.php b/discover-vlans.php index 63d8063efb..1691b446e4 100644 --- a/discover-vlans.php +++ b/discover-vlans.php @@ -14,7 +14,10 @@ while ($device = mysql_fetch_array($device_query)) { if($vtpversion == '1' || $vtpversion == '2') { - echo("VLAN Trunking Protocol Version $vtpversion\n"); + $vtp_domain_cmd = "snmpget -Oqv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " .1.3.6.1.4.1.9.9.46.1.2.1.1.2.1"; + $vtp_domain = trim(str_replace("\"", "", `$vtp_domain_cmd 2>/dev/null`)); + + echo("VLAN Trunking Protocol Version $vtpversion Domain : $vtp_domain\n"); $vlans_cmd = "snmpwalk -O qn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " "; $vlans_cmd .= "1.3.6.1.4.1.9.9.46.1.3.1.1.2.1 | sed s/.1.3.6.1.4.1.9.9.46.1.3.1.1.2.1.//g | cut -f 1 -d\" \""; @@ -29,6 +32,11 @@ while ($device = mysql_fetch_array($device_query)) { $vlan_descr = trim(str_replace("\"", "", $vlan_descr)); + if(mysql_result(mysql_query("SELECT COUNT(vlan_id) FROM `vlans` WHERE `device_id` = '" . $device['device_id'] . "' AND `vlan_domain` = '" . $vtp_domain . "' AND `vlan_vlan` = '" . $vlan . "'"), 0) == '0') { + echo "Adding VLAN $vlan - $vlan_descr \n"; + mysql_query("INSERT INTO `vlans` (`device_id`,`vlan_domain`,`vlan_vlan`, `vlan_descr`) VALUES (" . $device['device_id'] . ",'" . $vtp_domain . "','$vlan', '$vlan_descr')"); + } + echo("VLAN $vlan ($vlan_descr)\n"); } diff --git a/html/includes/print-interface.inc b/html/includes/print-interface.inc index e1a735273d..3192adad01 100644 --- a/html/includes/print-interface.inc +++ b/html/includes/print-interface.inc @@ -34,7 +34,15 @@ echo(""); if($ifSpeed && $ifSpeed != "") { echo("$ifSpeed"); } echo("
"); - if($interface[ifDuplex] != unknown) { echo("Duplex " . $interface['ifDuplex'] . ""); } else { echo("-"); } +# if($interface[ifDuplex] != unknown) { echo("Duplex " . $interface['ifDuplex'] . ""); } else { echo("-"); } + + if($device['os'] == "IOS") { + + if($interface['ifTrunk']) { echo("" . $interface['ifTrunk'] . ""); + } elseif ($interface['ifVlan']) { echo("VLAN " . $interface['ifVlan'] . ""); } + + } + echo(""); if($ifType && $ifType != "") { echo("" . $ifType . ""); } else { echo("-"); } echo("
"); diff --git a/html/pages/device.php b/html/pages/device.php index 2f30ab4dca..92563ceb04 100644 --- a/html/pages/device.php +++ b/html/pages/device.php @@ -25,6 +25,16 @@ echo(" Overview "); + +if(@mysql_result(mysql_query("select count(vlan_id) from vlans WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0') { + echo(" +
  • + + VLANs + +
  • "); +} + if(@mysql_result(mysql_query("select count(interface_id) from interfaces WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0') { echo("
  • @@ -38,6 +48,7 @@ if(@mysql_result(mysql_query("select count(interface_id) from interfaces WHERE d
  • "); } + echo("
  • Host Graphs diff --git a/includes/cdp.php b/includes/cdp.inc.php similarity index 100% rename from includes/cdp.php rename to includes/cdp.inc.php diff --git a/poll-interface.php b/poll-interface.php index cd977e4ca8..3da0fc0d6d 100755 --- a/poll-interface.php +++ b/poll-interface.php @@ -12,30 +12,26 @@ while ($interface = mysql_fetch_array($interface_query)) { $device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE device_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']; - $snmp_cmd .= " 1.3.6.1.4.1.9.2.2.1.1.1." . $interface['ifIndex']; + unset($update); + unset($update_query); + unset($seperator); + + echo("Looking at " . $interface['ifDescr'] . " on " . $device['hostname'] . "\n"); + + $snmp_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname']; + $snmp_cmd .= " ifAdminStatus." . $interface['ifIndex'] . " ifOperStatus." . $interface['ifIndex'] . " ifAlias." . $interface['ifIndex']; $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); $snmp_output = str_replace("\"", "", $snmp_output); - echo("Looking at " . $interface['ifDescr'] . " on " . $device['hostname'] . "\n"); + list($ifAdminStatus, $ifOperStatus, $ifAlias) = explode("\n", $snmp_output); - list($ifName, $ifDescr, $ifAdminStatus, $ifOperStatus, $ifAlias, $ifSpeed, $ifDuplex, $ifType, $ifMtu, $ifPhysAddress, $ifHardType) = explode("\n", $snmp_output); - $ifDescr = trim(str_replace("\"", "", $ifDescr)); - if ($ifDuplex == 3) { $ifDuplex = "half"; } elseif ($ifDuplex == 2) { $ifDuplex = "full"; } else { $ifDuplex = "unknown"; } - $ifDescr = strtolower($ifDescr); if ($ifAlias == " ") { $ifAlias = str_replace(" ", "", $ifAlias); } $ifAlias = trim(str_replace("\"", "", $ifAlias)); $ifAlias = trim($ifAlias); - $ifPhysAddress = strtolower(str_replace("\"", "", $ifPhysAddress)); - $ifPhysAddress = str_replace(" ", ":", $ifPhysAddress); - $rrdfile = "rrd/" . $device['hostname'] . "." . $interface['ifIndex'] . ".rrd"; if(!is_file($rrdfile)) { $woo = `rrdtool create $rrdfile \ @@ -57,17 +53,8 @@ while ($interface = mysql_fetch_array($interface_query)) { RRA:MAX:0.5:288:797`; } - unset($update); - unset($update_query); - unset($seperator); - - if ( $interface['ifDescr'] != $ifDescr && $ifDescr != "" ) { - $update = "`if` = '$ifDescr'"; - $seperator = ", "; - mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Name -> " . $ifDescr . "')"); - } if ( $interface['ifAlias'] != $ifAlias ) { - $update .= $seperator . "`name` = '$ifAlias'"; + $update .= $seperator . "`ifAlias` = '$ifAlias'"; $seperator = ", "; mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Desc -> $ifAlias')"); } @@ -82,41 +69,6 @@ while ($interface = mysql_fetch_array($interface_query)) { if($ifAdminStatus == "up") { $admin = "enabled"; } else { $admin = "disabled"; } mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Interface $admin')"); } - if ( $interface['ifDuplex'] != $ifDuplex && $ifDuplex != "" ) { - $update .= $seperator . "`ifDuplex` = '$ifDuplex'"; - $seperator = ", "; - mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Duplex -> $ifDuplex')"); - } - if ( $interface['ifType'] != $ifType && $ifType != "" ) { - $update .= $seperator . "`ifType` = '$ifType'"; - $seperator = ", "; - mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Type -> $ifType')"); - } - if ( $interface['ifMtu'] != $ifMtu && $ifMtu != "" ) { - $update .= $seperator . "`ifMtu` = '$ifMtu'"; - $seperator = ", "; - mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'MTU -> $ifMtu')"); - } - if ( $interface['ifPhysAddress'] != $ifPhysAddress && $ifPhysAddress != "" ) { - $update .= $seperator . "`ifPhysAddress` = '$ifPhysAddress'"; - $seperator = ", "; - mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'MAC -> $ifPhysAddress')"); - } - - if ( $interface['ifHardType'] != $ifHardType && $ifHardType != "" ) { - $update .= $seperator . "`ifHardType` = '$ifHardType'"; - $seperator = ", "; - mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" .$interface['interface_id'] . "', NOW(), 'HW Type -> $ifHardType')"); - } - - - if ( $interface['ifSpeed'] != $ifSpeed && $ifSpeed != "" ) { - $update .= $seperator . "`ifSpeed` = '$ifSpeed'"; - $seperator = ", "; - $prev = humanspeed($interface['ifSpeed']); - $now = humanspeed($ifSpeed); - 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 "; @@ -125,7 +77,7 @@ while ($interface = mysql_fetch_array($interface_query)) { echo("Updating : " . $device['hostname'] . " $ifDescr\nSQL :$update_query\n\n"); $update_result = mysql_query($update_query); } else { - echo("Not Updating : " . $device['hostname'] ." $ifDescr ( " . $interface['ifDescr'] . " )\n\n"); +# echo("Not Updating : " . $device['hostname'] ." $ifDescr ( " . $interface['ifDescr'] . " )\n\n"); } if($ifOperStatus == "up") {