Merge pull request #1613 from laf/issue-1524

Added edit page to update storage percent warn value
This commit is contained in:
Daniel Preussker
2015-08-09 09:26:17 +00:00
5 changed files with 189 additions and 0 deletions

View File

@@ -1759,3 +1759,7 @@ tr.search:nth-child(odd) {
#leaflet-map {
height: 600px;
}
.edit-storage-input {
width: 100px;
}

View File

@@ -0,0 +1,46 @@
<?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.
*/
$status = 'error';
$message = 'Error updating storage information';
$device_id = mres($_POST['device_id']);
$storage_id = mres($_POST['storage_id']);
$data = mres($_POST['data']);
if (!is_numeric($device_id)) {
$message = 'Missing device id';
}
elseif (!is_numeric($storage_id)) {
$message = 'Missing storage id';
}
elseif (!is_numeric($data)) {
$message = 'Missing value';
}
else {
if (dbUpdate(array('storage_perc_warn'=>$data), 'storage', '`storage_id`=? AND `device_id`=?',array($storage_id,$device_id))) {
$message = 'Storage information updated';
$status = 'ok';
}
else {
$message = 'Could not update storage information';
}
}
$response = array(
'status' => $status,
'message' => $message,
'extra' => $extra,
);
echo _json_encode($response);

View File

@@ -0,0 +1,51 @@
<?php
$device_id = mres($_POST['device_id']);
$sql = " FROM `storage` AS `S` LEFT JOIN `devices` AS `D` ON `S`.`device_id` = `D`.`device_id` WHERE `D`.`device_id`=? AND `S`.`storage_deleted`=0";
$param[] = $device_id;
if (isset($searchPhrase) && !empty($searchPhrase)) {
$sql .= " AND (`D`.`hostname` LIKE '%$searchPhrase%' OR `S`.`storage_descr` LIKE '%$searchPhrase%' OR `S.`storage_perc` LIKE '%$searchPhrase%' OR `S`.`storage_perc_warn` LIKE '%$searchPhrase%')";
}
$count_sql = "SELECT COUNT(`storage_id`) $sql";
$total = dbFetchCell($count_sql,$param);
if (empty($total)) {
$total = 0;
}
if (!isset($sort) || empty($sort)) {
$sort = '`D`.`hostname`, `S`.`storage_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";
//$response[] = array('storage_descr' => $sql);
foreach (dbFetchRows($sql,$param) as $drive) {
$perc = round($drive['storage_perc'], 0);
$perc_warn = round($drive['storage_perc_warn'], 0);
$response[] = array(
'storage_id' => $drive['storage_id'],
'hostname' => generate_device_link($drive),
'storage_descr' => $drive['storage_descr'],
'storage_perc' => $perc . "%",
'storage_perc_warn' => $perc_warn);
}
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total);
echo _json_encode($output);

View File

@@ -34,6 +34,8 @@ else {
$panes['health'] = 'Health';
}
$panes['storage'] = 'Storage';
print_optionbar_start();
unset($sep);

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>Storage settings</h3>
<div class="table-responsive">
<table id="storage" class="table table-hover table-condensed storage">
<thead>
<tr>
<th data-column-id="hostname">Device</th>
<th data-column-id="storage_descr">Storage</th>
<th data-column-id="storage_perc">%</th>
<th data-column-id="storage_perc_warn" data-formatter="perc_update" data-header-css-class="edit-storage-input">% Warn</th>
</tr>
</thead>
</table>
</div>
<script>
var grid = $("#storage").bootgrid({
ajax: true,
rowCount: [25,50,100,250,-1],
post: function ()
{
return {
id: "storage-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 storage' data-device_id='<?php echo $device['device_id']; ?>' data-storage_id='"+row.storage_id+"' value='"+row.storage_perc_warn+"'></div>";
}
},
templates: {
}
}).on("loaded.rs.jquery.bootgrid", function() {
grid.find(".storage").blur(function(event) {
event.preventDefault();
var device_id = $(this).data("device_id");
var storage_id = $(this).data("storage_id");
var data = $(this).val();
var $this = $(this);
$.ajax({
type: 'POST',
url: '/ajax_form.php',
data: {type: "storage-update", device_id: device_id, data: data, storage_id: storage_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>