Tidy up + new tiles

This commit is contained in:
laf
2015-07-22 22:04:33 +01:00
parent bd7ba8b1b5
commit 8f282c5174
14 changed files with 364 additions and 417 deletions

View File

@ -10,14 +10,14 @@
* the source code distribution for details.
*/
$sql = "SELECT `D`.`hostname`,`D`.`device_id`,`D`.`status`,`D`.`uptime` FROM `devices` AS `D`";
$sql = 'SELECT `D`.`hostname`,`D`.`device_id`,`D`.`status`,`D`.`uptime` FROM `devices` AS `D`';
if (is_admin() === false && is_read() === false) {
$sql .= " , `devices_perms` AS P WHERE D.`device_id` = P.`device_id` AND P.`user_id` = ? AND";
$sql .= ' , `devices_perms` AS P WHERE D.`device_id` = P.`device_id` AND P.`user_id` = ? AND';
$param = array($_SESSION['user_id']);
}
else {
$sql .= " WHERE";
$sql .= ' WHERE';
}
$sql .= " `D`.`ignore` = '0' AND `D`.`disabled` = '0' ORDER BY `hostname`";
@ -34,12 +34,11 @@ foreach(dbFetchRows($sql,$param) as $device) {
else {
$btn_type = 'btn-danger';
}
$temp_output[] = "<a href='" .generate_url(array('page' => 'device', 'device' => $device['device_id'])). "' role='button' class='btn " . $btn_type . " btn-xs' title='" . $device['hostname'] . "' style='min-height:25px; min-width:25px; border-radius:0px; border:0px; margin:0; padding:0;'></a>";
$temp_output[] = '<a href="' .generate_url(array('page' => 'device', 'device' => $device['device_id'])). '" role="button" class="btn ' . $btn_type . ' btn-xs" title="' . $device['hostname'] . '" style="min-height:25px; min-width:25px; border-radius:0px; border:0px; margin:0; padding:0;"></a>';
}
$temp_rows = count($temp_output);
$temp_output[] = "</div>";
$temp_header = array("<div style='margin-left:auto; margin-right:auto;'><center><h3>All Devices(" . $temp_rows . ")</h3></center>");
$temp_output[] = '</div>';
$temp_header = array('<div style="margin-left:auto; margin-right:auto;"><center><h3>All Devices(' . $temp_rows . ')</h3></center>');
$common_output = array_merge($temp_header,$temp_output);

View File

@ -49,4 +49,5 @@ $temp_output .= '
</div>
';
unset($common_output);
$common_output[] = $temp_output;

View File

@ -0,0 +1,110 @@
<?php
require_once 'includes/object-cache.inc.php';
$temp_output = '
<div class="panel panel-default panel-condensed table-responsive">
<table class="table table-hover table-condensed table-striped">
<thead>
<tr class="info">
<th>Summary</th>
<th><a href="devices/">Devices</a></th>
<th><a href="ports/">Ports</a></th>
';
if ($config['show_services']) {
$temp_output .= '
<th><a href="services/">Services</a></th>
';
}
$temp_output .= '
</tr>
</thead>
<tbody>
<tr class="active">
<th><span class="green">Up</span></th>
<td><a href="devices/format=list_detail/state=up/"><span class="green">'. $devices['up'] .'</span></a></td>
<td><a href="ports/format=list_detail/state=up/"><span class="green">'. $ports['up'] .'</span></a></td>
';
if ($config['show_services']) {
$temp_output .= '
<td><a href="services/view=details/state=up/"><span class="green">'. $services['up'] .'</span></a></td>
';
}
$temp_output .= '
</tr>
<tr class="active">
<th><span class="red">Down</span></th>
<td><a href="devices/format=list_detail/state=down/"><span class="red">'. $devices['down'] .'</span></a></td>
<td><a href="ports/format=list_detail/state=down/"><span class="red">'. $ports['down'] .'</span></a></td>
';
if ($config['show_services']) {
$temp_output .= '
<td><a href="services/view=details/state=down/"><span class="red">'. $services['down'] .'</span></a></td>
';
}
$temp_output .= '
</tr>
<tr class="active">
<th><span class="grey">Ignored</span></th>
<td><a href="devices/format=list_detail/ignore=1/"><span class="grey">'. $devices['ignored'] .'</span></a></td>
<td><a href="ports/format=list_detail/ignore=1/"><span class="grey">'. $ports['ignored'] .'</span></a></td>
';
if ($config['show_services']) {
$temp_output .= '
<td><a href="services/view=details/ignore=1/"><span class="grey">'. $services['ignored'] .'</span></a></td>
';
}
$temp_output .= '
</tr>
<tr class="active">
<th><span class="black">Disabled/Shutdown</span></th>
<td><a href="devices/format=list_detail/disabled=1/"><span class="black">'. $devices['disabled'] .'</span></a></td>
<td><a href="ports/format=list_detail/state=admindown/"><span class="black">'. $ports['shutdown'] .'</span></a></td>
';
if ($config['show_services']) {
$temp_output .= '
<td><a href="services/view=details/disabled=1/"><span class="black">'. $services['disabled'] .'</span></a></td>
';
}
$temp_output .= '
</tr>
<tr class="active">
<th>Total</th>
<td><a href="devices/"><span>'. $devices['count'] .'</span></a></td>
<td><a href="ports/"><span>'. $ports['count'] .'</span></a></td>
';
if ($config['show_services']) {
$temp_output .= '
<td><a href="services/"><span>'. $services['count'] .'</span></a></td>
';
}
$temp_output .= '
</tr>
</tbody>
</table>
</div>
';
unset($common_output);
$common_output[] = $temp_output;

