mirror of
https://github.com/librenms/librenms.git
synced 2024-09-21 10:28:13 +00:00
Improved module controls (#16372)
* Improved module controls Ability to clear device module overrides from webui Ability to clear all database data for a module (helpful for module you have disabled that still have data) Database reset only works for modern modules. * Update functions.php
This commit is contained in:
parent
ebce44543c
commit
071076149a
@ -65,13 +65,18 @@ interface Module
|
|||||||
*/
|
*/
|
||||||
public function poll(OS $os, DataStorageInterface $datastore): void;
|
public function poll(OS $os, DataStorageInterface $datastore): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if data exists for this module
|
||||||
|
*/
|
||||||
|
public function dataExists(Device $device): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all DB data for this module.
|
* Remove all DB data for this module.
|
||||||
* This will be run when the module is disabled.
|
* This will be run when the module is disabled.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Device $device
|
* @param \App\Models\Device $device
|
||||||
*/
|
*/
|
||||||
public function cleanup(Device $device): void;
|
public function cleanup(Device $device): int;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dump current module data for the given device for tests.
|
* Dump current module data for the given device for tests.
|
||||||
|
@ -100,12 +100,17 @@ class Availability implements Module
|
|||||||
$os->getDevice()->availability()->whereNotIn('availability_id', $valid_ids)->delete();
|
$os->getDevice()->availability()->whereNotIn('availability_id', $valid_ids)->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dataExists(Device $device): bool
|
||||||
|
{
|
||||||
|
return $device->availability()->exists();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function cleanup(Device $device): void
|
public function cleanup(Device $device): int
|
||||||
{
|
{
|
||||||
$device->availability()->delete();
|
return $device->availability()->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,9 +125,14 @@ class Core implements Module
|
|||||||
$device->save();
|
$device->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cleanup(Device $device): void
|
public function dataExists(Device $device): bool
|
||||||
{
|
{
|
||||||
// nothing to cleanup
|
return false; // no module specific data
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cleanup(Device $device): int
|
||||||
|
{
|
||||||
|
return 0; // nothing to cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,12 +58,17 @@ class EntityPhysical implements Module
|
|||||||
// no polling
|
// no polling
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dataExists(Device $device): bool
|
||||||
|
{
|
||||||
|
return $device->entityPhysical()->exists();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function cleanup(Device $device): void
|
public function cleanup(Device $device): int
|
||||||
{
|
{
|
||||||
$device->entityPhysical()->delete();
|
return $device->entityPhysical()->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,18 +107,6 @@ class Isis implements Module
|
|||||||
$updated->each->save();
|
$updated->each->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove all DB data for this module.
|
|
||||||
* This will be run when the module is disabled.
|
|
||||||
*/
|
|
||||||
public function cleanup(Device $device): void
|
|
||||||
{
|
|
||||||
$device->isisAdjacencies()->delete();
|
|
||||||
|
|
||||||
// clean up legacy components from old code
|
|
||||||
$device->components()->where('type', 'ISIS')->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function discoverIsIsMib(OS $os): Collection
|
public function discoverIsIsMib(OS $os): Collection
|
||||||
{
|
{
|
||||||
// Check if the device has any ISIS enabled interfaces
|
// Check if the device has any ISIS enabled interfaces
|
||||||
@ -197,6 +185,23 @@ class Isis implements Module
|
|||||||
return (int) (max($data['isisISAdjLastUpTime'] ?? 1, 1) / 100);
|
return (int) (max($data['isisISAdjLastUpTime'] ?? 1, 1) / 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dataExists(Device $device): bool
|
||||||
|
{
|
||||||
|
return $device->isisAdjacencies()->exists() || $device->components()->where('type', 'ISIS')->exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all DB data for this module.
|
||||||
|
* This will be run when the module is disabled.
|
||||||
|
*/
|
||||||
|
public function cleanup(Device $device): int
|
||||||
|
{
|
||||||
|
// clean up legacy components from old code
|
||||||
|
$legacyDeleted = $device->components()->where('type', 'ISIS')->delete();
|
||||||
|
|
||||||
|
return $device->isisAdjacencies()->delete() + $legacyDeleted;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
|
@ -117,9 +117,14 @@ class LegacyModule implements Module
|
|||||||
Debug::enableErrorReporting(); // and back to normal
|
Debug::enableErrorReporting(); // and back to normal
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cleanup(Device $device): void
|
public function dataExists(Device $device): bool
|
||||||
{
|
{
|
||||||
// TODO: Implement cleanup() method.
|
return false; // impossible to determine for legacy modules
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cleanup(Device $device): int
|
||||||
|
{
|
||||||
|
return 0; // Not possible to cleanup legacy modules
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -148,9 +148,14 @@ class Mempools implements Module
|
|||||||
return $mempools;
|
return $mempools;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cleanup(Device $device): void
|
public function dataExists(Device $device): bool
|
||||||
{
|
{
|
||||||
$device->mempools()->delete();
|
return $device->mempools()->exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cleanup(Device $device): int
|
||||||
|
{
|
||||||
|
return $device->mempools()->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -165,20 +165,34 @@ class Mpls implements Module
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dataExists(Device $device): bool
|
||||||
|
{
|
||||||
|
return $device->mplsLsps()->exists()
|
||||||
|
|| $device->mplsLspPaths()->exists()
|
||||||
|
|| $device->mplsSdps()->exists()
|
||||||
|
|| $device->mplsServices()->exists()
|
||||||
|
|| $device->mplsSaps()->exists()
|
||||||
|
|| $device->mplsSdpBinds()->exists()
|
||||||
|
|| $device->mplsTunnelArHops()->exists()
|
||||||
|
|| $device->mplsTunnelCHops()->exists();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all DB data for this module.
|
* Remove all DB data for this module.
|
||||||
* This will be run when the module is disabled.
|
* This will be run when the module is disabled.
|
||||||
*/
|
*/
|
||||||
public function cleanup(Device $device): void
|
public function cleanup(Device $device): int
|
||||||
{
|
{
|
||||||
$device->mplsLsps()->delete();
|
$deleted = $device->mplsLsps()->delete();
|
||||||
$device->mplsLspPaths()->delete();
|
$deleted += $device->mplsLspPaths()->delete();
|
||||||
$device->mplsSdps()->delete();
|
$deleted += $device->mplsSdps()->delete();
|
||||||
$device->mplsServices()->delete();
|
$deleted += $device->mplsServices()->delete();
|
||||||
$device->mplsSaps()->delete();
|
$deleted += $device->mplsSaps()->delete();
|
||||||
$device->mplsSdpBinds()->delete();
|
$deleted += $device->mplsSdpBinds()->delete();
|
||||||
$device->mplsTunnelArHops()->delete();
|
$deleted += $device->mplsTunnelArHops()->delete();
|
||||||
$device->mplsTunnelCHops()->delete();
|
$deleted += $device->mplsTunnelCHops()->delete();
|
||||||
|
|
||||||
|
return $deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -113,13 +113,18 @@ class Nac implements Module
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dataExists(Device $device): bool
|
||||||
|
{
|
||||||
|
return $device->portsNac()->exists();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all DB data for this module.
|
* Remove all DB data for this module.
|
||||||
* This will be run when the module is disabled.
|
* This will be run when the module is disabled.
|
||||||
*/
|
*/
|
||||||
public function cleanup(Device $device): void
|
public function cleanup(Device $device): int
|
||||||
{
|
{
|
||||||
$device->portsNac()->delete();
|
return $device->portsNac()->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -227,12 +227,17 @@ class Netstats implements Module
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dataExists(Device $device): bool
|
||||||
|
{
|
||||||
|
return false; // no database data
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function cleanup(Device $device): void
|
public function cleanup(Device $device): int
|
||||||
{
|
{
|
||||||
// no cleanup
|
return 0; // no cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -109,12 +109,17 @@ class Os implements Module
|
|||||||
$this->handleChanges($os);
|
$this->handleChanges($os);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dataExists(Device $device): bool
|
||||||
|
{
|
||||||
|
return false; // data part of device
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function cleanup(Device $device): void
|
public function cleanup(Device $device): int
|
||||||
{
|
{
|
||||||
// no cleanup needed
|
return 0; // no cleanup needed
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -243,15 +243,25 @@ class Ospf implements Module
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dataExists(Device $device): bool
|
||||||
|
{
|
||||||
|
return $device->ospfPorts()->exists()
|
||||||
|
|| $device->ospfNbrs()->exists()
|
||||||
|
|| $device->ospfAreas()->exists()
|
||||||
|
|| $device->ospfInstances()->exists();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function cleanup(Device $device): void
|
public function cleanup(Device $device): int
|
||||||
{
|
{
|
||||||
$device->ospfPorts()->delete();
|
$deleted = $device->ospfPorts()->delete();
|
||||||
$device->ospfNbrs()->delete();
|
$deleted += $device->ospfNbrs()->delete();
|
||||||
$device->ospfAreas()->delete();
|
$deleted += $device->ospfAreas()->delete();
|
||||||
$device->ospfInstances()->delete();
|
$deleted += $device->ospfInstances()->delete();
|
||||||
|
|
||||||
|
return $deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,12 +101,17 @@ class PortsStack implements Module
|
|||||||
// no polling
|
// no polling
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dataExists(Device $device): bool
|
||||||
|
{
|
||||||
|
return $device->portsStack()->exists();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function cleanup(Device $device): void
|
public function cleanup(Device $device): int
|
||||||
{
|
{
|
||||||
$device->portsStack()->delete();
|
return $device->portsStack()->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -135,13 +135,18 @@ class PrinterSupplies implements Module
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dataExists(Device $device): bool
|
||||||
|
{
|
||||||
|
return $device->printerSupplies()->exists();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all DB data for this module.
|
* Remove all DB data for this module.
|
||||||
* This will be run when the module is disabled.
|
* This will be run when the module is disabled.
|
||||||
*/
|
*/
|
||||||
public function cleanup(Device $device): void
|
public function cleanup(Device $device): int
|
||||||
{
|
{
|
||||||
$device->printerSupplies()->delete();
|
return $device->printerSupplies()->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,13 +102,18 @@ class Slas implements Module
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dataExists(Device $device): bool
|
||||||
|
{
|
||||||
|
return $device->slas()->exists();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all DB data for this module.
|
* Remove all DB data for this module.
|
||||||
* This will be run when the module is disabled.
|
* This will be run when the module is disabled.
|
||||||
*/
|
*/
|
||||||
public function cleanup(Device $device): void
|
public function cleanup(Device $device): int
|
||||||
{
|
{
|
||||||
$device->slas()->delete();
|
return $device->slas()->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,10 +88,17 @@ class Stp implements Module
|
|||||||
$this->syncModels($device, 'stpPorts', $ports);
|
$this->syncModels($device, 'stpPorts', $ports);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cleanup(Device $device): void
|
public function dataExists(Device $device): bool
|
||||||
{
|
{
|
||||||
$device->stpInstances()->delete();
|
return $device->stpInstances()->exists() || $device->stpPorts()->exists();
|
||||||
$device->stpPorts()->delete();
|
}
|
||||||
|
|
||||||
|
public function cleanup(Device $device): int
|
||||||
|
{
|
||||||
|
$deleted = $device->stpInstances()->delete();
|
||||||
|
$deleted += $device->stpPorts()->delete();
|
||||||
|
|
||||||
|
return $deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -93,12 +93,17 @@ class Vminfo implements \LibreNMS\Interfaces\Module
|
|||||||
$this->discover($os);
|
$this->discover($os);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dataExists(Device $device): bool
|
||||||
|
{
|
||||||
|
return $device->vminfo()->exists();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function cleanup(Device $device): void
|
public function cleanup(Device $device): int
|
||||||
{
|
{
|
||||||
$device->vminfo()->delete();
|
return $device->vminfo()->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,13 +101,20 @@ class Xdsl implements Module
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dataExists(Device $device): bool
|
||||||
|
{
|
||||||
|
return $device->portsAdsl()->exists() || $device->portsVdsl()->exists();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function cleanup(Device $device): void
|
public function cleanup(Device $device): int
|
||||||
{
|
{
|
||||||
$device->portsAdsl()->delete();
|
$deleted = $device->portsAdsl()->delete();
|
||||||
$device->portsVdsl()->delete();
|
$deleted += $device->portsVdsl()->delete();
|
||||||
|
|
||||||
|
return $deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
59
app/Http/Controllers/Device/Tabs/ModuleController.php
Normal file
59
app/Http/Controllers/Device/Tabs/ModuleController.php
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Device\Tabs;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\Device;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Gate;
|
||||||
|
use LibreNMS\Config;
|
||||||
|
use LibreNMS\Util\Module;
|
||||||
|
|
||||||
|
class ModuleController extends Controller
|
||||||
|
{
|
||||||
|
public function update(Device $device, string $module, Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
Gate::authorize('update', $device);
|
||||||
|
|
||||||
|
$this->validate($request, [
|
||||||
|
'discovery' => 'in:true,false,clear',
|
||||||
|
'polling' => 'in:true,false,clear',
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($request->has('discovery')) {
|
||||||
|
$discovery = $request->get('discovery');
|
||||||
|
if ($discovery == 'clear') {
|
||||||
|
$device->forgetAttrib('discover_' . $module);
|
||||||
|
} else {
|
||||||
|
$device->setAttrib('discover_' . $module, $discovery == 'true' ? 1 : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->has('polling')) {
|
||||||
|
$polling = $request->get('polling');
|
||||||
|
if ($polling == 'clear') {
|
||||||
|
$device->forgetAttrib('poll_' . $module);
|
||||||
|
} else {
|
||||||
|
$device->setAttrib('poll_' . $module, $polling == 'true' ? 1 : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// return the module status
|
||||||
|
return response()->json([
|
||||||
|
'discovery' => (bool) $device->getAttrib('discover_' . $module, Config::getCombined($device->os, 'discovery_modules')[$module] ?? false),
|
||||||
|
'polling' => (bool) $device->getAttrib('poll_' . $module, Config::getCombined($device->os, 'poller_modules')[$module] ?? false),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(Device $device, string $module): JsonResponse
|
||||||
|
{
|
||||||
|
Gate::authorize('delete', $device);
|
||||||
|
|
||||||
|
$deleted = Module::fromName($module)->cleanup($device);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'deleted' => $deleted,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
@ -406,9 +406,9 @@ class Device extends BaseModel
|
|||||||
$this->save();
|
$this->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAttrib($name)
|
public function getAttrib($name, $default = null)
|
||||||
{
|
{
|
||||||
return $this->attribs->pluck('attrib_value', 'attrib_type')->get($name);
|
return $this->attribs->pluck('attrib_value', 'attrib_type')->get($name, $default);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAttrib($name, $value)
|
public function setAttrib($name, $value)
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
header('Content-type: text/plain');
|
|
||||||
|
|
||||||
// FUA
|
|
||||||
|
|
||||||
if (! Auth::user()->hasGlobalAdmin()) {
|
|
||||||
exit('ERROR: You need to be admin');
|
|
||||||
}
|
|
||||||
|
|
||||||
$device['device_id'] = $_POST['device_id'];
|
|
||||||
$module = 'discover_' . $_POST['discovery_module'];
|
|
||||||
|
|
||||||
if (! isset($module) && validate_device_id($device['device_id']) === false) {
|
|
||||||
echo 'error with data';
|
|
||||||
exit;
|
|
||||||
} else {
|
|
||||||
if ($_POST['state'] == 'true') {
|
|
||||||
$state = 1;
|
|
||||||
} elseif ($_POST['state'] == 'false') {
|
|
||||||
$state = 0;
|
|
||||||
} else {
|
|
||||||
$state = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
set_dev_attrib($device, $module, $state);
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
header('Content-type: text/plain');
|
|
||||||
|
|
||||||
if (! Auth::user()->hasGlobalAdmin()) {
|
|
||||||
exit('ERROR: You need to be admin');
|
|
||||||
}
|
|
||||||
|
|
||||||
// FUA
|
|
||||||
$device['device_id'] = $_POST['device_id'];
|
|
||||||
$module = 'poll_' . $_POST['poller_module'];
|
|
||||||
|
|
||||||
if (! isset($module) && validate_device_id($device['device_id']) === false) {
|
|
||||||
echo 'error with data';
|
|
||||||
exit;
|
|
||||||
} else {
|
|
||||||
if ($_POST['state'] == 'true') {
|
|
||||||
$state = 1;
|
|
||||||
} elseif ($_POST['state'] == 'false') {
|
|
||||||
$state = 0;
|
|
||||||
} else {
|
|
||||||
$state = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
set_dev_attrib($device, $module, $state);
|
|
||||||
}
|
|
@ -14,16 +14,18 @@
|
|||||||
<th>Global</th>
|
<th>Global</th>
|
||||||
<th>OS</th>
|
<th>OS</th>
|
||||||
<th>Device</th>
|
<th>Device</th>
|
||||||
|
<th>Override</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use LibreNMS\Config;
|
use LibreNMS\Config;
|
||||||
|
use LibreNMS\Util\Module;
|
||||||
|
|
||||||
$language = \config('app.locale');
|
$language = \config('app.locale');
|
||||||
$settings = (include Config::get('install_dir') . '/lang/' . $language . '/settings.php')['settings'];
|
$settings = (include Config::get('install_dir') . '/lang/' . $language . '/settings.php')['settings'];
|
||||||
|
|
||||||
$attribs = get_dev_attribs($device['device_id']);
|
$attribs = DeviceCache::getPrimary()->getAttribs();
|
||||||
$poller_module_names = $settings['poller_modules'];
|
$poller_module_names = $settings['poller_modules'];
|
||||||
$discovery_module_names = $settings['discovery_modules'];
|
$discovery_module_names = $settings['discovery_modules'];
|
||||||
|
|
||||||
@ -87,11 +89,20 @@ foreach ($poller_modules as $module => $module_status) {
|
|||||||
<td>
|
<td>
|
||||||
';
|
';
|
||||||
|
|
||||||
echo '<input type="checkbox" style="visibility:hidden;width:100px;" name="poller-module" data-poller_module="'
|
echo '<input type="checkbox" style="visibility:hidden;width:100px;" name="poller-module" id="poller-toggle-' . $module . '" ' . $module_checked . '>';
|
||||||
. $module . '" data-device_id="' . $device['device_id'] . '" ' . $module_checked . '>';
|
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
</td>
|
</td>
|
||||||
|
<td style="vertical-align: middle">';
|
||||||
|
|
||||||
|
echo '<button type="button" class="btn btn-default tw-mr-1 poller-reset-button" id="poller-reset-button-' . $module . '" style="visibility: ' . (isset($attribs['poll_' . $module]) ? 'visible' : 'hidden') . '" title="Reset device override"><i class="fa fa-lg fa-solid fa-rotate-left"></i></button>';
|
||||||
|
|
||||||
|
$moduleInstance = Module::fromName($module);
|
||||||
|
if ($moduleInstance->dataExists(DeviceCache::getPrimary())) {
|
||||||
|
echo '<button type="button" class="btn btn-default delete-button-' . $module . '" title="Delete Module Data" data-toggle="modal" data-target="#delete-module-data" data-module="' . $module . '" data-module-name="' . $module_name . '"><i class="fa fa-lg fa-solid fa-trash tw-text-red-600"></button>';
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '</td>
|
||||||
</tr>
|
</tr>
|
||||||
';
|
';
|
||||||
}
|
}
|
||||||
@ -107,6 +118,7 @@ foreach ($poller_modules as $module => $module_status) {
|
|||||||
<th>Global</th>
|
<th>Global</th>
|
||||||
<th>OS</th>
|
<th>OS</th>
|
||||||
<th>Device</th>
|
<th>Device</th>
|
||||||
|
<th>Override</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@ -172,16 +184,45 @@ foreach ($discovery_modules as $module => $module_status) {
|
|||||||
</td>
|
</td>
|
||||||
<td>';
|
<td>';
|
||||||
|
|
||||||
echo '<input type="checkbox" style="visibility:hidden;width:100px;" name="discovery-module" data-discovery_module="'
|
echo '<input type="checkbox" style="visibility:hidden;width:100px;" name="discovery-module" id="discovery-toggle-' . $module . '" ' . $module_checked . '>';
|
||||||
. $module . '" data-device_id="' . $device['device_id'] . '" ' . $module_checked . '>';
|
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
</td>
|
</td>
|
||||||
|
<td style="vertical-align: middle">';
|
||||||
|
|
||||||
|
echo '<button type="button" class="btn btn-default tw-mr-1 discovery-reset-button" id="discovery-reset-button-' . $module . '" style="visibility: ' . (isset($attribs['discover_' . $module]) ? 'visible' : 'hidden') . '" title="Reset device override"><i class="fa fa-lg fa-solid fa-rotate-left"></i></button>';
|
||||||
|
|
||||||
|
$moduleInstance = Module::fromName($module);
|
||||||
|
if ($moduleInstance->dataExists(DeviceCache::getPrimary())) {
|
||||||
|
echo '<button type="button" class="btn btn-default delete-button-' . $module . '" title="Delete Module Data" data-toggle="modal" data-target="#delete-module-data" data-module="' . $module . '" data-module-name="' . $module_name . '"><i class="fa fa-lg fa-solid fa-trash tw-text-red-600"></button>';
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '</td>
|
||||||
</tr>';
|
</tr>';
|
||||||
}
|
}
|
||||||
echo '
|
echo '
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="modal fade" id="delete-module-data" tabindex="-1" role="dialog" aria-labelledby="delete-module-dialog-title" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-md">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
<h4 class="modal-title" id="delete-module-dialog-title">Delete module data for <span class="dialog-module-name">module</span>?</h4>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<p>Delete this device's data for module <span class="dialog-module-name">module</span>?</p>
|
||||||
|
<p>Data will not repopulate until discovery and/or polling is run again.</p>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-primary" id="module-data-delete-button">Delete</button>
|
||||||
|
<button type="button" class="btn btn-danger" data-dismiss="modal">Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
';
|
';
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@ -190,14 +231,12 @@ echo '
|
|||||||
$("[name='poller-module']").bootstrapSwitch('offColor','danger');
|
$("[name='poller-module']").bootstrapSwitch('offColor','danger');
|
||||||
$('input[name="poller-module"]').on('switchChange.bootstrapSwitch', function(event, state) {
|
$('input[name="poller-module"]').on('switchChange.bootstrapSwitch', function(event, state) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
var $this = $(this);
|
var poller_module = $(this).attr('id').replace('poller-toggle-', '');
|
||||||
var poller_module = $(this).data("poller_module");
|
|
||||||
var device_id = $(this).data("device_id");
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'PUT',
|
||||||
url: 'ajax_form.php',
|
url: '<?php echo route('device.module.delete', ['device' => $device['device_id'], 'module' => ':module']) ?>'.replace(':module', poller_module),
|
||||||
data: { type: "poller-module-update", poller_module: poller_module, device_id: device_id, state: state},
|
data: { polling: state},
|
||||||
dataType: "html",
|
dataType: "json",
|
||||||
success: function(data){
|
success: function(data){
|
||||||
//alert('good');
|
//alert('good');
|
||||||
if(state)
|
if(state)
|
||||||
@ -212,6 +251,7 @@ echo '
|
|||||||
$('#poller-module-'+poller_module).addClass('text-danger');
|
$('#poller-module-'+poller_module).addClass('text-danger');
|
||||||
$('#poller-module-'+poller_module).html('Disabled');
|
$('#poller-module-'+poller_module).html('Disabled');
|
||||||
}
|
}
|
||||||
|
$('#poller-reset-button-' + poller_module).css('visibility', 'visible');
|
||||||
},
|
},
|
||||||
error:function(){
|
error:function(){
|
||||||
//alert('bad');
|
//alert('bad');
|
||||||
@ -221,14 +261,12 @@ echo '
|
|||||||
$("[name='discovery-module']").bootstrapSwitch('offColor','danger');
|
$("[name='discovery-module']").bootstrapSwitch('offColor','danger');
|
||||||
$('input[name="discovery-module"]').on('switchChange.bootstrapSwitch', function(event, state) {
|
$('input[name="discovery-module"]').on('switchChange.bootstrapSwitch', function(event, state) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
var $this = $(this);
|
var discovery_module = $(this).attr('id').replace('discovery-toggle-', '');
|
||||||
var discovery_module = $(this).data("discovery_module");
|
|
||||||
var device_id = $(this).data("device_id");
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'PUT',
|
||||||
url: 'ajax_form.php',
|
url: '<?php echo route('device.module.delete', ['device' => $device['device_id'], 'module' => ':module']) ?>'.replace(':module', discovery_module),
|
||||||
data: { type: "discovery-module-update", discovery_module: discovery_module, device_id: device_id, state: state},
|
data: { discovery: state},
|
||||||
dataType: "html",
|
dataType: "json",
|
||||||
success: function(data){
|
success: function(data){
|
||||||
//alert('good');
|
//alert('good');
|
||||||
if(state)
|
if(state)
|
||||||
@ -243,10 +281,67 @@ echo '
|
|||||||
$('#discovery-module-'+discovery_module).addClass('text-danger');
|
$('#discovery-module-'+discovery_module).addClass('text-danger');
|
||||||
$('#discovery-module-'+discovery_module).html('Disabled');
|
$('#discovery-module-'+discovery_module).html('Disabled');
|
||||||
}
|
}
|
||||||
|
$('#discovery-reset-button-' + discovery_module).css('visibility', 'visible');
|
||||||
},
|
},
|
||||||
error:function(){
|
error:function(){
|
||||||
//alert('bad');
|
//alert('bad');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
$('#delete-module-data').on('show.bs.modal', function (event) {
|
||||||
|
$('.dialog-module-name').text($(event.relatedTarget).data('module-name'));
|
||||||
|
$('#module-data-delete-button').data('module', $(event.relatedTarget).data('module'));
|
||||||
|
});
|
||||||
|
$('.poller-reset-button').on('click', function (event) {
|
||||||
|
var poller_module = $(this).attr('id').replace('poller-reset-button-', '');
|
||||||
|
$.ajax({
|
||||||
|
type: 'PUT',
|
||||||
|
url: '<?php echo route('device.module.delete', ['device' => $device['device_id'], 'module' => ':module']) ?>'.replace(':module', poller_module),
|
||||||
|
data: { polling: 'clear'},
|
||||||
|
dataType: "json",
|
||||||
|
success: function(data){
|
||||||
|
$('#poller-toggle-'+poller_module).bootstrapSwitch('state', data.polling, true);
|
||||||
|
$('#poller-module-'+poller_module).removeClass('text-danger');
|
||||||
|
$('#poller-module-'+poller_module).removeClass('text-success');
|
||||||
|
$('#poller-module-'+poller_module).html('Unset');
|
||||||
|
$('#poller-reset-button-'+poller_module).css('visibility', 'hidden');
|
||||||
|
},
|
||||||
|
error:function(){
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$('.discovery-reset-button').on('click', function (event) {
|
||||||
|
var discovery_module = $(this).attr('id').replace('discovery-reset-button-', '');
|
||||||
|
$.ajax({
|
||||||
|
type: 'PUT',
|
||||||
|
url: '<?php echo route('device.module.delete', ['device' => $device['device_id'], 'module' => ':module']) ?>'.replace(':module', discovery_module),
|
||||||
|
data: { discovery: 'clear'},
|
||||||
|
dataType: "json",
|
||||||
|
success: function(data){
|
||||||
|
$('#discovery-toggle-'+discovery_module).bootstrapSwitch('state', data.discovery, true);
|
||||||
|
$('#discovery-module-'+discovery_module).removeClass('text-danger');
|
||||||
|
$('#discovery-module-'+discovery_module).removeClass('text-success');
|
||||||
|
$('#discovery-module-'+discovery_module).html('Unset');
|
||||||
|
$('#discovery-reset-button-'+discovery_module).css('visibility', 'hidden');
|
||||||
|
},
|
||||||
|
error:function(){
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$('#module-data-delete-button').on('click', function (event) {
|
||||||
|
var module = $(this).data('module');
|
||||||
|
$.ajax({
|
||||||
|
type: 'DELETE',
|
||||||
|
url: '<?php echo route('device.module.delete', ['device' => $device['device_id'], 'module' => ':module']) ?>'.replace(':module', module),
|
||||||
|
data: {},
|
||||||
|
dataType: "json",
|
||||||
|
success: function(data){
|
||||||
|
console.log('Deleted: ' + data.deleted);
|
||||||
|
$('#delete-module-data').modal('hide');
|
||||||
|
$('.delete-button-' + module).remove();
|
||||||
|
},
|
||||||
|
error:function(){
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
@ -75,6 +75,8 @@ Route::middleware(['auth'])->group(function () {
|
|||||||
// Device Tabs
|
// Device Tabs
|
||||||
Route::prefix('device/{device}')->namespace('Device\Tabs')->name('device.')->group(function () {
|
Route::prefix('device/{device}')->namespace('Device\Tabs')->name('device.')->group(function () {
|
||||||
Route::put('notes', 'NotesController@update')->name('notes.update');
|
Route::put('notes', 'NotesController@update')->name('notes.update');
|
||||||
|
Route::put('module/{module}', [\App\Http\Controllers\Device\Tabs\ModuleController::class, 'update'])->name('module.update');
|
||||||
|
Route::delete('module/{module}', [\App\Http\Controllers\Device\Tabs\ModuleController::class, 'delete'])->name('module.delete');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::match(['get', 'post'], 'device/{device}/{tab?}/{vars?}', 'DeviceController@index')
|
Route::match(['get', 'post'], 'device/{device}/{tab?}/{vars?}', 'DeviceController@index')
|
||||||
|
Loading…
Reference in New Issue
Block a user