From 8bb0b4106ad1cb3645c506513065349386c439a9 Mon Sep 17 00:00:00 2001 From: Tom Laermans Date: Thu, 25 Nov 2010 15:32:47 +0000 Subject: [PATCH] no longer show broken graphs when there are none to be shown, indentation fixes git-svn-id: http://www.observium.org/svn/observer/trunk@1742 61d68cd4-352d-0410-923a-c4978735b2b8 --- html/pages/device/bgp.inc.php | 214 +++++++++++++++++++--------------- html/pages/iftype.inc.php | 88 +++++++------- 2 files changed, 167 insertions(+), 135 deletions(-) diff --git a/html/pages/device/bgp.inc.php b/html/pages/device/bgp.inc.php index 95787692d..13f548de7 100644 --- a/html/pages/device/bgp.inc.php +++ b/html/pages/device/bgp.inc.php @@ -1,91 +1,116 @@ - -
Local AS : " . $device['bgpLocalAs'] . "
-"); +
Local AS :
+ + No Graphs | - Updates | Prefixes: + Updates"); + +echo(" | Prefixes: IPv4 | VPNv4 | IPv6 - | Traffic: - Mac Accounting - + "); + +echo("| Traffic: + Mac Accounting"); + +echo(" "); + print_optionbar_end(); +?> - echo("
"); +
- $i = "1"; - $peer_query = mysql_query("select * from bgpPeers WHERE device_id = '".$device['device_id']."' ORDER BY bgpPeerRemoteAs, bgpPeerIdentifier"); - while($peer = mysql_fetch_array($peer_query)) { - unset($bg_image); - if(!is_integer($i/2)) { $bg_colour = $list_colour_a; } else { $bg_colour = $list_colour_b; } - #if($peer['bgpPeerAdminStatus'] == "start") { $img = "images/16/accept.png"; } else { $img = "images/16/delete.png"; } - if($peer['bgpPeerState'] == "established") { $col = "green"; } else { $col = "red"; $bg_image = "images/warning-background.png"; } - if($peer['bgpPeerAdminStatus'] == "start" || $peer['bgpPeerAdminStatus'] == "running") { $admin_col = "green"; } else { $admin_col = "red"; $bg_image = "images/warning-background.png"; } +iBGP"; } else { $peer_type = "eBGP"; } + if ($peer['bgpPeerRemoteAs'] == $device['bgpLocalAs']) { $peer_type = "iBGP"; } else { $peer_type = "eBGP"; } - $query = "SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE "; - $query .= "(A.ipv4_address = '".$peer['bgpPeerIdentifier']."' AND I.interface_id = A.interface_id)"; - $query .= " AND D.device_id = I.device_id"; - $ipv4_host = mysql_fetch_array(mysql_query($query)); + $query = "SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE "; + $query .= "(A.ipv4_address = '".$peer['bgpPeerIdentifier']."' AND I.interface_id = A.interface_id)"; + $query .= " AND D.device_id = I.device_id"; + $ipv4_host = mysql_fetch_assoc(mysql_query($query)); - $query = "SELECT * FROM ipv6_addresses AS A, ports AS I, devices AS D WHERE "; - $query .= "(A.ipv6_address = '".$peer['bgpPeerIdentifier']."' AND I.interface_id = A.interface_id)"; - $query .= " AND D.device_id = I.device_id"; - $ipv6_host = mysql_fetch_array(mysql_query($query)); + $query = "SELECT * FROM ipv6_addresses AS A, ports AS I, devices AS D WHERE "; + $query .= "(A.ipv6_address = '".$peer['bgpPeerIdentifier']."' AND I.interface_id = A.interface_id)"; + $query .= " AND D.device_id = I.device_id"; + $ipv6_host = mysql_fetch_assoc(mysql_query($query)); - if($ipv4_host) { - $peerhost = $ipv4_host; - } elseif($ipv6_host) { - $peerhost = $ipv6_host; - } else { unset($peerhost); } + if ($ipv4_host) + { + $peerhost = $ipv4_host; + } + elseif ($ipv6_host) + { + $peerhost = $ipv6_host; + } + else + { + unset($peerhost); + } - if($peerhost) { - $peername = generate_device_link($peerhost); - } else { - $peername = gethostbyaddr($peer['bgpPeerIdentifier']); - if($peername == $peer['bgpPeerIdentifier']) { - unset ($peername); - } else { - $peername = "".$peername.""; - } + if ($peerhost) + { + $peername = generate_device_link($peerhost); + } + else + { + $peername = gethostbyaddr($peer['bgpPeerIdentifier']); + if ($peername == $peer['bgpPeerIdentifier']) + { + unset($peername); + } else { + $peername = "".$peername.""; } + } - $af_query = mysql_query("SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['bgpPeerIdentifier']."'"); - unset($peer_af); - while($afisafi = mysql_fetch_array($af_query)) { - $afi = $afisafi['afi']; - $safi = $afisafi['safi']; - $peer_af .= $sep . $config['afi'][$afi][$safi]; ##### CLEAN ME UP, I AM MESSY AND I SMELL OF CHEESE! - $sep = "
"; - $valid_afi_safi[$afi][$safi] = 1; ## Build a list of valid AFI/SAFI for this peer - } + $af_query = mysql_query("SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['bgpPeerIdentifier']."'"); + unset($peer_af); - unset($sep); - echo("
- - + while ($afisafi = mysql_fetch_assoc($af_query)) + { + $afi = $afisafi['afi']; + $safi = $afisafi['safi']; + $peer_af .= $sep . $config['afi'][$afi][$safi]; ##### CLEAN ME UP, I AM MESSY AND I SMELL OF CHEESE! + $sep = "
"; + $valid_afi_safi[$afi][$safi] = 1; ## Build a list of valid AFI/SAFI for this peer + } + + unset($sep); + + echo("
+ + - - - - "); + + + + "); - - if (isset($_GET['opta']) && $_GET['opta'] != "macaccounting") { - foreach(explode(" ", $_GET['opta']) as $graph_type) { - if($graph_type == "prefixes") { list($afi, $safi) = explode(".", $_GET['optb']); $afisafi = "&afi=$afi&safi=$safi"; } - if($graph_type == "updates" || $valid_afi_safi[$afi][$safi]) { + if (isset($_GET['opta']) && $_GET['opta'] != "macaccounting") + { + foreach(explode(" ", $_GET['opta']) as $graph_type) + { + if ($graph_type == "prefixes") { list($afi, $safi) = explode(".", $_GET['optb']); $afisafi = "&afi=$afi&safi=$safi"; } + if ($graph_type == "updates" || $valid_afi_safi[$afi][$safi]) + { $daily_traffic = $config['base_url'] . "/graph.php?id=" . $peer['bgpPeer_id'] . "&type=bgp_$graph_type&from=$day&to=$now&width=210&height=100$afisafi"; $daily_url = $config['base_url'] . "/graph.php?id=" . $peer['bgpPeer_id'] . "&type=bgp_$graph_type&from=$day&to=$now&width=500&height=150$afisafi"; $weekly_traffic = $config['base_url'] . "/graph.php?id=" . $peer['bgpPeer_id'] . "&type=bgp_$graph_type&from=$week&to=$now&width=210&height=100$afisafi"; @@ -100,38 +125,39 @@ print_optionbar_end(); echo("', LEFT".$config['overlib_defaults'].", WIDTH, 350);\" onmouseout=\"return nd();\"> "); echo("', LEFT".$config['overlib_defaults'].", WIDTH, 350);\" onmouseout=\"return nd();\">"); echo(""); - } - } - } - if ($_GET['opta'] == "macaccounting") { - if(mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv4_mac` AS I, mac_accounting AS M WHERE I.ipv4_address = '".$peer['bgpPeerIdentifier']."' AND M.mac = I.mac_address"),0)) { - $acc = mysql_fetch_array(mysql_query("SELECT * FROM `ipv4_mac` AS I, mac_accounting AS M, ports AS P WHERE I.ipv4_address = '".$peer['bgpPeerIdentifier']."' AND M.mac = I.mac_address AND P.interface_id = M.interface_id")); - $graph_type = "mac_acc_bits"; - $database = $config['rrd_dir'] . "/" . $device['hostname'] . "/cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd"; - if ( is_file($database) ) { - $daily_traffic = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$day&to=$now&width=210&height=100"; - $daily_url = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$day&to=$now&width=500&height=150"; - $weekly_traffic = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$week&to=$now&width=210&height=100"; - $weekly_url = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$week&to=$now&width=500&height=150"; - $monthly_traffic = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$month&to=$now&width=210&height=100"; - $monthly_url = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$month&to=$now&width=500&height=150"; - $yearly_traffic = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$year&to=$now&width=210&height=100"; - $yearly_url = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$year&to=$now&width=500&height=150"; - echo(""); } } } + if ($_GET['opta'] == "macaccounting" && $has_macaccounting) + { + $acc = mysql_fetch_assoc(mysql_query("SELECT * FROM `ipv4_mac` AS I, mac_accounting AS M, ports AS P WHERE I.ipv4_address = '".$peer['bgpPeerIdentifier']."' AND M.mac = I.mac_address AND P.interface_id = M.interface_id")); + $graph_type = "mac_acc_bits"; + $database = $config['rrd_dir'] . "/" . $device['hostname'] . "/cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd"; + if (is_file($database)) + { + $daily_traffic = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$day&to=$now&width=210&height=100"; + $daily_url = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$day&to=$now&width=500&height=150"; + $weekly_traffic = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$week&to=$now&width=210&height=100"; + $weekly_url = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$week&to=$now&width=500&height=150"; + $monthly_traffic = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$month&to=$now&width=210&height=100"; + $monthly_url = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$month&to=$now&width=500&height=150"; + $yearly_traffic = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$year&to=$now&width=210&height=100"; + $yearly_url = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$year&to=$now&width=500&height=150"; + echo(""); + } + } + $i++; } -echo("
$i" . $peer['bgpPeerIdentifier'] . "
".$peername."
$i" . $peer['bgpPeerIdentifier'] . "
".$peername."
$peer_type" . (isset($peer_af) ? $peer_af : '') . "AS" . $peer['bgpPeerRemoteAs'] . "
" . $peer['astext'] . "
" . $peer['bgpPeerAdminStatus'] . "
" . $peer['bgpPeerState'] . "
" .formatUptime($peer['bgpPeerFsmEstablishedTime']). "
- Updates " . $peer['bgpPeerInUpdates'] . " - " . $peer['bgpPeerOutUpdates'] . "
" . (isset($peer_af) ? $peer_af : '') . "AS" . $peer['bgpPeerRemoteAs'] . "
" . $peer['astext'] . "
" . $peer['bgpPeerAdminStatus'] . "
" . $peer['bgpPeerState'] . "
" .formatUptime($peer['bgpPeerFsmEstablishedTime']). "
+ Updates " . $peer['bgpPeerInUpdates'] . " + " . $peer['bgpPeerOutUpdates'] . "
"); - echo("', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\"> - "); - echo("', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\"> - "); - echo("', LEFT".$config['overlib_defaults'].", WIDTH, 350);\" onmouseout=\"return nd();\"> - "); - echo("', LEFT".$config['overlib_defaults'].", WIDTH, 350);\" onmouseout=\"return nd();\"> - "); - echo("
"); + echo("', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\"> + "); + echo("', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\"> + "); + echo("', LEFT".$config['overlib_defaults'].", WIDTH, 350);\" onmouseout=\"return nd();\"> + "); + echo("', LEFT".$config['overlib_defaults'].", WIDTH, 350);\" onmouseout=\"return nd();\"> + "); + echo("
"); - ?> + + diff --git a/html/pages/iftype.inc.php b/html/pages/iftype.inc.php index dde985e4b..99b83720a 100644 --- a/html/pages/iftype.inc.php +++ b/html/pages/iftype.inc.php @@ -1,42 +1,47 @@ + + "); -#if($_GET['type']) { +if ($bg == "#ffffff") { $bg = "#e5e5e5"; } else { $bg="#ffffff"; } - $type_where = " ("; - foreach(split(",", $_GET['opta']) as $type) { - $type_where .= " $or `port_descr_type` = '$type' "; - $or = "OR"; - } - $type_where .= ") "; +$type_where = " ("; +foreach(split(",", $_GET['opta']) as $type) +{ + $type_where .= " $or `port_descr_type` = '" . mres($type) . "' "; + $or = "OR"; +} - $sql = "SELECT * FROM `ports` as I, `devices` AS D WHERE $type_where AND I.device_id = D.device_id ORDER BY I.ifAlias"; +$type_where .= ") "; - $query = mysql_query($sql); - while($interface = mysql_fetch_array($query)) { - $if_list .= $seperator . $interface['interface_id']; - $seperator = ","; - } - unset($seperator); +$sql = "SELECT * FROM `ports` as I, `devices` AS D WHERE $type_where AND I.device_id = D.device_id ORDER BY I.ifAlias"; - $types_array = explode(',',$_GET['opta']); - for ($i = 0; $i < count($types_array);$i++) $types_array[$i] = ucfirst($types_array[$i]); - $types = implode(' + ',$types_array); +$query = mysql_query($sql); +while($interface = mysql_fetch_array($query)) +{ + $if_list .= $seperator . $interface['interface_id']; + $seperator = ","; +} +unset($seperator); + +$types_array = explode(',',$_GET['opta']); +for ($i = 0; $i < count($types_array);$i++) $types_array[$i] = ucfirst($types_array[$i]); +$types = implode(' + ',$types_array); - echo(" +echo(""); +if ($iflist) +{ echo(""); - - + $sql = "select * from ports as I, devices as D WHERE $type_where AND I.device_id = D.device_id ORDER BY I.ifAlias"; $query = mysql_query($sql); - while($interface = mysql_fetch_array($query)) { + while($interface = mysql_fetch_array($query)) + { $done = "yes"; unset($class); $interface['ifAlias'] = str_ireplace($type . ": ", "", $interface['ifAlias']); @@ -46,26 +51,27 @@ echo("
Total Graph for ports of type : ".$types."
"); $graph_type = "multiport_bits"; $interface['interface_id'] = $if_list; include("includes/print-interface-graphs.inc.php"); echo("
"); echo(""); + + if(file_exists($config['rrd_dir'] . "/" . $interface['hostname'] . "/port-" . $interface['ifIndex'] . ".rrd")) + { + $graph_type = "port_bits"; + include("includes/print-interface-graphs.inc.php"); + } + + echo(""); } -#} - -echo("
" . generate_port_link($interface,$interface['port_descr_descr']) . "
".generate_device_link($interface)." ".generate_port_link($interface)." "); - - if(mysql_result(mysql_query("SELECT count(*) FROM mac_accounting WHERE interface_id = '".$interface['interface_id']."'"),0)){ + + if(mysql_result(mysql_query("SELECT count(*) FROM mac_accounting WHERE interface_id = '".$interface['interface_id']."'"),0)) + { echo(" MAC Accounting"); } - - + echo("
"); - -if(file_exists($config['rrd_dir'] . "/" . $interface['hostname'] . "/port-" . $interface['ifIndex'] . ".rrd")) { - - $graph_type = "port_bits"; - include("includes/print-interface-graphs.inc.php"); - -} - echo("
"); - -if(!$done) { echo("None found."); } - + +} +else +{ + echo("None found."); +} ?> + \ No newline at end of file