mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
updated vlan detection
git-svn-id: http://www.observium.org/svn/observer/trunk@3113 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -5,7 +5,7 @@ if (!is_integer($i/2)) { $bg_colour = $list_colour_a; } else { $bg_colour = $lis
|
||||
echo("<tr bgcolor='$bg_colour'>");
|
||||
|
||||
echo("<td width=100 class=list-large> Vlan " . $vlan['vlan_vlan'] . "</td>");
|
||||
echo("<td width=200 class=box-desc>" . $vlan['vlan_descr'] . "</td>");
|
||||
echo("<td width=200 class=box-desc>" . $vlan['vlan_name'] . "</td>");
|
||||
echo("<td class=list-bold>");
|
||||
|
||||
$vlan_ports = array();
|
||||
|
@@ -120,8 +120,8 @@ $config['snmp']['transports'] = array('udp', 'udp6', 'tcp', 'tcp6');
|
||||
### Or if one had a very fast I/O subsystem with no performance worries.
|
||||
|
||||
$config['rrd_rra'] = " RRA:AVERAGE:0.5:1:2016 RRA:AVERAGE:0.5:6:1440 RRA:AVERAGE:0.5:24:1440 RRA:AVERAGE:0.5:288:1440 ";
|
||||
$config['rrd_rra'] .= " RRA:MIN:0.5:6:1440 RRA:MIN:0.5:24:775 RRA:MIN:0.5:288:797 ";
|
||||
$config['rrd_rra'] .= " RRA:MAX:0.5:6:1440 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797 ";
|
||||
$config['rrd_rra'] .= " RRA:MAX:0.5:1:720 RRA:MIN:0.5:6:1440 RRA:MIN:0.5:24:775 RRA:MIN:0.5:288:797 ";
|
||||
$config['rrd_rra'] .= " RRA:MAX:0.5:1:720 RRA:MAX:0.5:6:1440 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797 ";
|
||||
$config['rrd_rra'] .= " RRA:LAST:0.5:1:1440 ";
|
||||
|
||||
### Autodiscovery Settings
|
||||
|
@@ -4,43 +4,31 @@ if ($device['os_group'] == "cisco")
|
||||
{
|
||||
echo("Cisco VLANs : ");
|
||||
|
||||
$vtpversion_cmd = $config['snmpget'] . " -M " . $config['mibdir'] . " -m CISCO-VTP-MIB -Oqv -" . $device['snmpver'] . " -c " . $device['community'] . " ";
|
||||
$vtpversion_cmd .= $device['hostname'].":".$device['port'] . " .1.3.6.1.4.1.9.9.46.1.1.1.0";
|
||||
$vtpversion = trim(`$vtpversion_cmd 2>/dev/null`);
|
||||
|
||||
if ($vtpversion == '1' || $vtpversion == '2' || $vtpversion == '3' || $vtpversion == 'one' || $vtpversion == 'two' || $vtpversion == 'three')
|
||||
/// Not sure why we check for VTP, but this data comes from that MIB, so...
|
||||
$vtpversion = snmp_get($device, "vtpVersion.0" , "-OnvQ", "CISCO-VTP-MIB");
|
||||
if ($vtpversion == '1' || $vtpversion == '2' || $vtpversion == '3' || $vtpversion == 'one' || $vtpversion == 'two' || $vtpversion == 'three')
|
||||
{
|
||||
$vtp_domain_cmd = $config['snmpget'] . " -M " . $config['mibdir'] . " -m CISCO-VTP-MIB -Oqv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'];
|
||||
$vtp_domain_cmd .= " .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("VTP v$vtpversion $vtp_domain ");
|
||||
## FIXME - can have multiple VTP domains.
|
||||
$vtpdomains = snmpwalk_cache_oid($device, "vlanManagementDomains", array(), "CISCO-VTP-MIB");
|
||||
$vlans = snmpwalk_cache_twopart_oid($device, "vtpVlanEntry", array(), "CISCO-VTP-MIB");
|
||||
|
||||
$vlans_cmd = $config['snmpwalk'] . " -M " . $config['mibdir'] . " -m CISCO-VTP-MIB -O qn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " ";
|
||||
$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\" \"";
|
||||
|
||||
$vlans = trim(`$vlans_cmd | grep -v o`);
|
||||
|
||||
foreach (explode("\n", $vlans) as $vlan)
|
||||
foreach($vtpdomains as $vtpdomain_id => $vtpdomain)
|
||||
{
|
||||
$vlan_descr_cmd = $config['snmpget'] . " -M " . $config['mibdir'] . " -m CISCO-VTP-MIB -O nvq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " ";
|
||||
$vlan_descr_cmd .= ".1.3.6.1.4.1.9.9.46.1.3.1.1.4.1." . $vlan;
|
||||
$vlan_descr = shell_exec($vlan_descr_cmd);
|
||||
|
||||
$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("VTP Domain ".$vtpdomain_id." ".$vtpdomain['managementDomainName']." ");
|
||||
foreach ($vlans[$vtpdomain_id] as $vlan_id => $vlan)
|
||||
{
|
||||
mysql_query("INSERT INTO `vlans` (`device_id`,`vlan_domain`,`vlan_vlan`, `vlan_descr`) VALUES (" . $device['device_id'] . ",'" . mres($vtp_domain) . "','$vlan', '" . mres($vlan_descr) . "')");
|
||||
echo("+");
|
||||
} else {
|
||||
echo(".");
|
||||
mysql_query("UPDATE `vlans` SET `vlan_descr`='" . mres($vlan_descr) . "' WHERE `device_id`='" . $device['device_id'] . "' AND `vlan_vlan`='" . $vlan . "' AND `vlan_domain`='" . $vtp_domain . "'");
|
||||
echo(" $vlan_id");
|
||||
if (is_array($vlans_db[$vtpdomain_id][$vlan_id]))
|
||||
{
|
||||
echo(".");
|
||||
} else {
|
||||
dbInsert(array('device_id' => $device['device_id'], 'vlan_domain' => $vtpdomain_id, 'vlan_vlan' => $vlan_id, 'vlan_name' => $vlan['vtpVlanName'], 'vlan_type' => $vlan['vtpVlanType']), 'vlans');
|
||||
echo("+");
|
||||
}
|
||||
$device['vlans'][$vtpdomain_id][$vlan_id] = $vlan_id;
|
||||
}
|
||||
|
||||
$this_vlans[] = $vlan;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo("\n");
|
||||
|
@@ -8,29 +8,21 @@ if ($vlanversion == 'version1')
|
||||
{
|
||||
echo("VLAN $vlanversion ");
|
||||
|
||||
$vlans = snmp_walk($device, "dot1qVlanFdbId", "-Oqn", "Q-BRIDGE-MIB");
|
||||
$vtpdomain_id = "1";
|
||||
$vlans = snmpwalk_cache_oid($device, "dot1qVlanStaticName", array(), "Q-BRIDGE-MIB");
|
||||
|
||||
$vlan_array = snmpwalk_cache_multi_oid($device, "dot1qVlanStaticName", $vlan_array, "Q-BRIDGE-MIB");
|
||||
|
||||
foreach (explode("\n", $vlans) as $vlan_oid)
|
||||
{
|
||||
list($oid,$vlan_index) = explode(' ',$vlan_oid);
|
||||
$oid_ex = explode('.',$oid);
|
||||
$vlan = $oid_ex[count($oid_ex)-1];
|
||||
|
||||
$vlan_descr = trim(str_replace("\"", "", $vlan_array[$vlan]['dot1qVlanStaticName']));
|
||||
|
||||
if (mysql_result(mysql_query("SELECT COUNT(vlan_id) FROM `vlans` WHERE `device_id` = '" . $device['device_id'] . "' AND `vlan_domain` = '' AND `vlan_vlan` = '" . $vlan . "'"), 0) == '0')
|
||||
{
|
||||
mysql_query("INSERT INTO `vlans` (`device_id`,`vlan_domain`,`vlan_vlan`, `vlan_descr`) VALUES (" . $device['device_id'] . ",'','$vlan', '" . mres($vlan_descr) . "')");
|
||||
echo("+");
|
||||
} else {
|
||||
mysql_query("UPDATE `vlans` SET `vlan_descr`='" . mres($vlan_descr) . "' WHERE `device_id`='" . $device['device_id'] . "' AND `vlan_vlan`='" . $vlan . "'");
|
||||
echo(".");
|
||||
}
|
||||
|
||||
$this_vlans[] = $vlan;
|
||||
}
|
||||
foreach ($vlans as $vlan_id => $vlan)
|
||||
{
|
||||
echo(" $vlan_id");
|
||||
if (is_array($vlans_db[$vtpdomain_id][$vlan_id]))
|
||||
{
|
||||
echo(".");
|
||||
} else {
|
||||
dbInsert(array('device_id' => $device['device_id'], 'vlan_domain' => $vtpdomain_id, 'vlan_vlan' => $vlan_id, 'vlan_name' => $vlan['dot1qVlanStaticName'], 'vlan_type' => array('NULL')), 'vlans');
|
||||
echo("+");
|
||||
}
|
||||
$device['vlans'][$vtpdomain_id][$vlan_id] = $vlan_id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,88 +2,91 @@
|
||||
|
||||
echo("VLANs:\n");
|
||||
|
||||
$this_vlans = array();
|
||||
/// Pre-cache the existing state of VLANs for this device from the database
|
||||
$vlans_db_raw = dbFetchRows("SELECT * FROM `vlans` WHERE `device_id` = ?", array($device['device_id']));
|
||||
foreach($vlans_db_raw as $vlan_db)
|
||||
{
|
||||
$vlans_db[$vlan_db['vlan_domain']][$vlan_db['vlan_vlan']] = $vlan_db;
|
||||
}
|
||||
|
||||
/// Create an empty array to record what VLANs we discover this session.
|
||||
$device['vlans'] = array();
|
||||
|
||||
include("includes/discovery/q-bridge-mib.inc.php");
|
||||
include("includes/discovery/cisco-vlans.inc.php");
|
||||
|
||||
foreach ($this_vlans as $vlan)
|
||||
/// Fetch switchport <> VLAN relationships. This is DIRTY.
|
||||
foreach ($device['vlans'] as $domain_id => $vlans)
|
||||
{
|
||||
foreach ($vlans as $vlan_id => $vlan)
|
||||
{
|
||||
/// Pull Tables for this VLAN
|
||||
|
||||
#/usr/bin/snmpbulkwalk -v2c -c kglk5g3l454@988 -OQUs -m BRIDGE-MIB -M /opt/observium/mibs/ udp:sw2.ahf:161 dot1dStpPortEntry
|
||||
#/usr/bin/snmpbulkwalk -v2c -c kglk5g3l454@988 -OQUs -m BRIDGE-MIB -M /opt/observium/mibs/ udp:sw2.ahf:161 dot1dBasePortEntry
|
||||
#/usr/bin/snmpbulkwalk -v2c -c kglk5g3l454@988 -OQUs -m BRIDGE-MIB -M /opt/observium/mibs/ udp:sw2.ahf:161 dot1dStpPortEntry
|
||||
#/usr/bin/snmpbulkwalk -v2c -c kglk5g3l454@988 -OQUs -m BRIDGE-MIB -M /opt/observium/mibs/ udp:sw2.ahf:161 dot1dBasePortEntry
|
||||
|
||||
if (is_numeric($vlan) && ($vlan <1002 || $vlan > 1105)) /// Ignore reserved VLAN IDs
|
||||
{
|
||||
|
||||
if ($device['os_group'] == "cisco" || $device['os'] == "ios") /// This shit only seems to work on IOS
|
||||
### FIXME - do this only when vlan type == ethernet?
|
||||
if (is_numeric($vlan_id) && ($vlan_id <1002 || $vlan_id > 1105)) /// Ignore reserved VLAN IDs
|
||||
{
|
||||
$vlan_device = array_merge($device, array('community' => $device['community']."@".$vlan));
|
||||
$vlan_data = snmpwalk_cache_oid($vlan_device, "dot1dStpPortEntry", array(), "BRIDGE-MIB:Q-BRIDGE-MIB");
|
||||
$vlan_data = snmpwalk_cache_oid($vlan_device, "dot1dBasePortEntry", $vlan_data, "BRIDGE-MIB:Q-BRIDGE-MIB");
|
||||
}
|
||||
|
||||
echo("VLAN $vlan \n");
|
||||
|
||||
if ($vlan_data)
|
||||
{
|
||||
echo(str_pad("dot1d id", 10).str_pad("ifIndex", 10).str_pad("Port Name", 25).
|
||||
str_pad("Priority", 10).str_pad("State", 15).str_pad("Cost", 10)."\n");
|
||||
}
|
||||
|
||||
foreach ($vlan_data as $vlan_port_id => $vlan_port)
|
||||
{
|
||||
$port = get_port_by_index_cache($device, $vlan_port['dot1dBasePortIfIndex']);
|
||||
echo(str_pad($vlan_port_id, 10).str_pad($vlan_port['dot1dBasePortIfIndex'], 10).
|
||||
str_pad($port['ifDescr'],25).str_pad($vlan_port['dot1dStpPortPriority'], 10).
|
||||
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'],
|
||||
'vlan' => $vlan);
|
||||
|
||||
$db_a = array('baseport' => $vlan_port_id,
|
||||
'priority' => $vlan_port['dot1dStpPortPriority'],
|
||||
'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));
|
||||
|
||||
if ($from_db['port_vlan_id'])
|
||||
if ($device['os_group'] == "cisco" || $device['os'] == "ios") /// This shit only seems to work on IOS
|
||||
{
|
||||
dbUpdate($db_a, 'ports_vlans', "`port_vlan_id` = ?", $from_db['port_vlan_id']);
|
||||
echo("Updated");
|
||||
} else {
|
||||
dbInsert(array_merge($db_w, $db_a), 'ports_vlans');
|
||||
echo("Inserted");
|
||||
$vlan_device = array_merge($device, array('community' => $device['community']."@".$vlan_id));
|
||||
$vlan_data = snmpwalk_cache_oid($vlan_device, "dot1dStpPortEntry", array(), "BRIDGE-MIB:Q-BRIDGE-MIB");
|
||||
$vlan_data = snmpwalk_cache_oid($vlan_device, "dot1dBasePortEntry", $vlan_data, "BRIDGE-MIB:Q-BRIDGE-MIB");
|
||||
}
|
||||
|
||||
echo("\n");
|
||||
echo("VLAN $vlan_id \n");
|
||||
|
||||
if ($vlan_data)
|
||||
{
|
||||
echo(str_pad("dot1d id", 10).str_pad("ifIndex", 10).str_pad("Port Name", 25).
|
||||
str_pad("Priority", 10).str_pad("State", 15).str_pad("Cost", 10)."\n");
|
||||
}
|
||||
|
||||
foreach ($vlan_data as $vlan_port_id => $vlan_port)
|
||||
{
|
||||
$port = get_port_by_index_cache($device, $vlan_port['dot1dBasePortIfIndex']);
|
||||
echo(str_pad($vlan_port_id, 10).str_pad($vlan_port['dot1dBasePortIfIndex'], 10).
|
||||
str_pad($port['ifDescr'],25).str_pad($vlan_port['dot1dStpPortPriority'], 10).
|
||||
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'],
|
||||
'vlan' => $vlan_id);
|
||||
|
||||
$db_a = array('baseport' => $vlan_port_id,
|
||||
'priority' => $vlan_port['dot1dStpPortPriority'],
|
||||
'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));
|
||||
|
||||
if ($from_db['port_vlan_id'])
|
||||
{
|
||||
dbUpdate($db_a, 'ports_vlans', "`port_vlan_id` = ?", $from_db['port_vlan_id']);
|
||||
echo("Updated");
|
||||
} else {
|
||||
dbInsert(array_merge($db_w, $db_a), 'ports_vlans');
|
||||
echo("Inserted");
|
||||
}
|
||||
echo("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($vlan_data);
|
||||
|
||||
}
|
||||
|
||||
$device_vlans = mysql_query("SELECT * FROM `vlans` WHERE `device_id` = '" . $device['device_id'] . "'");
|
||||
while ($dev_vlan = mysql_fetch_assoc($device_vlans))
|
||||
|
||||
foreach($vlans_db as $domain_id => $vlans)
|
||||
{
|
||||
unset($vlan_exists);
|
||||
foreach ($this_vlans as $test_vlan)
|
||||
foreach($vlans as $vlan_id => $vlan)
|
||||
{
|
||||
if ($test_vlan == $dev_vlan['vlan_vlan']) { $vlan_exists = 1; }
|
||||
}
|
||||
if (!$vlan_exists)
|
||||
{
|
||||
mysql_query("DELETE FROM `vlans` WHERE `vlan_id` = '" . $dev_vlan['vlan_id'] . "'");
|
||||
echo("-");
|
||||
if ($debug) { echo("Deleted VLAN ". $dev_vlan['vlan_vlan'] ."\n"); }
|
||||
if(empty($device['vlans'][$domain_id][$vlan_id]))
|
||||
{
|
||||
dbDelete('vlans', "`device_id` = ? AND vlan_domain = ? AND vlan_vlan = ?", array($device['device_id'], $domain_id, $vlan_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($this_vlans);
|
||||
unset($device['vlans']);
|
||||
|
||||
?>
|
||||
|
@@ -42,18 +42,23 @@ if ($dataHandle)
|
||||
} else {
|
||||
if ($cur != $data)
|
||||
{
|
||||
echo("Current Version : $cur_omnipotence.$cur_year.$cur_month.$cur_revision \n");
|
||||
echo("Current Revision : $cur_revision\n");
|
||||
|
||||
if ($omnipotence > $cur_omnipotence)
|
||||
if ($omnipotence > $cur_revision)
|
||||
{
|
||||
echo("New version : $omnipotence.$year.$month.$revision\n");
|
||||
} elseif ($year > $cur_year) {
|
||||
echo("New version : $omnipotence.$year.$month.$revision\n");
|
||||
} elseif ($month > $cur_month) {
|
||||
echo("New version : $omnipotence.$year.$month.$revision\n");
|
||||
} elseif ($revision > $cur_revision) {
|
||||
echo("New release : $omnipotence.$year.$month.$revision\n");
|
||||
echo("New Revision : $omnipotence\n");
|
||||
}
|
||||
|
||||
# if ($omnipotence > $cur_omnipotence)
|
||||
# {
|
||||
# echo("New version : $omnipotence.$year.$month.$revision\n");
|
||||
# } elseif ($year > $cur_year) {
|
||||
# echo("New version : $omnipotence.$year.$month.$revision\n");
|
||||
# } elseif ($month > $cur_month) {
|
||||
# echo("New version : $omnipotence.$year.$month.$revision\n");
|
||||
# } elseif ($revision > $cur_revision) {
|
||||
# echo("New release : $omnipotence.$year.$month.$revision\n");
|
||||
# }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
4
sql-schema/016.sql
Normal file
4
sql-schema/016.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
ALTER TABLE `vlans` ADD `vlan_type` VARCHAR( 16 ) NULL;
|
||||
ALTER TABLE `vlans` CHANGE `vlan_domain` `vlan_domain` INT NULL DEFAULT NULL;
|
||||
ALTER TABLE `vlans` CHANGE `vlan_descr` `vlan_name` VARCHAR( 32 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL;
|
||||
ALTER TABLE `vlans` ADD `vlan_mtu` INT NULL;
|
Reference in New Issue
Block a user