Merge pull request #1523 from laf/issue-685

Dynamic dashboard
This commit is contained in:
Daniel Preussker
2015-08-01 10:06:28 +00:00
50 changed files with 14078 additions and 206 deletions
@@ -1,3 +1,6 @@
<?php
$common_output[] = '
<div class="row">
<div class="col-sm-12">
<span id="message"></span>
@@ -25,39 +28,39 @@ var grid = $("#alerts").bootgrid({
{
return {
id: "alerts",
device_id: '<?php echo $device['device_id']; ?>'
device_id: \'' . $device['device_id'] .'\'
};
},
url: "/ajax_table.php",
formatters: {
"status": function(column,row) {
return "<h4><span class='label label-"+row.extra+" threeqtr-width'>" + row.msg + "</span></h4>";
return "<h4><span class=\'label label-"+row.extra+" threeqtr-width\'>" + row.msg + "</span></h4>";
},
"ack": function(column,row) {
return "<button type='button' class='btn btn-"+row.ack_col+" btn-sm command-ack-alert' data-target='#ack-alert' data-state='"+row.state+"' data-alert_id='"+row.alert_id+"' name='ack-alert' id='ack-alert' data-extra='"+row.extra+"'><span class='glyphicon glyphicon-"+row.ack_ico+"'aria-hidden='true'></span></button>";
return "<button type=\'button\' class=\'btn btn-"+row.ack_col+" btn-sm command-ack-alert\' data-target=\'#ack-alert\' data-state=\'"+row.state+"\' data-alert_id=\'"+row.alert_id+"\' name=\'ack-alert\' id=\'ack-alert\' data-extra=\'"+row.extra+"\'><span class=\'glyphicon glyphicon-"+row.ack_ico+"\'aria-hidden=\'true\'></span></button>";
}
},
templates: {
}
}).on("loaded.rs.jquery.bootgrid", function() {
grid.find(".incident-toggle").each( function() {
$(this).parent().addClass('incident-toggle-td');
$(this).parent().addClass(\'incident-toggle-td\');
}).on("click", function(e) {
var target = $(this).data("target");
$(target).collapse('toggle');
$(this).toggleClass('glyphicon-plus glyphicon-minus');
$(target).collapse(\'toggle\');
$(this).toggleClass(\'glyphicon-plus glyphicon-minus\');
});
grid.find(".incident").each( function() {
$(this).parent().addClass('col-lg-4 col-md-4 col-sm-4 col-xs-4');
$(this).parent().addClass(\'col-lg-4 col-md-4 col-sm-4 col-xs-4\');
$(this).parent().parent().on("mouseenter", function() {
$(this).find(".incident-toggle").fadeIn(200);
}).on("mouseleave", function() {
$(this).find(".incident-toggle").fadeOut(200);
}).on("click", "td:not(.incident-toggle-td)", function() {
var target = $(this).parent().find(".incident-toggle").data("target");
if( $(this).parent().find(".incident-toggle").hasClass('glyphicon-plus') ) {
$(this).parent().find(".incident-toggle").toggleClass('glyphicon-plus glyphicon-minus');
$(target).collapse('toggle');
if( $(this).parent().find(".incident-toggle").hasClass(\'glyphicon-plus\') ) {
$(this).parent().find(".incident-toggle").toggleClass(\'glyphicon-plus glyphicon-minus\');
$(target).collapse(\'toggle\');
}
});
});
@@ -70,15 +73,17 @@ var grid = $("#alerts").bootgrid({
url: "/ajax_form.php",
data: { type: "ack-alert", alert_id: alert_id, state: state },
success: function(msg){
$("#message").html('<div class="alert alert-info">'+msg+'</div>');
$("#message").html(\'<div class="alert alert-info">\'+msg+\'</div>\');
if(msg.indexOf("ERROR:") <= -1) {
location.reload();
}
},
error: function(){
$("#message").html('<div class="alert alert-info">An error occurred acking this alert.</div>');
$("#message").html(\'<div class="alert alert-info">An error occurred acking this alert.</div>\');
}
});
});
});
</script>
</script>';
@@ -0,0 +1,53 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2015 Søren Friis Rosiak <sorenrosiak@gmail.com>
* 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/object-cache.inc.php';
$sql = 'SELECT `D`.`hostname`,`D`.`device_id`,`D`.`status`,`D`.`uptime` FROM `devices` AS `D`';
if (is_normal_user() === true) {
$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.= " `D`.`ignore` = '0' AND `D`.`disabled` = '0' ORDER BY `hostname`";
$temp_output = array();
$c = '0';
foreach(dbFetchRows($sql, $param) as $device) {
if ($device['status'] == '1') {
$btn_type = 'btn-success';
if ($device['uptime'] < $config['uptime_warning']) {
$btn_type = 'btn-warning';
$c++;
}
}
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_rows = count($temp_output);
$temp_output[] = '</div>';
$temp_header = array(
'<div style="margin-left:auto; margin-right:auto;"><center><h5><i class="fa fa-check" style="color:green">' . $devices['up'] . ' </i> <i class="fa fa-exclamation-triangle" style="color:orange"> '. $c .'</i> <i class="fa fa-exclamation-circle" style="color:red"> ' . $devices['down'] . '</i></h5></center><br />'
);
$common_output = array_merge($temp_header, $temp_output);
@@ -1,6 +1,7 @@
<?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>
@@ -16,30 +17,37 @@ require_once 'includes/object-cache.inc.php';
<tbody>
<tr class="active">
<td><a href="devices/">Devices</a></td>
<td><a href="devices/"><span><?php echo($devices['count']) ?></span></a></td>
<td><a href="devices/state=up/format=list_detail/"><span class="green"> <?php echo($devices['up']) ?> up</span></a></td>
<td><a href="devices/state=down/format=list_detail/"><span class="red"> <?php echo($devices['down']) ?> down</span></a></td>
<td><a href="devices/ignore=1/format=list_detail/"><span class="grey"> <?php echo($devices['ignored']) ?> ignored </span></a></td>
<td><a href="devices/disabled=1/format=list_detail/"><span class="black"> <?php echo($devices['disabled']) ?> disabled</span></a></td>
<td><a href="devices/"><span>'.$devices['count'].'</span></a></td>
<td><a href="devices/state=up/format=list_detail/"><span class="green"> '.$devices['up'].'</span></a></td>
<td><a href="devices/state=down/format=list_detail/"><span class="red"> '.$devices['down'].'</span></a></td>
<td><a href="devices/ignore=1/format=list_detail/"><span class="grey"> '.$devices['ignored'].'</span></a></td>
<td><a href="devices/disabled=1/format=list_detail/"><span class="black"> '.$devices['disabled'].'</span></a></td>
</tr>
<tr class="active">
<td><a href="ports/">Ports</a></td>
<td><a href="ports/"><span><?php echo($ports['count']) ?></span></a></td>
<td><a href="ports/format=list_detail/state=up/"><span class="green"> <?php echo($ports['up']) ?> up </span></a></td>
<td><a href="ports/format=list_detail/state=down/"><span class="red"> <?php echo($ports['down']) ?> down </span></a></td>
<td><a href="ports/format=list_detail/ignore=1/"><span class="grey"> <?php echo($ports['ignored']) ?> ignored </span></a></td>
<td><a href="ports/format=list_detail/state=admindown/"><span class="black"> <?php echo($ports['shutdown']) ?> shutdown</span></a></td>
</tr>
<?php if ($config['show_services']) { ?>
<td><a href="ports/"><span>'.$ports['count'].'</span></a></td>
<td><a href="ports/format=list_detail/state=up/"><span class="green"> '.$ports['up'].'</span></a></td>
<td><a href="ports/format=list_detail/state=down/"><span class="red"> '.$ports['down'].'</span></a></td>
<td><a href="ports/format=list_detail/ignore=1/"><span class="grey"> '.$ports['ignored'].'</span></a></td>
<td><a href="ports/format=list_detail/state=admindown/"><span class="black"> '.$ports['shutdown'].'</span></a></td>
</tr>';
if ($config['show_services']) {
$temp_output .= '
<tr class="active">
<td><a href="services/">Services</a></td>
<td><a href="services/"><span><?php echo($services['count']) ?></span></a></td>
<td><a href="services/state=up/view=details/"><span class="green"><?php echo($services['up']) ?> up</span></a></td>
<td><a href="services/state=down/view=details/"><span class="red"> <?php echo($services['down']) ?> down</span></a></td>
<td><a href="services/ignore=1/view=details/"><span class="grey"> <?php echo($services['ignored']) ?> ignored</span></a></td>
<td><a href="services/disabled=1/view=details/"><span class="black"> <?php echo($services['disabled']) ?> disabled</span></a></td>
</tr>
<?php } ?>
<td><a href="services/"><span>'.$services['count'].'</span></a></td>
<td><a href="services/state=up/view=details/"><span class="green">'.$services['up'].'</span></a></td>
<td><a href="services/state=down/view=details/"><span class="red"> '.$services['down'].'</span></a></td>
<td><a href="services/ignore=1/view=details/"><span class="grey"> '.$services['ignored'].'</span></a></td>
<td><a href="services/disabled=1/view=details/"><span class="black"> '.$services['disabled'].'</span></a></td>
</tr>';
}
$temp_output .= '
</tbody>
</table>
</div>
';
unset($common_output);
$common_output[] = $temp_output;
@@ -1,6 +1,7 @@
<?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>
@@ -8,52 +9,102 @@ require_once 'includes/object-cache.inc.php';
<th>Summary</th>
<th><a href="devices/">Devices</a></th>
<th><a href="ports/">Ports</a></th>
<?php if ($config['show_services']) { ?>
';
if ($config['show_services']) {
$temp_output .= '
<th><a href="services/">Services</a></th>
<?php } ?>
';
}
$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"><?php echo($devices['up']) ?></span></a></td>
<td><a href="ports/format=list_detail/state=up/"><span class="green"><?php echo($ports['up']) ?></span></a></td>
<?php if ($config['show_services']) { ?>
<td><a href="services/view=details/state=up/"><span class="green"><?php echo($services['up']) ?></span></a></td>
<?php } ?>
<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"><?php echo($devices['down']) ?></span></a></td>
<td><a href="ports/format=list_detail/state=down/"><span class="red"><?php echo($ports['down']) ?></span></a></td>
<?php if ($config['show_services']) { ?>
<td><a href="services/view=details/state=down/"><span class="red"><?php echo($services['down']) ?></span></a></td>
<?php } ?>
<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"><?php echo($devices['ignored']) ?></span></a></td>
<td><a href="ports/format=list_detail/ignore=1/"><span class="grey"><?php echo($ports['ignored']) ?></span></a></td>
<?php if ($config['show_services']) { ?>
<td><a href="services/view=details/ignore=1/"><span class="grey"><?php echo($services['ignored']) ?></span></a></td>
<?php } ?>
<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"><?php echo($devices['disabled']) ?></span></a></td>
<td><a href="ports/format=list_detail/state=admindown/"><span class="black"><?php echo($ports['shutdown']) ?></span></a></td>
<?php if ($config['show_services']) { ?>
<td><a href="services/view=details/disabled=1/"><span class="black"><?php echo($services['disabled']) ?></span></a></td>
<?php } ?>
<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><?php echo($devices['count']) ?></span></a></td>
<td><a href="ports/"><span><?php echo($ports['count']) ?></span></a></td>
<?php if ($config['show_services']) { ?>
<td><a href="services/"><span><?php echo($services['count']) ?></span></a></td>
<?php } ?>
<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;
+108
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;
+20
View File
@@ -953,6 +953,25 @@ function is_read() {
}//end is_read()
function is_demo_user() {
if ($_SESSION['userlevel'] == 11) {
return true;
}
else {
return false;
}
}// end is_demo_user();
function is_normal_user() {
if (is_admin() === false && is_read() === false && is_demo_user() === false) {
return true;
}
else {
return false;
}
}// end is_normal_user()
function demo_account() {
print_error("You are logged in as a demo account, this page isn't accessible to you");
@@ -1117,3 +1136,4 @@ function alert_details($details) {
return $fault_detail;
}//end alert_details()