Next front page improvement

- load all files in include directory
- half-baked attempt to make HTML output more readable
- add top hosts by total bits box
- horrible hack to generate_device_link() to make it possible to insert the device_bits graph
This commit is contained in:
Paul Gear
2013-11-26 14:35:23 +10:00
parent 663c3649a9
commit a5b152cd98
7 changed files with 97 additions and 52 deletions

View File

@@ -1,6 +1,6 @@
<?php <?php
/* /*
* LibreNMS front page graphs - common code * LibreNMS front page graphs
* *
* Copyright (c) 2013 Gear Consulting Pty Ltd <http://libertysys.com.au/> * Copyright (c) 2013 Gear Consulting Pty Ltd <http://libertysys.com.au/>
* *
@@ -10,7 +10,20 @@
* option) any later version. Please see LICENSE.txt at the top level of * option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details. * the source code distribution for details.
*/ */
?> ?>
<script type="text/javascript" src="js/jquery.cycle.all.js"></script> <script type="text/javascript" src="js/jquery.cycle.all.js"></script>
<script type="text/javascript" src="js/jquery-cycle-boxes.js"></script> <script type="text/javascript" src="js/jquery-cycle-boxes.js"></script>
<?php
echo("<div class='right-2-col-fixed'>\n<div class='boxes'>\n");
foreach (get_matching_files($config['html_dir']."/includes/front/", "/^top_.*\.php$/") as $file) {
echo("<div class=box>\n");
include_once($file);
echo("</div>\n");
}
echo("</div>\n");
echo("</div>\n");
?>

View File

@@ -0,0 +1,42 @@
<?php
/*
* LibreNMS front page top devices graph
* - Find most utilised devices that have been polled in the last N minutes
*
* 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']['devices'];
$query = "
SELECT *, sum(p.ifInOctets_rate + p.ifOutOctets_rate) as total
FROM ports as p, devices as d
WHERE d.device_id = p.device_id
AND unix_timestamp() - p.poll_time < $seconds
AND ( p.ifInOctets_rate > 0
OR p.ifOutOctets_rate > 0 )
GROUP BY d.device_id
ORDER BY total desc
LIMIT $top
";
echo("<strong>Top $top devices (last $minutes minutes)</strong>\n");
echo("<table class='simple'>\n");
foreach (dbFetchRows($query) as $result) {
echo("<tr>".
"<td>".generate_device_link($result, shorthost($result['hostname']))."</td>".
"<td>".generate_device_link($result,
generate_minigraph_image($result, $config['time']['day'], $config['time']['now'], "device_bits", "no", 150, 21, '&'), array(), 0, 0, 0)."</td>".
"</tr>\n");
}
echo("</table>\n");
?>

View File

@@ -1,38 +0,0 @@
<?php
/*
* LibreNMS front page graphs
*
* 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.
*/
require_once("includes/front/common.inc.php");
echo('<div class="right-2-col-fixed">');
echo('<div class="boxes">');
echo('<div class=box>');
require_once("includes/front/top_ports.inc.php");
echo('</div>');
/*
echo('<div class=box>');
echo('<h5>Something</h5>');
echo('<p>Next 1</p>');
echo('</div>');
echo('<div class=box>');
echo('<h5>Something else</h5>');
echo('<p>Next 2</p>');
echo('</div>');
*/
echo('</div>');
echo('</div>');
?>

View File

@@ -26,14 +26,14 @@ $query = "
LIMIT $top LIMIT $top
"; ";
echo("<strong>Top $top ports (last $minutes minutes)</strong>"); echo("<strong>Top $top ports (last $minutes minutes)</strong>\n");
echo('<table class="simple">'); echo("<table class='simple'>\n");
foreach (dbFetchRows($query) as $result) { foreach (dbFetchRows($query) as $result) {
echo('<tr><td>'. echo("<tr><td>".
generate_device_link($result, shorthost($result['hostname'])). generate_device_link($result, shorthost($result['hostname'])).
'</td><td>'.generate_port_link($result). "</td><td>".generate_port_link($result).
'</td><td>'.generate_port_link($result, generate_port_thumbnail($result)).'</td></tr>'); "</td><td>".generate_port_link($result, generate_port_thumbnail($result))."</td></tr>\n");
} }
echo('</table>'); echo("</table>\n");
?> ?>

