Improved Modern Modules (#14315)

* Improved Modern Modules
Modules now report module dependencies and can dump data for testing
This should serve to the process of building a module more obvious.
cleanup now only requires a device, not an os wrapped around a device
Helper to create a modern module (including the legacy adapter) from a name.

* return false correctly for dump and handle it.

* make sure test data is in the right format.

* wrong isis table name

* sort

* Fix style and lint issues
This commit is contained in:
Tony Murray
2022-09-07 16:53:16 -05:00
committed by GitHub
parent 6342d69b18
commit b44f1546a2
18 changed files with 506 additions and 427 deletions

View File

@@ -20,6 +20,7 @@
namespace LibreNMS\Modules;
use App\Models\Device;
use App\Models\Sla;
use App\Observers\ModuleModelObserver;
use LibreNMS\DB\SyncsModels;
@@ -32,13 +33,21 @@ class Slas implements Module
{
use SyncsModels;
/**
* @inheritDoc
*/
public function dependencies(): array
{
return [];
}
/**
* Discover this module. Heavier processes can be run here
* Run infrequently (default 4 times a day)
*
* @param \LibreNMS\OS $os
*/
public function discover(OS $os)
public function discover(OS $os): void
{
if ($os instanceof SlaDiscovery) {
$slas = $os->discoverSlas();
@@ -54,7 +63,7 @@ class Slas implements Module
*
* @param \LibreNMS\OS $os
*/
public function poll(OS $os)
public function poll(OS $os): void
{
if ($os instanceof SlaPolling) {
// Gather our SLA's from the DB.
@@ -72,11 +81,20 @@ class Slas implements Module
/**
* Remove all DB data for this module.
* This will be run when the module is disabled.
*
* @param \LibreNMS\OS $os
*/
public function cleanup(OS $os)
public function cleanup(Device $device): void
{
$os->getDevice()->slas()->delete();
$device->slas()->delete();
}
/**
* @inheritDoc
*/
public function dump(Device $device)
{
return [
'slas' => $device->slas()->orderBy('sla_nr')
->get()->map->makeHidden(['device_id', 'sla_id']),
];
}
}