pseudowire reworking. add device tab (no wonder no one ever asked about it, damn tab was missing!)

git-svn-id: http://www.observium.org/svn/observer/trunk@3116 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2012-05-02 17:23:27 +00:00
parent dc66830e95
commit 944130f0bb
4 changed files with 144 additions and 58 deletions
+11
View File
@@ -217,6 +217,17 @@ if (device_permitted($vars['device']) || $check_device == $vars['device'])
</li>');
}
$device_pw_count = @dbFetchCell("SELECT COUNT(*) FROM `pseudowires` WHERE `device_id` = ?", array($device['device_id']));
if ($device_routing_count)
{
echo('<li class="' . $select['pseudowires'] . '">
<a href="'.generate_device_url($device, array('tab' => 'pseudowires')).'">
<img src="images/16/arrow_switch.png" align="absmiddle" border="0" /> Pseudowires
</a>
</li>');
}
if ($_SESSION['userlevel'] >= "5" && dbFetchCell("SELECT COUNT(*) FROM links AS L, ports AS I WHERE I.device_id = '".$device['device_id']."' AND I.interface_id = L.local_interface_id"))
{
$discovery_links = TRUE;
+97
View File
@@ -0,0 +1,97 @@
<?php
$pagetitle[] = "Pseudowires";
if(!isset($vars['view'])) { $vars['view'] = 'detail'; }
$link_array = array('page' => 'pseudowires');
print_optionbar_start();
echo('<span style="font-weight: bold;">Pseudowires</span> &#187; ');
if ($vars['view'] == "detail") { echo('<span class="pagemenu-selected">'); }
echo(generate_link("Details",$link_array,array('view'=> 'detail')));
if ($vars['view'] == "detail") { echo('</span>'); }
echo(" | ");
if ($vars['view'] == "minigraphs") { echo('<span class="pagemenu-selected">'); }
echo(generate_link("Mini Graphs",$link_array,array('view' => "minigraphs")));
if ($vars['view'] == "minigraphs") { echo('</span>'); }
print_optionbar_end();
echo("<table cellpadding=5 cellspacing=0 class=devicetable width=100%>");
foreach (dbFetchRows("SELECT * FROM pseudowires AS P, ports AS I WHERE P.interface_id = I.interface_id AND I.device_id = ? ORDER BY I.ifDescr", array($device['device_id'])) as $pw_a)
{
$i = 0;
while ($i < count($linkdone))
{
$thislink = $pw_a['device_id'] . $pw_a['interface_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']));
if (!port_permitted($pw_a['interface_id'])) { $skip = "yes"; }
if (!port_permitted($pw_b['interface_id'])) { $skip = "yes"; }
if ($skip)
{
unset($skip);
} else {
if ($bg == "ffffff") { $bg = "e5e5e5"; } else { $bg="ffffff"; }
echo("<tr style=\"background-color: #$bg;\"><td rowspan=2 style='font-size:18px; padding:4px;'>".$pw_a['cpwVcID']."</td><td>".generate_port_link($pw_a)."</td>
<td rowspan=2> <img src='images/16/arrow_right.png'> </td>
<td>".generate_device_link($pw_b)."</td><td>".generate_port_link($pw_b)."</td></tr>");
echo("<tr style=\"background-color: #$bg;\"><td colspan=2>".$pw_a['ifAlias']."</td><td>".$pw_b['ifAlias']."</td></tr>");
if ($vars['view'] == "minigraphs")
{
echo("<tr style=\"background-color: #$bg;\"><td></td><td colspan=2>");
if ($pw_a)
{
$pw_a['width'] = "150";
$pw_a['height'] = "30";
$pw_a['from'] = $day;
$pw_a['to'] = $now;
$pw_a['bg'] = $bg;
$types = array('bits','upkts','errors');
foreach ($types as $graph_type)
{
$pw_a['graph_type'] = "port_".$graph_type;
generate_port_thumbnail($pw_a);
}
}
echo("</td><td></td><td colspan=2>");
if ($pw_b)
{
$pw_b['width'] = "150";
$pw_b['height'] = "30";
$pw_b['from'] = $day;
$pw_b['to'] = $now;
$pw_b['bg'] = $bg;
$types = array('bits','upkts','errors');
foreach ($types as $graph_type)
{
$pw_b['graph_type'] = "port_".$graph_type;
generate_port_thumbnail($pw_b);
}
}
echo("</td></tr>");
}
$linkdone[] = $pw_b['device_id'] . $pw_b['interface_id'];
}
}
echo("</table>");
?>
+34 -53
View File
@@ -7,71 +7,52 @@ if ($config['enable_pseudowires'] && $device['os_group'] == "cisco")
echo("Cisco Pseudowires : ");
# FIXME snmp_walk
$oids = shell_exec($config['snmpwalk'] . " -M " . $config['mibdir'] . " -m CISCO-IETF-PW-MIB -CI -Ln -Osqn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " cpwVcID");
$oids = str_replace(".1.3.6.1.4.1.9.10.106.1.2.1.10.", "", $oids);
$oids = trim($oids);
foreach (explode("\n", $oids) as $oid)
/// Pre-cache the existing state of pseudowires for this device from the database
$pws_db_raw = dbFetchRows("SELECT * FROM `pseudowires` WHERE `device_id` = ?", array($device['device_id']));
foreach($pws_db_raw as $pw_db)
{
if ($oid)
{
list($cpwOid, $cpwVcID) = explode(" ", $oid);
$device['pws_db'][$pw_db['cpwVcID']] = $pw_db['pseudowire_id'];
}
unset($pws_db_raw); unset($pw_db);
if ($cpwOid)
{
list($cpw_remote_id) = explode(":", shell_exec($config['snmpget'] . " -M " . $config['mibdir'] . " -m CISCO-IETF-PW-MPLS-MIB -Ln -Osqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " cpwVcMplsPeerLdpID." . $cpwOid));
$interface_descr = trim(shell_exec($config['snmpwalk'] . " -M " . $config['mibdir'] . " -m CISCO-IETF-PW-MIB -Oqvn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " cpwVcName." . $cpwOid));
$pws = snmpwalk_cache_oid($device, "cpwVcID", array(), "CISCO-IETF-PW-MPLS-MIB");
$pws = snmpwalk_cache_oid($device, "cpwVcName", $pws, "CISCO-IETF-PW-MPLS-MIB");
$pws = snmpwalk_cache_oid($device, "cpwVcType", $pws, "CISCO-IETF-PW-MPLS-MIB");
$pws = snmpwalk_cache_oid($device, "cpwVcPsnType", $pws, "CISCO-IETF-PW-MPLS-MIB");
$pws = snmpwalk_cache_oid($device, "cpwVcDescr", $pws, "CISCO-IETF-PW-MPLS-MIB");
/// For MPLS pseudowires
$pws = snmpwalk_cache_oid($device, "cpwVcMplsPeerLdpID", $pws, "CISCO-IETF-PW-MPLS-MIB");
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` = '$interface_descr' AND `device_id` = '".$device['device_id']."'"),0);
$if_id = @mysql_result(mysql_query("SELECT `interface_id` FROM `ports` WHERE `ifDescr` = '".$pw['cpwVcName']."' AND `device_id` = '".$device['device_id']."'"),0);
if ($cpw_remote_device && $if_id)
if (!empty($device['pws_db'][$pw['cpwVcID']]))
{
$hostname = gethostbyid($cpw_remote_device);
#echo("\nOid: " . $cpwOid . " cpwVcID: " . $cpwVcID . " Remote Id: " . $cpw_remote_id . "($hostname(".$cpw_remote_device.") -> $interface_descr($if_id))");
if (mysql_result(mysql_query("SELECT count(*) FROM pseudowires WHERE `interface_id` = '$if_id'
AND `cpwVcID`='".$cpwVcID."'"),0))
{
echo(".");
}
else
{
$insert_query = "INSERT INTO `pseudowires` (`interface_id`,`peer_device_id`,`peer_ldp_id`,`cpwVcID`,`cpwOid`) ";
$insert_query .= "VALUES ('$if_id','$cpw_remote_device','$cpw_remote_id','$cpwVcID', '$cpwOid')";
mysql_query($insert_query);
echo("+");
#echo($device['device_id'] . " $cpwOid $cpw_remote_device $if_id $cpwVcID\n");
}
$cpw_exists[] = $device['device_id'] . " $cpwOid $cpw_remote_device $if_id $cpwVcID";
$pseudowire_id = $device['pws_db'][$pw['cpwVcID']];
echo(".");
}
}
}
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,
'cpwVcID' => $pw['cpwVcID'], 'cpwOid' => $pw_id, 'pw_type' => $pw['cpwVcType'], 'pw_descr' => $pw['cpwVcDescr'], 'pw_psntype' => $pw['cpwVcPsnType']), 'pseudowires');
echo("+");
}
$device['pws'][$pw['cpwVcID']] = $pseudowire_id;
}
$sql = "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 AND D.device_id = '".$device['device_id']."'";
$query = mysql_query($sql);
while ($cpw = mysql_fetch_assoc($query))
/// Cycle the list of pseudowires we cached earlier and make sure we saw them again.
foreach($device['pws_db'] as $pw_id => $pseudowire_id)
{
unset($exists);
$i = 0;
while ($i < count($cpw_exists) && !$exists)
if(empty($device['pws'][$pw_id]))
{
$this_cpw = $cpw['device_id'] . " " . $cpw['cpwOid'] . " " . $cpw['peer_device_id'] . " " . $cpw['interface_id'] . " " . $cpw['cpwVcID'];
if ($cpw_exists[$i] == $this_cpw) { $exists = 1;
# echo($cpw_exists[$i]. " || $this_cpw \n");
}
$i++;
}
if (!$exists)
{
echo("-");
# echo($this_cpw . "\n");
mysql_query("DELETE FROM pseudowires WHERE pseudowire_id = '" . $cpw['pseudowire_id'] . "'");
dbDelete('vlans', "`pseudowire_id` = ?", array($pseudowire_id));
}
}
echo("\n");
} # enable_pseudowires + os_group=cisco
+2 -5
View File
@@ -32,11 +32,6 @@
if (isset($entity_array['$entPhysicalIndex']['0']['entAliasMappingIdentifier'])) { $ifIndex = $entity_array['$entPhysicalIndex']['0']['entAliasMappingIdentifier']; }
# $ent_data = $config['snmpget'] . " -M ".$config['mibdir']." -m ENTITY-MIB:IF-MIB -Ovqs -";
# $ent_data .= $device['snmpver'] . " -M ".$config['mibdir']." -c " . $device['community'] . " " . $device['hostname'] .":".$device['port'];
# $ent_data .= " entAliasMappingIdentifier." . $entPhysicalIndex. ".0";
# $ifIndex = shell_exec($ent_data);
if (!strpos($ifIndex, "fIndex") || $ifIndex == "") { unset($ifIndex); }
list(,$ifIndex) = explode(".", $ifIndex);
@@ -45,6 +40,8 @@
$entPhysicalModelName = $entPhysicalVendorTypes[$entPhysicalVendorType];
}
## FIXME - dbFacile
if ($entPhysicalDescr || $entPhysicalName)
{
$entPhysical_id = @mysql_result(mysql_query("SELECT entPhysical_id FROM `entPhysical` WHERE device_id = '".$device['device_id']."' AND entPhysicalIndex = '$entPhysicalIndex'"),0);