View File

@@ -113,10 +113,10 @@ function get_percentage_colours($percentage)
} }
function generate_minigraph_image($device, $start, $end, $type, $legend = 'no', $width = 275, $height = 100) function generate_minigraph_image($device, $start, $end, $type, $legend = 'no', $width = 275, $height = 100, $sep = '&amp;')
{ {
return '<img class=minigraph-image src="graph.php?device='.$device['device_id']. return '<img class=minigraph-image src="graph.php?'.
"&amp;from=$start&amp;to=$end&amp;width=$width&amp;height=$height&amp;type=$type&amp;legend=$legend".'">'; implode(array('device='.$device['device_id'], "from=$start", "to=$end", "width=$width", "height=$height", "type=$type", "legend=$legend"), $sep).'">';
} }
function generate_device_url($device, $vars=array()) function generate_device_url($device, $vars=array())
@@ -124,7 +124,7 @@ function generate_device_url($device, $vars=array())
return generate_url(array('page' => 'device', 'device' => $device['device_id']), $vars); return generate_url(array('page' => 'device', 'device' => $device['device_id']), $vars);
} }
function generate_device_link($device, $text=NULL, $vars=array(), $start=0, $end=0) function generate_device_link($device, $text=NULL, $vars=array(), $start=0, $end=0, $escape_text=1)
{ {
global $config; global $config;
@@ -169,7 +169,7 @@ function generate_device_link($device, $text=NULL, $vars=array(), $start=0, $end
$contents .= '</div>'; $contents .= '</div>';
} }
$text = htmlentities($text); if ($escape_text) { $text = htmlentities($text); }
$link = overlib_link($url, $text, escape_quotes($contents), $class); $link = overlib_link($url, $text, escape_quotes($contents), $class);
if (device_permitted($device['device_id'])) if (device_permitted($device['device_id']))
@@ -644,4 +644,31 @@ function report_this_text($message)
return $message.'\nPlease report this to the developers at '.$config['project_issues'].'\n'; return $message.'\nPlease report this to the developers at '.$config['project_issues'].'\n';
} }
# Find all the files in the given directory that match the pattern
function get_matching_files($dir, $match = "/\.php$/")
{
global $config;
if ($handle = opendir($dir))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != ".." && preg_match($match, $file) === 1)
{
$list[] = $file;
}
}
closedir($handle);
}
return $list;
}
# Include all the files in the given directory that match the pattern
function include_matching_files($dir, $match = "/\.php$/")
{
foreach (get_matching_files($dir, $match) as $file) {
include_once($file);
}
}
?> ?>

View File

@@ -1,6 +1,6 @@
<?php <?php
require_once("includes/front/top_graphs.inc.php"); include_once("includes/front/boxes.inc.php");
function generate_front_box ($frontbox_class, $content) function generate_front_box ($frontbox_class, $content)
{ {

View File

@@ -112,6 +112,7 @@ $config['header_color'] = "#1F334E";
$config['page_refresh'] = "300"; // Refresh the page every xx seconds, 0 to disable $config['page_refresh'] = "300"; // Refresh the page every xx seconds, 0 to disable
$config['front_page'] = "pages/front/default.php"; $config['front_page'] = "pages/front/default.php";
$config['front_page_settings']['top']['ports'] = 10; $config['front_page_settings']['top']['ports'] = 10;
$config['front_page_settings']['top']['devices'] = 10;
$config['page_title_prefix'] = ""; $config['page_title_prefix'] = "";
$config['page_title_suffix'] = $config['project_name']; $config['page_title_suffix'] = $config['project_name'];
$config['timestamp_format'] = 'd-m-Y H:i:s'; $config['timestamp_format'] = 'd-m-Y H:i:s';