Poller rewrite (Try 2) (#13525)

* core WIP

* try to finish up

* trim space too
and a couple of cleanups

* update test data

* put escapes back

* another net-snmp difference

* correct copy paste error

* WIP

* Use new code YAY

* a tiny bit more

* Kind of working

* Handle manual modules correctly

* convert core to modern module

* Only save metrics if modules is not overridden

* correct module exists check

* database error handling

* debug handling

* restore bad changes

* Introduce Actions
 RunAlertRulesAction
 UpdateDeviceGroupsAction

* tweaks to output

* Fix some issues in outside code

* Style fixes

* fixes to module status checks

* typehints!

* Use logger only and DI

* OS module not named correctly

* Work on quiet output a bit more

* generically don't change output when disabling debug if the driver is already stack

* Fix missing $device variable for legacy os polling
Fix missing dbFacile functions when no legacy modules polled in RunAlertRulesAction

* restore legacy os module shim

* use the new poller code for tests

* PollingDevice event

* Fix some issues and enable/disable error reporting around legacy modules

* typehints

* fully update baseline

* Use Process for version commands so we don't leak debug output.

* don't detect rrdtool version in ci every time

* style fixes

* Warning fixes

* more fixes

* re-update baseline

* remove diff noise

* fix up alerts

* Catch exceptions in device ip lookup

* Revert accidental snmp.inc.php poller target change
(should have been ?: not ??)
This commit is contained in:
Tony Murray
2021-11-17 19:23:55 -06:00
committed by GitHub
parent 7893b8bebe
commit c79b187d72
48 changed files with 1187 additions and 305 deletions

View File

@@ -51,7 +51,7 @@ class Isis implements Module
* Discover this module. Heavier processes can be run here
* Run infrequently (default 4 times a day)
*
* @param OS $os
* @param \LibreNMS\OS $os
*/
public function discover(OS $os)
{
@@ -68,7 +68,7 @@ class Isis implements Module
* Try to keep this efficient and only run if discovery has indicated there is a reason to run.
* Run frequently (default every 5 minutes)
*
* @param OS $os
* @param \LibreNMS\OS $os
*/
public function poll(OS $os)
{
@@ -89,7 +89,7 @@ class Isis implements Module
* Remove all DB data for this module.
* This will be run when the module is disabled.
*
* @param OS $os
* @param Os $os
*/
public function cleanup(OS $os)
{

View File

@@ -0,0 +1,65 @@
<?php
/**
* LegacyModule.php
*
* -Description-
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @link https://www.librenms.org
*
* @copyright 2021 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace LibreNMS\Modules;
use LibreNMS\Interfaces\Module;
use LibreNMS\OS;
use LibreNMS\Util\Debug;
class LegacyModule implements Module
{
/**
* @var string
*/
private $name;
public function __construct(string $name)
{
$this->name = $name;
}
public function discover(OS $os): void
{
// TODO: Implement discover() method.
}
public function poll(OS $os): void
{
$device = &$os->getDeviceArray();
$device['attribs'] = $os->getDevice()->attribs->toArray();
Debug::disableErrorReporting(); // ignore errors in legacy code
include_once base_path('includes/dbFacile.php');
include base_path("includes/polling/$this->name.inc.php");
Debug::enableErrorReporting(); // and back to normal
}
public function cleanup(OS $os): void
{
// TODO: Implement cleanup() method.
}
}

View File

@@ -108,7 +108,7 @@ class Mempools implements Module
}
/**
* @param OS $os
* @param \LibreNMS\OS $os
* @param \Illuminate\Support\Collection $mempools
* @return \Illuminate\Support\Collection
*/

View File

@@ -42,7 +42,7 @@ class Mpls implements Module
* Discover this module. Heavier processes can be run here
* Run infrequently (default 4 times a day)
*
* @param OS $os
* @param \LibreNMS\OS $os
*/
public function discover(OS $os)
{
@@ -88,7 +88,7 @@ class Mpls implements Module
* Try to keep this efficient and only run if discovery has indicated there is a reason to run.
* Run frequently (default every 5 minutes)
*
* @param OS $os
* @param \LibreNMS\OS $os
*/
public function poll(OS $os)
{
@@ -151,7 +151,7 @@ class Mpls implements Module
* Remove all DB data for this module.
* This will be run when the module is disabled.
*
* @param OS $os
* @param Os $os
*/
public function cleanup(OS $os)
{

View File

@@ -37,7 +37,7 @@ class Nac implements Module
* Discover this module. Heavier processes can be run here
* Run infrequently (default 4 times a day)
*
* @param OS $os
* @param Os $os
*/
public function discover(OS $os)
{
@@ -49,7 +49,7 @@ class Nac implements Module
* Try to keep this efficient and only run if discovery has indicated there is a reason to run.
* Run frequently (default every 5 minutes)
*
* @param OS $os
* @param \LibreNMS\OS $os
*/
public function poll(OS $os)
{
@@ -82,7 +82,7 @@ class Nac implements Module
* Remove all DB data for this module.
* This will be run when the module is disabled.
*
* @param OS $os
* @param \LibreNMS\OS $os
*/
public function cleanup(OS $os)
{

View File

@@ -30,9 +30,9 @@ use LibreNMS\Interfaces\Module;
use LibreNMS\Interfaces\Polling\OSPolling;
use LibreNMS\Util\Url;
class OS implements Module
class Os implements Module
{
public function discover(\LibreNMS\OS $os)
public function discover(\LibreNMS\OS $os): void
{
$this->updateLocation($os);
$this->sysContact($os);
@@ -50,7 +50,7 @@ class OS implements Module
$this->handleChanges($os);
}
public function poll(\LibreNMS\OS $os)
public function poll(\LibreNMS\OS $os): void
{
$deviceModel = $os->getDevice(); /** @var \App\Models\Device $deviceModel */
if ($os instanceof OSPolling) {
@@ -58,6 +58,11 @@ class OS implements Module
} else {
// legacy poller files
global $graphs, $device;
if (empty($device)) {
$device = $os->getDeviceArray();
}
$location = null;
if (is_file(base_path('/includes/polling/os/' . $device['os'] . '.inc.php'))) {
@@ -85,12 +90,12 @@ class OS implements Module
$this->handleChanges($os);
}
public function cleanup(\LibreNMS\OS $os)
public function cleanup(\LibreNMS\OS $os): void
{
// no cleanup needed?
}
private function handleChanges(\LibreNMS\OS $os)
private function handleChanges(\LibreNMS\OS $os): void
{
$device = $os->getDevice();
@@ -104,7 +109,7 @@ class OS implements Module
$device->save();
}
private function updateLocation(\LibreNMS\OS $os)
private function updateLocation(\LibreNMS\OS $os): void
{
$device = $os->getDevice();
$new_location = $device->override_sysLocation ? new Location() : $os->fetchLocation(); // fetch location data from device
@@ -112,7 +117,7 @@ class OS implements Module
optional($device->location)->save();
}
private function sysContact(\LibreNMS\OS $os)
private function sysContact(\LibreNMS\OS $os): void
{
$device = $os->getDevice();
$device->sysContact = snmp_get($os->getDeviceArray(), 'sysContact.0', '-Ovq', 'SNMPv2-MIB');

View File

@@ -39,7 +39,7 @@ class PrinterSupplies implements Module
* Discover this module. Heavier processes can be run here
* Run infrequently (default 4 times a day)
*
* @param OS $os
* @param \LibreNMS\OS $os
*/
public function discover(OS $os)
{
@@ -58,7 +58,7 @@ class PrinterSupplies implements Module
* Try to keep this efficient and only run if discovery has indicated there is a reason to run.
* Run frequently (default every 5 minutes)
*
* @param OS $os
* @param \LibreNMS\OS $os
*/
public function poll(OS $os)
{
@@ -114,7 +114,7 @@ class PrinterSupplies implements Module
* Remove all DB data for this module.
* This will be run when the module is disabled.
*
* @param OS $os
* @param Os $os
*/
public function cleanup(OS $os)
{

View File

@@ -36,7 +36,7 @@ class Slas implements Module
* Discover this module. Heavier processes can be run here
* Run infrequently (default 4 times a day)
*
* @param OS $os
* @param \LibreNMS\OS $os
*/
public function discover(OS $os)
{
@@ -52,7 +52,7 @@ class Slas implements Module
* Try to keep this efficient and only run if discovery has indicated there is a reason to run.
* Run frequently (default every 5 minutes)
*
* @param OS $os
* @param \LibreNMS\OS $os
*/
public function poll(OS $os)
{
@@ -73,7 +73,7 @@ class Slas implements Module
* Remove all DB data for this module.
* This will be run when the module is disabled.
*
* @param OS $os
* @param \LibreNMS\OS $os
*/
public function cleanup(OS $os)
{