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 15:07:12 +00:00
committed by Neil Lathwood
parent 354bd2144d
commit afb838bc10
18 changed files with 399 additions and 12 deletions
@@ -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(