webui: Allow deletion of dead poller nodes (#7721)

* webui: allow deletion of dead poller nodes

* improve messages
This commit is contained in:
Tony Murray
2017-11-22 01:50:29 -06:00
committed by Neil Lathwood
parent ccbe3ea2e3
commit ea684c3543
3 changed files with 143 additions and 3 deletions

View File

@@ -0,0 +1,42 @@
<?php
/**
* delete-poller.inc.php
*
* Handle poller delete request
*
* 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/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2017 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
if (is_admin() === false) {
$status = array('status' =>1, 'message' => 'ERROR: You need to be admin to delete poller entries');
} else {
$id = $vars['id'];
if (!is_numeric($id)) {
$status = array('status' =>1, 'message' => 'No poller has been selected');
} else {
$poller_name = dbFetchCell('SELECT `poller_name` FROM `pollers` WHERE `id`=?', array($id));
if (dbDelete('pollers', 'id=?', array($id))) {
$status = array('status' => 0, 'message' => "Poller: <i>$poller_name ($id), has been deleted.</i>");
} else {
$status = array('status' => 1, 'message' => "Poller: <i>$poller_name ($id), has NOT been deleted.</i>");
}
}
}
header('Content-Type: application/json');
echo _json_encode($status);

View File

@@ -0,0 +1,84 @@
<?php
/**
* delete_poller.inc.php
*
* -Description-
*
* 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/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2017 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
if (is_admin() !== false) {
?>
<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="Delete" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h5 class="modal-title" id="Delete">Confirm Delete</h5>
</div>
<div class="modal-body">
<p>Please confirm that you would like to delete this poller.</p>
</div>
<div class="modal-footer">
<form role="form" class="remove_token_form">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-danger danger" id="poller-removal"
data-target="poller-removal">Delete
</button>
<input type="hidden" name="id" id="id" value="">
<input type="hidden" name="confirm" id="confirm" value="yes">
</form>
</div>
</div>
</div>
</div>
<script>
$('#confirm-delete').on('show.bs.modal', function (e) {
id = $(e.relatedTarget).data('id');
$("#id").val(id);
});
$('#poller-removal').click('', function (e) {
e.preventDefault();
var id = $("#id").val();
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: {type: "delete-poller", id: id},
success: function (result) {
if (result.status == 0) {
toastr.success(result.message);
$("#row_" + id).remove();
}
else {
toastr.error(result.message);
}
$("#confirm-delete").modal('hide');
},
error: function () {
toastr.error('An error occurred deleting this poller.');
$("#confirm-delete").modal('hide');
}
});
});
</script>
<?php
}
?>

View File

@@ -12,6 +12,10 @@
* the source code distribution for details.
*/
use LibreNMS\Config;
require_once 'includes/modal/delete_poller.inc.php';
?>
<br />
<div class="table-responsive">
@@ -21,6 +25,7 @@
<th>Devices Polled</th>
<th>Total Poll Time</th>
<th>Last Ran</th>
<th>Actions</th>
</tr>
<?php
@@ -28,20 +33,29 @@ $query = 'SELECT *,UNIX_TIMESTAMP(NOW()) AS `now`, UNIX_TIMESTAMP(`last_polled`)
foreach (dbFetchRows($query) as $poller) {
$old = ($poller['now'] - $poller['then']);
if ($old >= 300) {
$step = Config::get('rrd.step', 300);
if ($old >= $step) {
$row_class = 'danger';
} elseif ($old >= 280 && $old < 300) {
} elseif ($old >= ($step * 0.95)) {
$row_class = 'warning';
} else {
$row_class = 'success';
}
$actions = "";
if (is_admin() && $old > ($step * 2)) {
// missed 2 polls show delete button
$actions .= "<button type='button' class='btn btn-danger btn-sm' aria-label='Delete' data-toggle='modal' data-target='#confirm-delete' data-id='{$poller['id']}' name='delete-poller'><i class='fa fa-trash' aria-hidden='true'></i></button>";
}
echo '
<tr class="'.$row_class.'">
<tr class="'.$row_class.'" id="row_' . $poller['id'] . '">
<td>'.$poller['poller_name'].'</td>
<td>'.$poller['devices'].'</td>
<td>'.$poller['time_taken'].' Seconds</td>
<td>'.$poller['last_polled'].'</td>
<td>'.$actions.'</td>
</tr>
';
}