webgui: Added ability to set warning percentage for CPU, mempools from device edit page (#5895)

This commit is contained in:
Robbie Penziol
2017-03-03 07:07:12 -08:00
committed by Neil Lathwood
parent 354bd2144d
commit afb838bc10
18 changed files with 399 additions and 12 deletions
+3 -1
View File
@@ -1764,7 +1764,9 @@ tr.search:nth-child(odd) {
height: 600px;
}
.edit-storage-input {
.edit-storage-input,
.edit-processor-input,
.edit-mempool-input {
width: 100px;
}
@@ -0,0 +1,52 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2015 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
*
* 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.
*/
header('Content-type: application/json');
if (is_admin() === false) {
$response = array(
'status' => 'error',
'message' => 'Need to be admin',
);
echo _json_encode($response);
exit;
}
$status = 'error';
$message = 'Error updating mempool information';
$device_id = mres($_POST['device_id']);
$mempool_id = mres($_POST['mempool_id']);
$data = mres($_POST['data']);
if (!is_numeric($device_id)) {
$message = 'Missing device id';
} elseif (!is_numeric($mempool_id)) {
$message = 'Missing mempool id';
} elseif (!is_numeric($data)) {
$message = 'Missing value';
} else {
if (dbUpdate(array('mempool_perc_warn'=>$data), 'mempools', '`mempool_id`=? AND `device_id`=?', array($mempool_id,$device_id)) >= 0) {
$message = 'Memory information updated';
$status = 'ok';
} else {
$message = 'Could not update mempool information';
}
}
$response = array(
'status' => $status,
'message' => $message,
'extra' => $extra,
);
echo _json_encode($response);
@@ -0,0 +1,52 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2015 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
*
* 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.
*/
header('Content-type: application/json');
if (is_admin() === false) {
$response = array(
'status' => 'error',
'message' => 'Need to be admin',
);
echo _json_encode($response);
exit;
}
$status = 'error';
$message = 'Error updating processor information';
$device_id = mres($_POST['device_id']);
$processor_id = mres($_POST['processor_id']);
$data = mres($_POST['data']);
if (!is_numeric($device_id)) {
$message = 'Missing device id';
} elseif (!is_numeric($processor_id)) {
$message = 'Missing processor id';
} elseif (!is_numeric($data)) {
$message = 'Missing value';
} else {
if (dbUpdate(array('processor_perc_warn'=>$data), 'processors', '`processor_id`=? AND `device_id`=?', array($processor_id,$device_id)) >= 0) {
$message = 'Processor information updated';
$status = 'ok';
} else {
$message = 'Could not update processor information';
}
}
$response = array(
'status' => $status,
'message' => $message,
'extra' => $extra,
);
echo _json_encode($response);
+8 -2
View File
@@ -196,10 +196,16 @@ function generate_overlib_content($graph_array, $text)
}//end generate_overlib_content()
function get_percentage_colours($percentage)
function get_percentage_colours($percentage, $component_perc_warn = null)
{
$perc_warn = '75';
if (isset($component_perc_warn)) {
$perc_warn = round($component_perc_warn, 0);
}
$background = array();
if ($percentage > '90') {
if ($percentage > $perc_warn) {
$background['left'] = 'c4323f';
$background['right'] = 'C96A73';
} elseif ($percentage > '75') {
+1 -1
View File
@@ -26,7 +26,7 @@ if ($width > '500') {
$descr = rrdtool_escape(short_hrDeviceDescr($mempool['mempool_descr']), $descr_len);
$perc = round($mempool['mempool_perc'], 0);
$background = get_percentage_colours($perc);
$background = get_percentage_colours($perc, $mempool['mempool_perc_warn']);
$rrd_options .= " DEF:$mempool[mempool_id]used=$rrd_filename:used:AVERAGE";
$rrd_options .= " DEF:$mempool[mempool_id]free=$rrd_filename:free:AVERAGE";
+1 -1
View File
@@ -20,7 +20,7 @@ $descr = rrdtool_escape($storage['storage_descr'], 12);
$percentage = round($storage['storage_perc'], 0);
$background = get_percentage_colours($percentage);
$background = get_percentage_colours($percentage, $storage['storage_perc_warn']);
$rrd_options .= " DEF:used=$rrd_filename:used:AVERAGE";
$rrd_options .= " DEF:free=$rrd_filename:free:AVERAGE";
+48
View File
@@ -0,0 +1,48 @@
<?php
$device_id = mres($_POST['device_id']);
$sql = " FROM `mempools` AS `M` LEFT JOIN `devices` AS `D` ON `M`.`device_id` = `D`.`device_id` WHERE `D`.`device_id`=?";
$param[] = $device_id;
if (isset($searchPhrase) && !empty($searchPhrase)) {
$sql .= " AND (`D`.`hostname` LIKE '%$searchPhrase%' OR `M`.`mempool_descr` LIKE '%$searchPhrase%' OR `S.`mempool_perc` LIKE '%$searchPhrase%' OR `M`.`mempool_perc_warn` LIKE '%$searchPhrase%')";
}
$count_sql = "SELECT COUNT(`mempool_id`) $sql";
$total = dbFetchCell($count_sql, $param);
if (empty($total)) {
$total = 0;
}
if (!isset($sort) || empty($sort)) {
$sort = '`D`.`hostname`, `M`.`mempool_descr`';
}
$sql .= " ORDER BY $sort";
if (isset($current)) {
$limit_low = ($current * $rowCount) - ($rowCount);
$limit_high = $rowCount;
}
if ($rowCount != -1) {
$sql .= " LIMIT $limit_low,$limit_high";
}
$sql = "SELECT * $sql";
foreach (dbFetchRows($sql, $param) as $drive) {
$perc = round($drive['mempool_perc'], 0);
$perc_warn = round($drive['mempool_perc_warn'], 0);
$response[] = array(
'mempool_id' => $drive['mempool_id'],
'hostname' => generate_device_link($drive),
'mempool_descr' => $drive['mempool_descr'],
'mempool_perc' => $perc . "%",
'mempool_perc_warn' => $perc_warn);
}
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total);
echo _json_encode($output);
+1 -1
View File
@@ -50,7 +50,7 @@ foreach (dbFetchRows($sql, $param) as $mempool) {
$graph_array_zoom['width'] = '400';
$link = 'graphs/id='.$graph_array['id'].'/type='.$graph_array['type'].'/from='.$graph_array['from'].'/to='.$graph_array['to'].'/';
$mini_graph = overlib_link($link, generate_lazy_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), null);
$background = get_percentage_colours($perc);
$background = get_percentage_colours($perc, $mempool['mempool_perc_warn']);
$bar_link = overlib_link($link, print_percentage_bar(400, 20, $perc, "$used / $total", 'ffffff', $background['left'], $free, 'ffffff', $background['right']), generate_graph_tag($graph_array_zoom), null);
$response[] = array(
@@ -0,0 +1,48 @@
<?php
$device_id = mres($_POST['device_id']);
$sql = " FROM `processors` AS `P` LEFT JOIN `devices` AS `D` ON `P`.`device_id` = `D`.`device_id` WHERE `D`.`device_id`=?";
$param[] = $device_id;
if (isset($searchPhrase) && !empty($searchPhrase)) {
$sql .= " AND (`D`.`hostname` LIKE '%$searchPhrase%' OR `P`.`processor_descr` LIKE '%$searchPhrase%' OR `S.`processor_perc` LIKE '%$searchPhrase%' OR `P`.`processor_perc_warn` LIKE '%$searchPhrase%')";
}
$count_sql = "SELECT COUNT(`processor_id`) $sql";
$total = dbFetchCell($count_sql, $param);
if (empty($total)) {
$total = 0;
}
if (!isset($sort) || empty($sort)) {
$sort = '`D`.`hostname`, `P`.`processor_descr`';
}
$sql .= " ORDER BY $sort";
if (isset($current)) {
$limit_low = ($current * $rowCount) - ($rowCount);
$limit_high = $rowCount;
}
if ($rowCount != -1) {
$sql .= " LIMIT $limit_low,$limit_high";
}
$sql = "SELECT * $sql";
foreach (dbFetchRows($sql, $param) as $drive) {
$perc = round($drive['processor_perc'], 0);
$perc_warn = round($drive['processor_perc_warn'], 0);
$response[] = array(
'processor_id' => $drive['processor_id'],
'hostname' => generate_device_link($drive),
'processor_descr' => $drive['processor_descr'],
'processor_perc' => $perc . "%",
'processor_perc_warn' => $perc_warn);
}
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total);
echo _json_encode($output);
+1 -1
View File
@@ -47,7 +47,7 @@ foreach (dbFetchRows($sql, $param) as $processor) {
$graph_array_zoom['width'] = '400';
$link = 'graphs/id='.$graph_array['id'].'/type='.$graph_array['type'].'/from='.$graph_array['from'].'/to='.$graph_array['to'].'/';
$mini_graph = overlib_link($link, generate_lazy_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), null);
$background = get_percentage_colours($perc);
$background = get_percentage_colours($perc, $processor['processor_perc_warn']);
$bar_link = overlib_link($link, print_percentage_bar(400, 20, $perc, $perc.'%', 'ffffff', $background['left'], (100 - $perc).'%', 'ffffff', $background['right']), generate_graph_tag($graph_array_zoom), null);
$response[] = array(
+1 -1
View File
@@ -59,7 +59,7 @@ foreach (dbFetchRows($sql, $param) as $drive) {
$graph_array_zoom['width'] = '400';
$link = 'graphs/id='.$graph_array['id'].'/type='.$graph_array['type'].'/from='.$graph_array['from'].'/to='.$graph_array['to'].'/';
$mini_graph = overlib_link($link, generate_lazy_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), null);
$background = get_percentage_colours($perc);
$background = get_percentage_colours($perc, $drive['storage_perc_warn']);
$bar_link = overlib_link($link, print_percentage_bar(400, 20, $perc, "$used / $total", 'ffffff', $background['left'], $free, 'ffffff', $background['right']), generate_graph_tag($graph_array_zoom), null);
$response[] = array(
+2
View File
@@ -34,6 +34,8 @@ if ($_SESSION['userlevel'] < '7') {
}
$panes['storage'] = 'Storage';
$panes['processors'] = 'Processors';
$panes['mempools'] = 'Memory';
$panes['misc'] = 'Misc';
$panes['component'] = 'Components';
+86
View File
@@ -0,0 +1,86 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2015 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
*
* 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.
*/
?>
<h3>Memory settings</h3>
<div class="table-responsive">
<table id="mempool" class="table table-hover table-condensed mempool">
<thead>
<tr>
<th data-column-id="hostname">Device</th>
<th data-column-id="mempool_descr">Memory</th>
<th data-column-id="mempool_perc">%</th>
<th data-column-id="mempool_perc_warn" data-formatter="perc_update" data-header-css-class="edit-mempool-input">% Warn</th>
</tr>
</thead>
</table>
</div>
<script>
var grid = $("#mempool").bootgrid({
ajax: true,
rowCount: [25,50,100,250,-1],
post: function ()
{
return {
id: "mempool-edit",
device_id: <?php echo $device['device_id']; ?>,
};
},
url: "ajax_table.php",
formatters: {
"perc_update": function(column,row) {
return "<div class='form-group'><input type='text' class='form-control input-sm mempool' data-device_id='<?php echo $device['device_id']; ?>' data-mempool_id='"+row.mempool_id+"' value='"+row.mempool_perc_warn+"'></div>";
}
},
templates: {
}
}).on("loaded.rs.jquery.bootgrid", function() {
grid.find(".mempool").blur(function(event) {
event.preventDefault();
var device_id = $(this).data("device_id");
var mempool_id = $(this).data("mempool_id");
var data = $(this).val();
var $this = $(this);
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: {type: "mempool-update", device_id: device_id, data: data, mempool_id: mempool_id},
dataType: "json",
success: function (data) {
if (data.status == 'ok') {
$this.closest('.form-group').addClass('has-success');
setTimeout(function () {
$this.closest('.form-group').removeClass('has-success');
}, 2000);
} else {
$this.closest('.form-group').addClass('has-error');
setTimeout(function () {
$this.closest('.form-group').removeClass('has-error');
}, 2000);
}
},
error: function () {
$this.closest('.form-group').addClass('has-error');
setTimeout(function () {
$this.closest('.form-group').removeClass('has-error');
}, 2000);
}
});
});
});
</script>
+86
View File
@@ -0,0 +1,86 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2015 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
*
* 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.
*/
?>
<h3>Processor settings</h3>
<div class="table-responsive">
<table id="processor" class="table table-hover table-condensed processor">
<thead>
<tr>
<th data-column-id="hostname">Device</th>
<th data-column-id="processor_descr">Processor</th>
<th data-column-id="processor_perc">%</th>
<th data-column-id="processor_perc_warn" data-formatter="perc_update" data-header-css-class="edit-processor-input">% Warn</th>
</tr>
</thead>
</table>
</div>
<script>
var grid = $("#processor").bootgrid({
ajax: true,
rowCount: [25,50,100,250,-1],
post: function ()
{
return {
id: "processor-edit",
device_id: <?php echo $device['device_id']; ?>,
};
},
url: "ajax_table.php",
formatters: {
"perc_update": function(column,row) {
return "<div class='form-group'><input type='text' class='form-control input-sm processor' data-device_id='<?php echo $device['device_id']; ?>' data-processor_id='"+row.processor_id+"' value='"+row.processor_perc_warn+"'></div>";
}
},
templates: {
}
}).on("loaded.rs.jquery.bootgrid", function() {
grid.find(".processor").blur(function(event) {
event.preventDefault();
var device_id = $(this).data("device_id");
var processor_id = $(this).data("processor_id");
var data = $(this).val();
var $this = $(this);
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: {type: "processor-update", device_id: device_id, data: data, processor_id: processor_id},
dataType: "json",
success: function (data) {
if (data.status == 'ok') {
$this.closest('.form-group').addClass('has-success');
setTimeout(function () {
$this.closest('.form-group').removeClass('has-success');
}, 2000);
} else {
$this.closest('.form-group').addClass('has-error');
setTimeout(function () {
$this.closest('.form-group').removeClass('has-error');
}, 2000);
}
},
error: function () {
$this.closest('.form-group').addClass('has-error');
setTimeout(function () {
$this.closest('.form-group').removeClass('has-error');
}, 2000);
}
});
});
});
</script>
+1 -1
View File
@@ -24,7 +24,7 @@ if (count($mempools)) {
$total = formatStorage($mempool['mempool_total']);
$used = formatStorage($mempool['mempool_used']);
$free = formatStorage($mempool['mempool_free']);
$background = get_percentage_colours($percent);
$background = get_percentage_colours($percent, $mempool['mempool_perc_warn']);
$graph_array = array();
$graph_array['height'] = '100';
@@ -21,13 +21,14 @@ if (count($processors)) {
$graph_array['legend'] = 'no';
$totalPercent=0;
$totalPercentWarn=0;
foreach ($processors as $proc) {
$text_descr = rewrite_entity_descr($proc['processor_descr']);
$percent = $proc['processor_usage'];
if ($config['cpu_details_overview'] === true) {
$background = get_percentage_colours($percent);
$background = get_percentage_colours($percent, $proc['processor_perc_warn']);
$graph_array['id'] = $proc['processor_id'];
@@ -54,6 +55,7 @@ if (count($processors)) {
</tr>';
} else {
$totalPercent = $totalPercent + $percent;
$totalPercentWarn = $totalPercentWarn + $proc['processor_perc_warn'];
}
}//end foreach
@@ -94,7 +96,8 @@ if (count($processors)) {
//Add a row with CPU desc, count and percent graph
$totalPercent=$totalPercent/count($processors);
$background = get_percentage_colours($totalPercent);
$totalPercentWarn=$totalPercentWarn/count($processors);
$background = get_percentage_colours($totalPercent, $totalPercentWarn);
echo '<tr>
<td class="col-md-4">'.overlib_link($link, $text_descr, $overlib_content).'</td>
+1 -1
View File
@@ -44,7 +44,7 @@ if (count($drives)) {
$total = formatStorage($drive['storage_size']);
$free = formatStorage($drive['storage_free']);
$used = formatStorage($drive['storage_used']);
$background = get_percentage_colours($percent);
$background = get_percentage_colours($percent, $drive['storage_perc_warn']);
$graph_array = array();
$graph_array['height'] = '100';
+2
View File
@@ -0,0 +1,2 @@
ALTER TABLE `processors` ADD `processor_perc_warn` int(11) DEFAULT '75';
ALTER TABLE `mempools` ADD `mempool_perc_warn` int(11) DEFAULT '75';