mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* 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
85 lines
1.7 KiB
PHP
85 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace LibreNMS\Modules;
|
|
|
|
use App\Models\Device;
|
|
use App\Models\EntPhysical;
|
|
use App\Observers\ModuleModelObserver;
|
|
use LibreNMS\DB\SyncsModels;
|
|
use LibreNMS\Interfaces\Data\DataStorageInterface;
|
|
use LibreNMS\Interfaces\Module;
|
|
use LibreNMS\OS;
|
|
use LibreNMS\Polling\ModuleStatus;
|
|
|
|
class EntityPhysical implements Module
|
|
{
|
|
use SyncsModels;
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function dependencies(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function shouldDiscover(OS $os, ModuleStatus $status): bool
|
|
{
|
|
return $status->isEnabledAndDeviceUp($os->getDevice());
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function shouldPoll(OS $os, ModuleStatus $status): bool
|
|
{
|
|
return $status->isEnabledAndDeviceUp($os->getDevice());
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function discover(OS $os): void
|
|
{
|
|
$inventory = $os->discoverEntityPhysical();
|
|
|
|
ModuleModelObserver::observe(EntPhysical::class);
|
|
$this->syncModels($os->getDevice(), 'entityPhysical', $inventory);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function poll(OS $os, DataStorageInterface $datastore): void
|
|
{
|
|
// no polling
|
|
}
|
|
|
|
public function dataExists(Device $device): bool
|
|
{
|
|
return $device->entityPhysical()->exists();
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function cleanup(Device $device): int
|
|
{
|
|
return $device->entityPhysical()->delete();
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function dump(Device $device)
|
|
{
|
|
return [
|
|
'entPhysical' => $device->entityPhysical()->orderBy('entPhysicalIndex')
|
|
->get()->map->makeHidden(['device_id', 'entPhysical_id']),
|
|
];
|
|
}
|
|
}
|