mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Basic Alert Stats Page
- Diagrams from visjs - Basic Alert Stats Global Page - Basic Alert Stats Device Specific Page Big thanks to lafwood for the help.
This commit is contained in:
100
html/includes/print-graph-alerts.inc.php
Normal file
100
html/includes/print-graph-alerts.inc.php
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
<?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.
|
||||||
|
*/
|
||||||
|
$pagetitle[] = "Alert Stats";
|
||||||
|
|
||||||
|
if (isset($device['device_id']) && $device['device_id'] > 0) {
|
||||||
|
$sql = " AND alert_log.device_id=?";
|
||||||
|
$param = array(
|
||||||
|
$device['device_id']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_SESSION['userlevel'] >= '5') {
|
||||||
|
$query = "SELECT DATE(time_logged) Date, COUNT(alert_log.device_id) totalCount, alert_rules.severity Severity FROM alert_log,alert_rules WHERE alert_log.rule_id=alert_rules.id $sql GROUP BY DATE(time_logged),alert_rules.severity";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_SESSION['userlevel'] < '5') {
|
||||||
|
$query = "SELECT DATE(time_logged) Date, COUNT(alert_log.device_id) totalCount, alert_rules.severity Severity FROM alert_log,alert_rules,devices_perms WHERE alert_log.rule_id=alert_rules.id $sql AND alert_log.device_id = devices_perms.device_id AND devices_perms.user_id = " . $_SESSION['user_id'] . " GROUP BY DATE(time_logged),alert_rules.severity";
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
<script src="js/vis.min.js"></script>
|
||||||
|
<div id="visualization"></div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
var container = document.getElementById('visualization');
|
||||||
|
<?php
|
||||||
|
$groups = array();
|
||||||
|
$max_count = 0;
|
||||||
|
|
||||||
|
foreach(dbFetchRows($query, $param) as $return_value) {
|
||||||
|
$date = $return_value['Date'];
|
||||||
|
$count = $return_value['totalCount'];
|
||||||
|
if ($count > $max_count) {
|
||||||
|
$max_count = $count;
|
||||||
|
}
|
||||||
|
|
||||||
|
$severity = $return_value['Severity'];
|
||||||
|
$data[] = array(
|
||||||
|
'x' => $date,
|
||||||
|
'y' => $count,
|
||||||
|
'group' => $severity
|
||||||
|
);
|
||||||
|
if (!in_array($severity, $groups)) {
|
||||||
|
array_push($groups, $severity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$graph_data = _json_encode($data);
|
||||||
|
?>
|
||||||
|
var groups = new vis.DataSet();
|
||||||
|
<?php
|
||||||
|
|
||||||
|
foreach($groups as $group) {
|
||||||
|
echo "groups.add({id: '$group', content: '$group' })\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
var items =
|
||||||
|
<?php
|
||||||
|
echo $graph_data; ?>
|
||||||
|
;
|
||||||
|
var dataset = new vis.DataSet(items);
|
||||||
|
var options = {
|
||||||
|
style:'bar',
|
||||||
|
barChart: {width:50, align:'right',handleOverlap:'sideBySide'}, // align: left, center, right
|
||||||
|
drawPoints: false,
|
||||||
|
legend: {left:{position:"bottom-left"}},
|
||||||
|
dataAxis: {
|
||||||
|
icons:true,
|
||||||
|
showMajorLabels: true,
|
||||||
|
showMinorLabels: true,
|
||||||
|
customRange: {
|
||||||
|
left: {
|
||||||
|
min: 0, max: <?php
|
||||||
|
echo $max_count; ?>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
zoomMin: 2073600000, //24hrs
|
||||||
|
zoomMax: <?php
|
||||||
|
$first_date = reset($data);
|
||||||
|
$last_date = end($data);
|
||||||
|
$milisec_diff = abs(strtotime($first_date[x]) - strtotime($last_date[x])) * 1000;
|
||||||
|
echo $milisec_diff;
|
||||||
|
?>,
|
||||||
|
orientation:'top'
|
||||||
|
};
|
||||||
|
var graph2d = new vis.Graph2d(container, items, groups, options);
|
||||||
|
|
||||||
|
</script>
|
@@ -56,6 +56,7 @@ if (isset($config['site_style']) && ($config['site_style'] == 'dark' || $config[
|
|||||||
<ul class="dropdown-menu scrollable-menu">
|
<ul class="dropdown-menu scrollable-menu">
|
||||||
<li><a href="<?php echo(generate_url(array('page'=>'alerts'))); ?>"><i class="fa fa-bell fa-fw fa-lg"></i> Alerts</a></li>
|
<li><a href="<?php echo(generate_url(array('page'=>'alerts'))); ?>"><i class="fa fa-bell fa-fw fa-lg"></i> Alerts</a></li>
|
||||||
<li><a href="<?php echo(generate_url(array('page'=>'alert-log'))); ?>"><i class="fa fa-th-list fa-fw fa-lg"></i> Alert Log</a></li>
|
<li><a href="<?php echo(generate_url(array('page'=>'alert-log'))); ?>"><i class="fa fa-th-list fa-fw fa-lg"></i> Alert Log</a></li>
|
||||||
|
<li><a href="<?php echo(generate_url(array('page'=>'alert-stats'))); ?>"><i class="fa fa-bar-chart fa-fw fa-lg"></i> Alert Stats</a></li>
|
||||||
<?php
|
<?php
|
||||||
if ($_SESSION['userlevel'] >= '10') {
|
if ($_SESSION['userlevel'] >= '10') {
|
||||||
?>
|
?>
|
||||||
|
13
html/pages/alert-stats.inc.php
Normal file
13
html/pages/alert-stats.inc.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?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/print-graph-alerts.inc.php');
|
||||||
|
?>
|
@@ -325,6 +325,15 @@ if (device_permitted($vars['device']) || $check_device == $vars['device'])
|
|||||||
</li>');
|
</li>');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (device_permitted($device['device_id']))
|
||||||
|
{
|
||||||
|
echo('<li class="' . $select['alert-stats'] . '">
|
||||||
|
<a href="'.generate_device_url($device, array('tab' => 'alert-stats')).'">
|
||||||
|
<img src="images/16/chart_bar.png" align="absmiddle" border="0" /> Alert Stats
|
||||||
|
</a>
|
||||||
|
</li>');
|
||||||
|
}
|
||||||
|
|
||||||
if ($_SESSION['userlevel'] >= "7")
|
if ($_SESSION['userlevel'] >= "7")
|
||||||
{
|
{
|
||||||
if (!is_array($config['rancid_configs'])) { $config['rancid_configs'] = array($config['rancid_configs']); }
|
if (!is_array($config['rancid_configs'])) { $config['rancid_configs'] = array($config['rancid_configs']); }
|
||||||
|
13
html/pages/device/alert-stats.inc.php
Normal file
13
html/pages/device/alert-stats.inc.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?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/print-graph-alerts.inc.php');
|
||||||
|
?>
|
Reference in New Issue
Block a user