mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Trigger Device Rediscovery for a device group (#10832)
* trigger rediscover for whole device group * travis fix * Update rediscover-device.inc.php
This commit is contained in:
@@ -22,18 +22,42 @@ if (!Auth::user()->hasGlobalAdmin()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Make this part of the API instead of a standalone function
|
// FIXME: Make this part of the API instead of a standalone function
|
||||||
if (!is_numeric($_POST['device_id'])) {
|
if (isset($_POST['device_id'])) {
|
||||||
$status = 'error';
|
if (!is_numeric($_POST['device_id'])) {
|
||||||
$message = 'Invalid device id';
|
$status = 'error';
|
||||||
} else {
|
$message = 'Invalid device id ' . $_POST['device_id'];
|
||||||
$update = dbUpdate(array('last_discovered' => array('NULL')), 'devices', '`device_id` = ?', array($_POST['device_id']));
|
|
||||||
if (!empty($update) || $update == '0') {
|
|
||||||
$status = 'ok';
|
|
||||||
$message = 'Device will be rediscovered';
|
|
||||||
} else {
|
} else {
|
||||||
$status = 'error';
|
$update = dbUpdate(array('last_discovered' => array('NULL')), 'devices', '`device_id` = ?', array($_POST['device_id']));
|
||||||
$message = 'Error rediscovering device';
|
if (!empty($update) || $update == '0') {
|
||||||
|
$status = 'ok';
|
||||||
|
$message = 'Device ' . $_POST['device_id'] . ' will be rediscovered';
|
||||||
|
} else {
|
||||||
|
$status = 'error';
|
||||||
|
$message = 'Error rediscovering device ' . $_POST['device_id'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} elseif (isset($_POST['device_group_id'])) {
|
||||||
|
if (!is_numeric($_POST['device_group_id'])) {
|
||||||
|
$status = 'error';
|
||||||
|
$message = 'Invalid device group id ' . $_POST['device_group_id'];
|
||||||
|
} else {
|
||||||
|
$device_ids = dbFetchColumn("SELECT `device_id` FROM `device_group_device` WHERE `device_group_id`=" . $_POST['device_group_id']);
|
||||||
|
$update = 0;
|
||||||
|
foreach ($device_ids as $device_id) {
|
||||||
|
$update += dbUpdate(array('last_discovered' => array('NULL')), 'devices', '`device_id` = ?', array($device_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($update) || $update == '0') {
|
||||||
|
$status = 'ok';
|
||||||
|
$message = 'Devices of group ' . $_POST['device_group_id'] . ' will be rediscovered';
|
||||||
|
} else {
|
||||||
|
$status = 'error';
|
||||||
|
$message = 'Error rediscovering devices of group ' . $_POST['device_group_id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$status = 'Error';
|
||||||
|
$message = 'Undefined POST keys received';
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = array(
|
$output = array(
|
||||||
|
@@ -41,10 +41,14 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>{{ $device_group->type == 'dynamic' ? $device_group->getParser()->toSql(false) : '' }}</td>
|
<td>{{ $device_group->type == 'dynamic' ? $device_group->getParser()->toSql(false) : '' }}</td>
|
||||||
<td>
|
<td>
|
||||||
<a type="button" class="btn btn-primary btn-sm" aria-label="@lang('Edit')"
|
<button type="button" title="@lang('Rediscover all Devices of Device Group')" class="btn btn-warning btn-sm" aria-label="@lang('Rediscover Group')"
|
||||||
|
onclick="discover_dg(this, '{{ $device_group->id }}')">
|
||||||
|
<i
|
||||||
|
class="fa fa-retweet" aria-hidden="true"></i></button>
|
||||||
|
<a type="button" title="@lang('edit Device Group')" class="btn btn-primary btn-sm" aria-label="@lang('Edit')"
|
||||||
href="{{ route('device-groups.edit', $device_group->id) }}">
|
href="{{ route('device-groups.edit', $device_group->id) }}">
|
||||||
<i class="fa fa-pencil" aria-hidden="true"></i></a>
|
<i class="fa fa-pencil" aria-hidden="true"></i></a>
|
||||||
<button type="button" class="btn btn-danger btn-sm" aria-label="@lang('Delete')"
|
<button type="button" class="btn btn-danger btn-sm" title="@lang('delete Device Group')" aria-label="@lang('Delete')"
|
||||||
onclick="delete_dg(this, '{{ $device_group->name }}', '{{ route('device-groups.destroy', $device_group->id) }}')">
|
onclick="delete_dg(this, '{{ $device_group->name }}', '{{ route('device-groups.destroy', $device_group->id) }}')">
|
||||||
<i
|
<i
|
||||||
class="fa fa-trash" aria-hidden="true"></i></button>
|
class="fa fa-trash" aria-hidden="true"></i></button>
|
||||||
@@ -111,6 +115,24 @@
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
function discover_dg(button, id) {
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: 'ajax_form.php',
|
||||||
|
data: { type: "rediscover-device", device_group_id: id },
|
||||||
|
dataType: "json",
|
||||||
|
success: function(data){
|
||||||
|
if(data['status'] == 'ok') {
|
||||||
|
toastr.success(data['message']);
|
||||||
|
} else {
|
||||||
|
toastr.error(data['message']);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error:function(){
|
||||||
|
toastr.error('An error occured setting this device Group to be rediscovered');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user