View File

@ -0,0 +1,108 @@
<?php
/* Copyright (C) 2014 Daniel Preussker <f0o@devilcode.org>
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Custom Frontpage
* @author f0o <f0o@devilcode.org>
* @copyright 2014 f0o, LibreNMS
* @license GPL
* @package LibreNMS
* @subpackage Frontpage
*/
$temp_output .= "
<script type='text/javascript'>
google.load('visualization', '1', {'packages': ['geochart'], callback: function() {
drawRegionsMap();
function drawRegionsMap() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Site');
data.addColumn('number', 'Status');
data.addColumn('number', 'Size');
data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});
data.addRows([
";
$locations = array();
foreach (getlocations() as $location) {
$devices = array();
$devices_down = array();
$devices_up = array();
$count = 0;
$down = 0;
foreach (dbFetchRows("SELECT devices.device_id,devices.hostname,devices.status FROM devices LEFT JOIN devices_attribs ON devices.device_id = devices_attribs.device_id WHERE ( devices.location = ? || ( devices_attribs.attrib_type = 'override_sysLocation_string' && devices_attribs.attrib_value = ? ) ) && devices.disabled = 0 && devices.ignore = 0 GROUP BY devices.hostname", array($location,$location)) as $device) {
if( $config['frontpage_globe']['markers'] == 'devices' || empty($config['frontpage_globe']['markers']) ) {
$devices[] = $device['hostname'];
$count++;
if( $device['status'] == "0" ) {
$down++;
$devices_down[] = $device['hostname']." DOWN";
}
else {
$devices_up[] = $device;
}
}
elseif( $config['frontpage_globe']['markers'] == 'ports' ) {
foreach( dbFetchRows("SELECT ifName,ifOperStatus,ifAdminStatus FROM ports WHERE ports.device_id = ? && ports.ignore = 0 && ports.disabled = 0 && ports.deleted = 0",array($device['device_id'])) as $port ) {
$count++;
if( $port['ifOperStatus'] == 'down' && $port['ifAdminStatus'] == 'up' ) {
$down++;
$devices_down[] = $device['hostname']."/".$port['ifName']." DOWN";
}
else {
$devices_up[] = $port;
}
}
}
}
$pdown = ($down / $count)*100;
if( $config['frontpage_globe']['markers'] == 'devices' || empty($config['frontpage_globe']['markers']) ) {
$devices_down = array_merge(array(count($devices_up). " Devices OK"), $devices_down);
}
elseif( $config['frontpage_globe']['markers'] == 'ports' ) {
$devices_down = array_merge(array(count($devices_up). " Ports OK"), $devices_down);
}
$locations[] = " ['".$location."', ".$pdown.", ".$count.", '".implode(",<br/> ", $devices_down)."']";
}
$temp_output .= implode(",\n", $locations);
$map_world = $config['frontpage_globe']['region'] ? $config['frontpage_globe']['region'] : 'world';
$map_countries = $config['frontpage_globe']['resolution'] ? $config['frontpage_globe']['resolution'] : 'countries';
$temp_output .= "
]);
var options = {
region: '". $map_world ."',
resolution: '". $map_countries ."',
displayMode: 'markers',
keepAspectRatio: 1,
magnifyingGlass: {enable: true, zoomFactor: 100},
colorAxis: {minValue: 0, maxValue: 100, colors: ['green', 'yellow', 'red']},
markerOpacity: 0.90,
tooltip: {isHtml: true},
};
var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
chart.draw(data, options);
};
}
});
</script>
<div id='chart_div'></div>
";
unset($common_output);
$common_output[] = $temp_output;