<?php /* * LibreNMS front page top ports graph * - Find most utilised ports that have been polled in the last N minutes * * Author: Paul Gear * Copyright (c) 2013 Gear Consulting Pty Ltd <http://libertysys.com.au/> * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. Please see LICENSE.txt at the top level of * the source code distribution for details. */ $minutes = 15; $seconds = $minutes * 60; $top = $config['front_page_settings']['top']['ports']; if (is_admin() === true || is_read() === true) { $query = "\n SELECT *, p.ifInOctets_rate + p.ifOutOctets_rate as total\n FROM ports as p, devices as d\n WHERE d.device_id = p.device_id\n AND unix_timestamp() - p.poll_time < {$seconds}\n AND ( p.ifInOctets_rate > 0\n OR p.ifOutOctets_rate > 0 )\n ORDER BY total desc\n LIMIT {$top}\n "; } else { $query = "\n SELECT *, I.ifInOctets_rate + I.ifOutOctets_rate as total\n FROM ports as I, devices as d,\n `devices_perms` AS `P`, `ports_perms` AS `PP`\n WHERE ((`P`.`user_id` = ? AND `P`.`device_id` = `d`.`device_id`) OR (`PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` AND `I`.`device_id` = `d`.`device_id`)) AND\n d.device_id = I.device_id\n AND unix_timestamp() - I.poll_time < {$seconds}\n AND ( I.ifInOctets_rate > 0\n OR I.ifOutOctets_rate > 0 )\n ORDER BY total desc\n LIMIT {$top}\n "; $param[] = array($_SESSION['user_id'], $_SESSION['user_id']); } //end if echo "<strong>Top {$top} ports (last {$minutes} minutes)</strong>\n"; echo "<table class='simple'>\n"; foreach (dbFetchRows($query, $param) as $result) { echo '<tr class=top10>' . '<td class=top10>' . generate_device_link($result, shorthost($result['hostname'])) . '</td>' . '<td class=top10>' . generate_port_link($result) . '</td>' . '<td class=top10>' . generate_port_link($result, generate_port_thumbnail($result)) . '</td>' . "</tr>\n"; } echo "</table>\n";
LIMIT :count '; } $common_output[] = ' <h4>Top ' . $interface_count . ' interfaces polled within ' . $interval . ' minutes</h4> <div class="table-responsive"> <table class="table table-hover table-condensed table-striped bootgrid-table"> <thead> <tr> <th class="text-left">Device</th> <th class="text-left">Interface</th> <th class="text-left">Total traffic</a></th> </tr> </thead> <tbody> '; foreach (dbFetchRows($query, $params) as $result) { $common_output[] = ' <tr> <td class="text-left">' . generate_device_link($result, shorthost($result['hostname'])) . '</td> <td class="text-left">' . generate_port_link($result, shorten_interface_type($result['ifName'])) . '</td> <td class="text-left">' . generate_port_link($result, generate_port_thumbnail($result)) . '</td> </tr> '; } $common_output[] = ' </tbody> </table> </div> '; }
echo "<a href='#' onmouseover=\" return overlib('Expected Name : " . $vrf['vrf_name'] . "<br />Configured : " . $device['vrf_name'] . "', CAPTION, '<span class=list-large>VRF Inconsistency</span>' ,FGCOLOR,'#e5e5e5', BGCOLOR, '#c0c0c0', BORDER, 5, CELLPAD, 4, CAPCOLOR, '#050505');\" onmouseout=\"return nd();\"> <img align=absmiddle src=images/16/exclamation.png></a>"; } echo "</td><td>"; $ports = mysql_query("SELECT * FROM `ports` WHERE `ifVrf` = '" . $device['vrf_id'] . "' and device_id = '" . $device['device_id'] . "'"); unset($seperator); while ($port = mysql_fetch_array($ports)) { $port = array_merge($device, $port); if ($_GET['opta']) { $port['width'] = "130"; $port['height'] = "30"; $port['from'] = $day; $port['to'] = $now; $port['bg'] = "#" . $bg; $port['graph_type'] = $_GET['opta']; echo "<div style='display: block; padding: 3px; margin: 3px; min-width: 135px; max-width:135px; min-height:75px; max-height:75px;\n text-align: center; float: left; background-color: " . $list_colour_b_b . ";'>\n <div style='font-weight: bold;'>" . makeshortif($port['ifDescr']) . "</div>"; generate_port_thumbnail($port); echo "<div style='font-size: 9px;'>" . truncate(short_port_descr($port['ifAlias']), 22, '') . "</div>\n </div>"; } else { echo $seperator . generateiflink($port, makeshortif($port['ifDescr'])); $seperator = ", "; } } echo "</td></tr>"; $x++; } // End While echo "</table></td>"; $i++; } echo "</table></div>"; } else {
if ($pw_a) { $pw_a['width'] = "150"; $pw_a['height'] = "30"; $pw_a['from'] = $config['time']['day']; $pw_a['to'] = $config['time']['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'] = $config['time']['day']; $pw_b['to'] = $config['time']['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['port_id']; } } echo "</table>";
/** * Display pseudowires. * * Display pages with device pseudowires in some formats. * Examples: * print_pseudowires() - display all pseudowires from all devices * print_pseudowires(array('pagesize' => 99)) - display 99 pseudowires from all device * print_pseudowires(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 pseudowires from page 3 with pagination header * print_pseudowires(array('pagesize' => 10, 'device' = 4)) - display 10 pseudowires for device_id 4 * * @param array $vars * @return none * */ function print_pseudowires($vars) { // Get pseudowires array $events = get_pseudowires_array($vars); if (!$events['count']) { // There have been no entries returned. Print the warning. print_warning('<h4>No pseudowires found!</h4>'); } else { // Entries have been returned. Print the table. $list = array('device' => FALSE); if ($vars['page'] != 'device') { $list['device'] = TRUE; } if (in_array($vars['graph'], array('bits', 'upkts', 'nupkts', 'pktsize', 'percent', 'errors', 'etherlike', 'fdb_count'))) { $graph_types = array($vars['graph']); } else { $graph_types = array('bits', 'upkts', 'errors'); } $string = '<table class="table table-bordered table-striped table-hover table-condensed-more">' . PHP_EOL; $cols = array('id' => 'PW ID', 'type' => array('Type', 'style="width: 5%;"'), 'device_a' => 'Local Device', 'port_a' => 'Local Port', 'NONE' => NULL, 'device_b' => 'Remote Device', 'port_b' => 'Remote Port'); if (!$list['device']) { unset($cols['device_a']); } $string .= get_table_header($cols); //, $vars); // Currently sorting is not available $string .= ' <tbody>' . PHP_EOL; foreach ($events['entries'] as $entry) { $string .= ' <tr>' . PHP_EOL; $string .= ' <td style="font-size: 18px; padding: 4px; width: 5%;">' . $entry['pwID'] . '</td>' . PHP_EOL; $string .= ' <td>' . strtoupper($entry['pwPsnType']) . '<br />' . nicecase($entry['pwType']) . '</td>' . PHP_EOL; if ($list['device']) { $local_dev = device_by_id_cache($entry['device_id']); $string .= ' <td class="entity">' . generate_device_link($local_dev, short_hostname($local_dev['hostname']), array('tab' => 'pseudowires')) . '</td>' . PHP_EOL; } $local_if = get_port_by_id_cache($entry['port_id']); $string .= ' <td class="entity">' . generate_port_link($local_if) . '<br />' . $local_if['ifAlias']; if ($vars['view'] == "minigraphs") { $string .= '<br />'; if ($local_if) { $local_if['width'] = "150"; $local_if['height'] = "30"; $local_if['from'] = $GLOBALS['config']['time']['day']; $local_if['to'] = $GLOBALS['config']['time']['now']; foreach ($graph_types as $graph_type) { $local_if['graph_type'] = "port_" . $graph_type; $string .= generate_port_thumbnail($local_if, FALSE); } } } $string .= '</td>' . PHP_EOL; $string .= ' <td style="width: 3%;"><i class="oicon-arrow_right"></i></td>' . PHP_EOL; if (is_numeric($entry['peer_port_id'])) { $peer_if = get_port_by_id_cache($entry['peer_port_id']); $peer_dev = device_by_id_cache($peer_if['device_id']); $string .= ' <td class="entity">' . generate_device_link($peer_dev, short_hostname($peer_dev['hostname']), array('tab' => 'pseudowires')) . '</br>' . $entry['peer_addr'] . '</td>' . PHP_EOL; $string .= ' <td class="entity">' . generate_port_link($peer_if) . '<br />' . $peer_if['ifAlias']; if ($vars['view'] == "minigraphs") { $string .= '<br />'; if ($peer_if) { $peer_if['width'] = "150"; $peer_if['height'] = "30"; $peer_if['from'] = $GLOBALS['config']['time']['day']; $peer_if['to'] = $GLOBALS['config']['time']['now']; foreach ($graph_types as $graph_type) { $peer_if['graph_type'] = "port_" . $graph_type; $string .= generate_port_thumbnail($peer_if, FALSE); } } } $string .= '</td>' . PHP_EOL; } else { // Show only peer address (and PTR name) $string .= ' <td class="entity">' . $entry['peer_rdns'] . '<br />' . $entry['peer_addr'] . '</td>' . PHP_EOL; $string .= ' <td class="entity"><br />' . $entry['pwRemoteIfString'] . '</td>' . PHP_EOL; } } $string .= ' </tbody>' . PHP_EOL; $string .= '</table>'; // Print pagination header if ($events['pagination_html']) { $string = $events['pagination_html'] . $string . $events['pagination_html']; } // Print echo $string; } }