Files
librenms-librenms/LibreNMS/Modules/EntityPhysical.php
Tony Murray 071076149a 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
2024-09-09 09:09:19 +02:00

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']),
];
}
}