From 818fd10d29cc75c22e1e7800b0af6f67503b938e Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Wed, 4 Oct 2023 00:35:20 -0500 Subject: [PATCH] Fix lint issues --- LibreNMS/Interfaces/Module.php | 2 +- LibreNMS/Modules/Availability.php | 2 +- LibreNMS/Modules/Core.php | 2 +- LibreNMS/Modules/Slas.php | 2 +- LibreNMS/Modules/Xdsl.php | 6 +++--- LibreNMS/OS/Fortigate.php | 1 + LibreNMS/OS/Poweralert.php | 3 ++- LibreNMS/OS/Vrp.php | 18 +++++------------- LibreNMS/Poller.php | 7 ++++--- LibreNMS/Waas.php | 5 +++-- 10 files changed, 22 insertions(+), 26 deletions(-) diff --git a/LibreNMS/Interfaces/Module.php b/LibreNMS/Interfaces/Module.php index 856c86024eb6..3a493a73c288 100644 --- a/LibreNMS/Interfaces/Module.php +++ b/LibreNMS/Interfaces/Module.php @@ -61,7 +61,7 @@ public function discover(OS $os): void; * Run frequently (default every 5 minutes) * * @param \LibreNMS\OS $os - * @param \LibreNMS\Interfaces\DataStorageInterface $datastore + * @param \LibreNMS\Interfaces\Data\DataStorageInterface $datastore */ public function poll(OS $os, DataStorageInterface $datastore): void; diff --git a/LibreNMS/Modules/Availability.php b/LibreNMS/Modules/Availability.php index 42e05e09b83a..11e43467508e 100644 --- a/LibreNMS/Modules/Availability.php +++ b/LibreNMS/Modules/Availability.php @@ -105,7 +105,7 @@ public function poll(OS $os, DataStorageInterface $datastore): void */ public function cleanup(Device $device): void { - $os->getDevice()->availability()->delete(); + $device->availability()->delete(); } /** diff --git a/LibreNMS/Modules/Core.php b/LibreNMS/Modules/Core.php index 019d63763f96..50abe79c201d 100644 --- a/LibreNMS/Modules/Core.php +++ b/LibreNMS/Modules/Core.php @@ -298,7 +298,7 @@ private function calculateUptime(OS $os, ?string $sysUpTime, DataStorageInterfac $os->enableGraph('uptime'); - echo 'Uptime: ' . Time::formatInterval($uptime) . PHP_EOL; + Log::info('Uptime: ' . Time::formatInterval($uptime)); $device->uptime = $uptime; } } diff --git a/LibreNMS/Modules/Slas.php b/LibreNMS/Modules/Slas.php index 9d7f59c513c3..50e869e58f63 100644 --- a/LibreNMS/Modules/Slas.php +++ b/LibreNMS/Modules/Slas.php @@ -90,7 +90,7 @@ public function poll(OS $os, DataStorageInterface $datastore): void // The base RRD foreach ($slas as $sla) { - $datastore->put($device, 'sla', [ + $datastore->put($os->getDeviceArray(), 'sla', [ 'sla_nr' => $sla->sla_nr, 'rrd_name' => ['sla', $sla->sla_nr], 'rrd_def' => RrdDefinition::make()->addDataset('rtt', 'GAUGE', 0, 300000), diff --git a/LibreNMS/Modules/Xdsl.php b/LibreNMS/Modules/Xdsl.php index e752b9ec3133..a5e9a372b7b6 100644 --- a/LibreNMS/Modules/Xdsl.php +++ b/LibreNMS/Modules/Xdsl.php @@ -70,9 +70,9 @@ public function shouldDiscover(OS $os, ModuleStatus $status): bool */ public function discover(OS $os): void { - //discover if any port has dsl data. We use the pollXdsl functions, with the store parameter set to false - $this->pollAdsl($os, false); - $this->pollVdsl($os, false); + //discover if any port has dsl data. We use the pollXdsl functions, with the datastore parameter ommitted + $this->pollAdsl($os); + $this->pollVdsl($os); } public function shouldPoll(OS $os, ModuleStatus $status): bool diff --git a/LibreNMS/OS/Fortigate.php b/LibreNMS/OS/Fortigate.php index b328683b90ef..40cd80344537 100644 --- a/LibreNMS/OS/Fortigate.php +++ b/LibreNMS/OS/Fortigate.php @@ -27,6 +27,7 @@ use App\Models\Device; use LibreNMS\Device\WirelessSensor; +use LibreNMS\Interfaces\Data\DataStorageInterface; use LibreNMS\Interfaces\Discovery\Sensors\WirelessApCountDiscovery; use LibreNMS\Interfaces\Discovery\Sensors\WirelessClientsDiscovery; use LibreNMS\Interfaces\Polling\OSPolling; diff --git a/LibreNMS/OS/Poweralert.php b/LibreNMS/OS/Poweralert.php index c262e1c94359..21332a93e971 100644 --- a/LibreNMS/OS/Poweralert.php +++ b/LibreNMS/OS/Poweralert.php @@ -26,6 +26,7 @@ namespace LibreNMS\OS; use App\Models\Device; +use LibreNMS\Interfaces\Data\DataStorageInterface; use LibreNMS\Interfaces\Polling\OSPolling; class Poweralert extends \LibreNMS\OS implements OSPolling @@ -37,7 +38,7 @@ public function discoverOS(Device $device): void $this->customSysName($device); } - public function pollOs(): void + public function pollOS(DataStorageInterface $datastore): void { $this->customSysName($this->getDevice()); } diff --git a/LibreNMS/OS/Vrp.php b/LibreNMS/OS/Vrp.php index 9f4bcf07435d..28e0c1e1bde2 100644 --- a/LibreNMS/OS/Vrp.php +++ b/LibreNMS/OS/Vrp.php @@ -542,15 +542,7 @@ public function pollSlas($slas): void $time = Carbon::parse($data[$owner][$test]['pingResultsLastGoodProbe'] ?? null)->toDateTimeString(); echo 'SLA : ' . $rtt_type . ' ' . $owner . ' ' . $test . '... ' . $sla->rtt . 'ms at ' . $time . "\n"; - $fields = [ - 'rtt' => $sla->rtt, - ]; - - // The base RRD - $rrd_name = ['sla', $sla['sla_nr']]; - $rrd_def = RrdDefinition::make()->addDataset('rtt', 'GAUGE', 0, 300000); - $tags = compact('sla_nr', 'rrd_name', 'rrd_def'); - $datastore->put($device, 'sla', $tags, $fields); + $collected = ['rtt' => $sla->rtt]; // Let's gather some per-type fields. switch ($rtt_type) { @@ -568,13 +560,13 @@ public function pollSlas($slas): void ->addDataset('ProbeResponses', 'GAUGE', 0, 300000) ->addDataset('ProbeLoss', 'GAUGE', 0, 300000); $tags = compact('rrd_name', 'rrd_def', 'sla_nr', 'rtt_type'); - $datastore->put($device, 'sla', $tags, $icmp); - $fields = array_merge($fields, $icmp); + app('Datastore')->put($device, 'sla', $tags, $icmp); + $collected = array_merge($collected, $icmp); break; } - d_echo('The following datasources were collected for #' . $sla['sla_nr'] . ":\n"); - d_echo($fields); + d_echo('The following datasources were collected for #' . $sla->sla_nr. ":\n"); + d_echo($collected); } } } diff --git a/LibreNMS/Poller.php b/LibreNMS/Poller.php index d67294737843..869275241d25 100644 --- a/LibreNMS/Poller.php +++ b/LibreNMS/Poller.php @@ -178,15 +178,15 @@ private function pollModules(): void foreach (array_keys(Config::get('poller_modules')) as $module) { $module_status = Module::status($module, $this->device, $this->isModuleManuallyEnabled($module)); $should_poll = false; + $start_memory = memory_get_usage(); + $module_start = microtime(true); try { $instance = Module::fromName($module); $should_poll = $instance->shouldPoll($this->os, $module_status); if ($should_poll) { - $start_memory = memory_get_usage(); - $module_start = microtime(true); - $this->logger->info("\n#### Load poller module $module ####"); + $this->logger->info("#### Load poller module $module ####\n"); $this->logger->debug($module_status); $instance->poll($this->os, $datastore); @@ -199,6 +199,7 @@ private function pollModules(): void } if ($should_poll) { + $this->logger->info(''); app(MeasurementManager::class)->printChangedStats(); $this->saveModulePerformance($module, $module_start, $start_memory); $this->logger->info("#### Unload poller module $module ####\n"); diff --git a/LibreNMS/Waas.php b/LibreNMS/Waas.php index 19c7618b9b4e..f961dfcb0e5e 100644 --- a/LibreNMS/Waas.php +++ b/LibreNMS/Waas.php @@ -25,17 +25,18 @@ namespace LibreNMS; +use LibreNMS\Interfaces\Data\DataStorageInterface; use LibreNMS\Interfaces\Polling\OSPolling; use LibreNMS\RRD\RrdDefinition; class Waas extends OS implements OSPolling { - public function pollOS(): void + public function pollOS(DataStorageInterface $datastore): void { $connections = \SnmpQuery::get('CISCO-WAN-OPTIMIZATION-MIB::cwoTfoStatsActiveOptConn.0')->value(); if (is_numeric($connections)) { - data_update($this->getDeviceArray(), 'waas_cwotfostatsactiveoptconn', [ + $datastore->put($this->getDeviceArray(), 'waas_cwotfostatsactiveoptconn', [ 'rrd_def' => RrdDefinition::make()->addDataset('connections', 'GAUGE', 0), ], [ 'connections' => $connections,