mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
This reverts commit 1752d1efd4
.
This commit is contained in:
@@ -33,7 +33,6 @@ namespace LibreNMS\Alert;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use LibreNMS\Enum\AlertState;
|
use LibreNMS\Enum\AlertState;
|
||||||
use Log;
|
|
||||||
|
|
||||||
class AlertRules
|
class AlertRules
|
||||||
{
|
{
|
||||||
@@ -58,7 +57,7 @@ class AlertRules
|
|||||||
}
|
}
|
||||||
//Checks each rule.
|
//Checks each rule.
|
||||||
foreach (AlertUtil::getRules($device_id) as $rule) {
|
foreach (AlertUtil::getRules($device_id) as $rule) {
|
||||||
Log::info('Rule %p#' . $rule['id'] . ' (' . $rule['name'] . '):%n ', ['color' => true]);
|
c_echo('Rule %p#' . $rule['id'] . ' (' . $rule['name'] . '):%n ');
|
||||||
$extra = json_decode($rule['extra'], true);
|
$extra = json_decode($rule['extra'], true);
|
||||||
if (isset($extra['invert'])) {
|
if (isset($extra['invert'])) {
|
||||||
$inv = (bool) $extra['invert'];
|
$inv = (bool) $extra['invert'];
|
||||||
@@ -91,9 +90,9 @@ class AlertRules
|
|||||||
$current_state = dbFetchCell('SELECT state FROM alerts WHERE rule_id = ? AND device_id = ? ORDER BY id DESC LIMIT 1', [$rule['id'], $device_id]);
|
$current_state = dbFetchCell('SELECT state FROM alerts WHERE rule_id = ? AND device_id = ? ORDER BY id DESC LIMIT 1', [$rule['id'], $device_id]);
|
||||||
if ($doalert) {
|
if ($doalert) {
|
||||||
if ($current_state == AlertState::ACKNOWLEDGED) {
|
if ($current_state == AlertState::ACKNOWLEDGED) {
|
||||||
Log::info('Status: %ySKIP%n', ['color' => true]);
|
c_echo('Status: %ySKIP');
|
||||||
} elseif ($current_state >= AlertState::ACTIVE) {
|
} elseif ($current_state >= AlertState::ACTIVE) {
|
||||||
Log::info('Status: %bNOCHG%n', ['color' => true]);
|
c_echo('Status: %bNOCHG');
|
||||||
// NOCHG here doesn't mean no change full stop. It means no change to the alert state
|
// NOCHG here doesn't mean no change full stop. It means no change to the alert state
|
||||||
// So we update the details column with any fresh changes to the alert output we might have.
|
// So we update the details column with any fresh changes to the alert output we might have.
|
||||||
$alert_log = dbFetchRow('SELECT alert_log.id, alert_log.details FROM alert_log,alert_rules WHERE alert_log.rule_id = alert_rules.id && alert_log.device_id = ? && alert_log.rule_id = ? && alert_rules.disabled = 0
|
$alert_log = dbFetchRow('SELECT alert_log.id, alert_log.details FROM alert_log,alert_rules WHERE alert_log.rule_id = alert_rules.id && alert_log.device_id = ? && alert_log.rule_id = ? && alert_rules.disabled = 0
|
||||||
@@ -114,12 +113,12 @@ class AlertRules
|
|||||||
} else {
|
} else {
|
||||||
dbUpdate(['state' => AlertState::ACTIVE, 'open' => 1, 'timestamp' => Carbon::now()], 'alerts', 'device_id = ? && rule_id = ?', [$device_id, $rule['id']]);
|
dbUpdate(['state' => AlertState::ACTIVE, 'open' => 1, 'timestamp' => Carbon::now()], 'alerts', 'device_id = ? && rule_id = ?', [$device_id, $rule['id']]);
|
||||||
}
|
}
|
||||||
Log::info(PHP_EOL . 'Status: %rALERT%n', ['color' => true]);
|
c_echo(PHP_EOL . 'Status: %rALERT');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (! is_null($current_state) && $current_state == AlertState::RECOVERED) {
|
if (! is_null($current_state) && $current_state == AlertState::RECOVERED) {
|
||||||
Log::info('Status: %bNOCHG%n', ['color' => true]);
|
c_echo('Status: %bNOCHG');
|
||||||
} else {
|
} else {
|
||||||
if (dbInsert(['state' => AlertState::RECOVERED, 'device_id' => $device_id, 'rule_id' => $rule['id']], 'alert_log')) {
|
if (dbInsert(['state' => AlertState::RECOVERED, 'device_id' => $device_id, 'rule_id' => $rule['id']], 'alert_log')) {
|
||||||
if (is_null($current_state)) {
|
if (is_null($current_state)) {
|
||||||
@@ -128,10 +127,11 @@ class AlertRules
|
|||||||
dbUpdate(['state' => AlertState::RECOVERED, 'open' => 1, 'note' => '', 'timestamp' => Carbon::now()], 'alerts', 'device_id = ? && rule_id = ?', [$device_id, $rule['id']]);
|
dbUpdate(['state' => AlertState::RECOVERED, 'open' => 1, 'note' => '', 'timestamp' => Carbon::now()], 'alerts', 'device_id = ? && rule_id = ?', [$device_id, $rule['id']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::info(PHP_EOL . 'Status: %gOK%n', ['color' => true]);
|
c_echo(PHP_EOL . 'Status: %gOK');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
c_echo('%n' . PHP_EOL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -51,14 +51,6 @@ class Device
|
|||||||
$this->primary = $device_id;
|
$this->primary = $device_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if a primary device is set
|
|
||||||
*/
|
|
||||||
public function hasPrimary(): bool
|
|
||||||
{
|
|
||||||
return $this->primary !== null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a device by device_id
|
* Get a device by device_id
|
||||||
*
|
*
|
||||||
|
@@ -168,7 +168,7 @@ class Rrd extends BaseDatastore
|
|||||||
$fields = array_filter($fields, function ($key) use ($rrd_def) {
|
$fields = array_filter($fields, function ($key) use ($rrd_def) {
|
||||||
$valid = $rrd_def->isValidDataset($key);
|
$valid = $rrd_def->isValidDataset($key);
|
||||||
if (! $valid) {
|
if (! $valid) {
|
||||||
Log::debug("RRD warning: unused data sent $key");
|
Log::warning("RRD warning: unused data sent $key");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $valid;
|
return $valid;
|
||||||
|
@@ -1,30 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* PollerException.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 <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* @package LibreNMS
|
|
||||||
* @link http://librenms.org
|
|
||||||
* @copyright 2021 Tony Murray
|
|
||||||
* @author Tony Murray <murraytony@gmail.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace LibreNMS\Exceptions;
|
|
||||||
|
|
||||||
class PollerException extends \Exception
|
|
||||||
{
|
|
||||||
}
|
|
@@ -33,7 +33,7 @@ interface Module
|
|||||||
* Discover this module. Heavier processes can be run here
|
* Discover this module. Heavier processes can be run here
|
||||||
* Run infrequently (default 4 times a day)
|
* Run infrequently (default 4 times a day)
|
||||||
*
|
*
|
||||||
* @param \LibreNMS\OS $os
|
* @param OS $os
|
||||||
*/
|
*/
|
||||||
public function discover(OS $os);
|
public function discover(OS $os);
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ interface Module
|
|||||||
* Try to keep this efficient and only run if discovery has indicated there is a reason to run.
|
* Try to keep this efficient and only run if discovery has indicated there is a reason to run.
|
||||||
* Run frequently (default every 5 minutes)
|
* Run frequently (default every 5 minutes)
|
||||||
*
|
*
|
||||||
* @param \LibreNMS\OS $os
|
* @param OS $os
|
||||||
*/
|
*/
|
||||||
public function poll(OS $os);
|
public function poll(OS $os);
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ interface Module
|
|||||||
* Remove all DB data for this module.
|
* Remove all DB data for this module.
|
||||||
* This will be run when the module is disabled.
|
* This will be run when the module is disabled.
|
||||||
*
|
*
|
||||||
* @param \LibreNMS\OS $os
|
* @param OS $os
|
||||||
*/
|
*/
|
||||||
public function cleanup(OS $os);
|
public function cleanup(OS $os);
|
||||||
}
|
}
|
||||||
|
@@ -51,7 +51,7 @@ class Isis implements Module
|
|||||||
* Discover this module. Heavier processes can be run here
|
* Discover this module. Heavier processes can be run here
|
||||||
* Run infrequently (default 4 times a day)
|
* Run infrequently (default 4 times a day)
|
||||||
*
|
*
|
||||||
* @param \LibreNMS\OS $os
|
* @param OS $os
|
||||||
*/
|
*/
|
||||||
public function discover(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.
|
* Try to keep this efficient and only run if discovery has indicated there is a reason to run.
|
||||||
* Run frequently (default every 5 minutes)
|
* Run frequently (default every 5 minutes)
|
||||||
*
|
*
|
||||||
* @param \LibreNMS\OS $os
|
* @param OS $os
|
||||||
*/
|
*/
|
||||||
public function poll(OS $os)
|
public function poll(OS $os)
|
||||||
{
|
{
|
||||||
@@ -89,7 +89,7 @@ class Isis implements Module
|
|||||||
* Remove all DB data for this module.
|
* Remove all DB data for this module.
|
||||||
* This will be run when the module is disabled.
|
* This will be run when the module is disabled.
|
||||||
*
|
*
|
||||||
* @param Os $os
|
* @param OS $os
|
||||||
*/
|
*/
|
||||||
public function cleanup(OS $os)
|
public function cleanup(OS $os)
|
||||||
{
|
{
|
||||||
|
@@ -1,65 +0,0 @@
|
|||||||
<?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.
|
|
||||||
}
|
|
||||||
}
|
|
@@ -108,7 +108,7 @@ class Mempools implements Module
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \LibreNMS\OS $os
|
* @param OS $os
|
||||||
* @param \Illuminate\Support\Collection $mempools
|
* @param \Illuminate\Support\Collection $mempools
|
||||||
* @return \Illuminate\Support\Collection
|
* @return \Illuminate\Support\Collection
|
||||||
*/
|
*/
|
||||||
|
@@ -42,7 +42,7 @@ class Mpls implements Module
|
|||||||
* Discover this module. Heavier processes can be run here
|
* Discover this module. Heavier processes can be run here
|
||||||
* Run infrequently (default 4 times a day)
|
* Run infrequently (default 4 times a day)
|
||||||
*
|
*
|
||||||
* @param \LibreNMS\OS $os
|
* @param OS $os
|
||||||
*/
|
*/
|
||||||
public function discover(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.
|
* Try to keep this efficient and only run if discovery has indicated there is a reason to run.
|
||||||
* Run frequently (default every 5 minutes)
|
* Run frequently (default every 5 minutes)
|
||||||
*
|
*
|
||||||
* @param \LibreNMS\OS $os
|
* @param OS $os
|
||||||
*/
|
*/
|
||||||
public function poll(OS $os)
|
public function poll(OS $os)
|
||||||
{
|
{
|
||||||
@@ -151,7 +151,7 @@ class Mpls implements Module
|
|||||||
* Remove all DB data for this module.
|
* Remove all DB data for this module.
|
||||||
* This will be run when the module is disabled.
|
* This will be run when the module is disabled.
|
||||||
*
|
*
|
||||||
* @param Os $os
|
* @param OS $os
|
||||||
*/
|
*/
|
||||||
public function cleanup(OS $os)
|
public function cleanup(OS $os)
|
||||||
{
|
{
|
||||||
|
@@ -37,7 +37,7 @@ class Nac implements Module
|
|||||||
* Discover this module. Heavier processes can be run here
|
* Discover this module. Heavier processes can be run here
|
||||||
* Run infrequently (default 4 times a day)
|
* Run infrequently (default 4 times a day)
|
||||||
*
|
*
|
||||||
* @param Os $os
|
* @param OS $os
|
||||||
*/
|
*/
|
||||||
public function discover(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.
|
* Try to keep this efficient and only run if discovery has indicated there is a reason to run.
|
||||||
* Run frequently (default every 5 minutes)
|
* Run frequently (default every 5 minutes)
|
||||||
*
|
*
|
||||||
* @param \LibreNMS\OS $os
|
* @param OS $os
|
||||||
*/
|
*/
|
||||||
public function poll(OS $os)
|
public function poll(OS $os)
|
||||||
{
|
{
|
||||||
@@ -82,7 +82,7 @@ class Nac implements Module
|
|||||||
* Remove all DB data for this module.
|
* Remove all DB data for this module.
|
||||||
* This will be run when the module is disabled.
|
* This will be run when the module is disabled.
|
||||||
*
|
*
|
||||||
* @param \LibreNMS\OS $os
|
* @param OS $os
|
||||||
*/
|
*/
|
||||||
public function cleanup(OS $os)
|
public function cleanup(OS $os)
|
||||||
{
|
{
|
||||||
|
@@ -30,9 +30,9 @@ use LibreNMS\Interfaces\Module;
|
|||||||
use LibreNMS\Interfaces\Polling\OSPolling;
|
use LibreNMS\Interfaces\Polling\OSPolling;
|
||||||
use LibreNMS\Util\Url;
|
use LibreNMS\Util\Url;
|
||||||
|
|
||||||
class Os implements Module
|
class OS implements Module
|
||||||
{
|
{
|
||||||
public function discover(\LibreNMS\OS $os): void
|
public function discover(\LibreNMS\OS $os)
|
||||||
{
|
{
|
||||||
$this->updateLocation($os);
|
$this->updateLocation($os);
|
||||||
$this->sysContact($os);
|
$this->sysContact($os);
|
||||||
@@ -50,7 +50,7 @@ class Os implements Module
|
|||||||
$this->handleChanges($os);
|
$this->handleChanges($os);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function poll(\LibreNMS\OS $os): void
|
public function poll(\LibreNMS\OS $os)
|
||||||
{
|
{
|
||||||
$deviceModel = $os->getDevice(); /** @var \App\Models\Device $deviceModel */
|
$deviceModel = $os->getDevice(); /** @var \App\Models\Device $deviceModel */
|
||||||
if ($os instanceof OSPolling) {
|
if ($os instanceof OSPolling) {
|
||||||
@@ -58,11 +58,6 @@ class Os implements Module
|
|||||||
} else {
|
} else {
|
||||||
// legacy poller files
|
// legacy poller files
|
||||||
global $graphs, $device;
|
global $graphs, $device;
|
||||||
|
|
||||||
if (empty($device)) {
|
|
||||||
$device = $os->getDeviceArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
$location = null;
|
$location = null;
|
||||||
|
|
||||||
if (is_file(base_path('/includes/polling/os/' . $device['os'] . '.inc.php'))) {
|
if (is_file(base_path('/includes/polling/os/' . $device['os'] . '.inc.php'))) {
|
||||||
@@ -90,12 +85,12 @@ class Os implements Module
|
|||||||
$this->handleChanges($os);
|
$this->handleChanges($os);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cleanup(\LibreNMS\OS $os): void
|
public function cleanup(\LibreNMS\OS $os)
|
||||||
{
|
{
|
||||||
// no cleanup needed?
|
// no cleanup needed?
|
||||||
}
|
}
|
||||||
|
|
||||||
private function handleChanges(\LibreNMS\OS $os): void
|
private function handleChanges(\LibreNMS\OS $os)
|
||||||
{
|
{
|
||||||
$device = $os->getDevice();
|
$device = $os->getDevice();
|
||||||
|
|
||||||
@@ -109,7 +104,7 @@ class Os implements Module
|
|||||||
$device->save();
|
$device->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function updateLocation(\LibreNMS\OS $os): void
|
private function updateLocation(\LibreNMS\OS $os)
|
||||||
{
|
{
|
||||||
$device = $os->getDevice();
|
$device = $os->getDevice();
|
||||||
$new_location = $device->override_sysLocation ? new Location() : $os->fetchLocation(); // fetch location data from device
|
$new_location = $device->override_sysLocation ? new Location() : $os->fetchLocation(); // fetch location data from device
|
||||||
@@ -117,7 +112,7 @@ class Os implements Module
|
|||||||
optional($device->location)->save();
|
optional($device->location)->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function sysContact(\LibreNMS\OS $os): void
|
private function sysContact(\LibreNMS\OS $os)
|
||||||
{
|
{
|
||||||
$device = $os->getDevice();
|
$device = $os->getDevice();
|
||||||
$device->sysContact = snmp_get($os->getDeviceArray(), 'sysContact.0', '-Ovq', 'SNMPv2-MIB');
|
$device->sysContact = snmp_get($os->getDeviceArray(), 'sysContact.0', '-Ovq', 'SNMPv2-MIB');
|
@@ -39,7 +39,7 @@ class PrinterSupplies implements Module
|
|||||||
* Discover this module. Heavier processes can be run here
|
* Discover this module. Heavier processes can be run here
|
||||||
* Run infrequently (default 4 times a day)
|
* Run infrequently (default 4 times a day)
|
||||||
*
|
*
|
||||||
* @param \LibreNMS\OS $os
|
* @param OS $os
|
||||||
*/
|
*/
|
||||||
public function discover(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.
|
* Try to keep this efficient and only run if discovery has indicated there is a reason to run.
|
||||||
* Run frequently (default every 5 minutes)
|
* Run frequently (default every 5 minutes)
|
||||||
*
|
*
|
||||||
* @param \LibreNMS\OS $os
|
* @param OS $os
|
||||||
*/
|
*/
|
||||||
public function poll(OS $os)
|
public function poll(OS $os)
|
||||||
{
|
{
|
||||||
@@ -114,7 +114,7 @@ class PrinterSupplies implements Module
|
|||||||
* Remove all DB data for this module.
|
* Remove all DB data for this module.
|
||||||
* This will be run when the module is disabled.
|
* This will be run when the module is disabled.
|
||||||
*
|
*
|
||||||
* @param Os $os
|
* @param OS $os
|
||||||
*/
|
*/
|
||||||
public function cleanup(OS $os)
|
public function cleanup(OS $os)
|
||||||
{
|
{
|
||||||
|
@@ -36,7 +36,7 @@ class Slas implements Module
|
|||||||
* Discover this module. Heavier processes can be run here
|
* Discover this module. Heavier processes can be run here
|
||||||
* Run infrequently (default 4 times a day)
|
* Run infrequently (default 4 times a day)
|
||||||
*
|
*
|
||||||
* @param \LibreNMS\OS $os
|
* @param OS $os
|
||||||
*/
|
*/
|
||||||
public function discover(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.
|
* Try to keep this efficient and only run if discovery has indicated there is a reason to run.
|
||||||
* Run frequently (default every 5 minutes)
|
* Run frequently (default every 5 minutes)
|
||||||
*
|
*
|
||||||
* @param \LibreNMS\OS $os
|
* @param OS $os
|
||||||
*/
|
*/
|
||||||
public function poll(OS $os)
|
public function poll(OS $os)
|
||||||
{
|
{
|
||||||
@@ -73,7 +73,7 @@ class Slas implements Module
|
|||||||
* Remove all DB data for this module.
|
* Remove all DB data for this module.
|
||||||
* This will be run when the module is disabled.
|
* This will be run when the module is disabled.
|
||||||
*
|
*
|
||||||
* @param \LibreNMS\OS $os
|
* @param OS $os
|
||||||
*/
|
*/
|
||||||
public function cleanup(OS $os)
|
public function cleanup(OS $os)
|
||||||
{
|
{
|
||||||
|
@@ -127,7 +127,7 @@ class OS implements
|
|||||||
$this->graphs[$name] = true;
|
$this->graphs[$name] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function persistGraphs(): void
|
public function persistGraphs()
|
||||||
{
|
{
|
||||||
$device = $this->getDevice();
|
$device = $this->getDevice();
|
||||||
$graphs = collect(array_keys($this->graphs));
|
$graphs = collect(array_keys($this->graphs));
|
||||||
|
@@ -1,374 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Poller.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;
|
|
||||||
|
|
||||||
use App\Events\DevicePolled;
|
|
||||||
use App\Events\PollingDevice;
|
|
||||||
use App\Models\Device;
|
|
||||||
use App\Polling\Measure\Measurement;
|
|
||||||
use App\Polling\Measure\MeasurementManager;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use DB;
|
|
||||||
use Exception;
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use LibreNMS\Exceptions\PollerException;
|
|
||||||
use LibreNMS\Modules\LegacyModule;
|
|
||||||
use LibreNMS\Polling\ConnectivityHelper;
|
|
||||||
use LibreNMS\RRD\RrdDefinition;
|
|
||||||
use LibreNMS\Util\Debug;
|
|
||||||
use LibreNMS\Util\Dns;
|
|
||||||
use LibreNMS\Util\Git;
|
|
||||||
use LibreNMS\Util\StringHelpers;
|
|
||||||
use Psr\Log\LoggerInterface;
|
|
||||||
|
|
||||||
class Poller
|
|
||||||
{
|
|
||||||
/** @var string */
|
|
||||||
private $device_spec;
|
|
||||||
/** @var array */
|
|
||||||
private $module_override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Device
|
|
||||||
*/
|
|
||||||
private $device;
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $deviceArray;
|
|
||||||
/**
|
|
||||||
* @var \LibreNMS\OS|\LibreNMS\OS\Generic
|
|
||||||
*/
|
|
||||||
private $os;
|
|
||||||
/**
|
|
||||||
* @var LoggerInterface
|
|
||||||
*/
|
|
||||||
private $logger;
|
|
||||||
|
|
||||||
public function __construct(string $device_spec, array $module_override, LoggerInterface $logger)
|
|
||||||
{
|
|
||||||
$this->device_spec = $device_spec;
|
|
||||||
$this->module_override = $module_override;
|
|
||||||
$this->logger = $logger;
|
|
||||||
$this->parseModules();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function poll(): int
|
|
||||||
{
|
|
||||||
$polled = 0;
|
|
||||||
$this->printHeader();
|
|
||||||
|
|
||||||
if (Debug::isEnabled()) {
|
|
||||||
\LibreNMS\Util\OS::updateCache(true); // Force update of OS Cache
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->logger->info("Starting polling run:\n");
|
|
||||||
|
|
||||||
foreach ($this->buildDeviceQuery()->pluck('device_id') as $device_id) {
|
|
||||||
$this->initDevice($device_id);
|
|
||||||
PollingDevice::dispatch($this->device);
|
|
||||||
$this->os = OS::make($this->deviceArray);
|
|
||||||
|
|
||||||
$helper = new ConnectivityHelper($this->device);
|
|
||||||
$helper->saveMetrics();
|
|
||||||
|
|
||||||
$measurement = Measurement::start('poll');
|
|
||||||
$measurement->manager()->checkpoint(); // don't count previous stats
|
|
||||||
|
|
||||||
if ($helper->isUp()) {
|
|
||||||
$this->pollModules();
|
|
||||||
}
|
|
||||||
$measurement->end();
|
|
||||||
|
|
||||||
if (empty($this->module_override)) {
|
|
||||||
// record performance
|
|
||||||
$measurement->manager()->record('device', $measurement);
|
|
||||||
$this->device->last_polled = Carbon::now();
|
|
||||||
$this->device->last_ping_timetaken = $measurement->getDuration();
|
|
||||||
app('Datastore')->put($this->deviceArray, 'poller-perf', [
|
|
||||||
'rrd_def' => RrdDefinition::make()->addDataset('poller', 'GAUGE', 0),
|
|
||||||
'module' => 'ALL',
|
|
||||||
], [
|
|
||||||
'poller' => $measurement->getDuration(),
|
|
||||||
]);
|
|
||||||
$this->os->enableGraph('poller_perf');
|
|
||||||
|
|
||||||
if ($helper->canPing()) {
|
|
||||||
$this->os->enableGraph('ping_perf');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->os->persistGraphs();
|
|
||||||
$this->logger->info(sprintf("Enabled graphs (%s): %s\n\n",
|
|
||||||
$this->device->graphs->count(),
|
|
||||||
$this->device->graphs->pluck('graph')->implode(' ')
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->device->save();
|
|
||||||
$polled++;
|
|
||||||
|
|
||||||
DevicePolled::dispatch($this->device);
|
|
||||||
|
|
||||||
$this->logger->info(sprintf("\n>>> Polled %s (%s) in %0.3f seconds <<<",
|
|
||||||
$this->device->displayName(),
|
|
||||||
$this->device->device_id,
|
|
||||||
$measurement->getDuration()));
|
|
||||||
|
|
||||||
// check if the poll took too long and log an event
|
|
||||||
if ($measurement->getDuration() > Config::get('rrd.step')) {
|
|
||||||
\Log::event('Polling took longer than ' . round(Config::get('rrd.step') / 60, 2) .
|
|
||||||
' minutes! This will cause gaps in graphs.', $this->device, 'system', 5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $polled;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function pollModules(): void
|
|
||||||
{
|
|
||||||
$this->filterModules();
|
|
||||||
|
|
||||||
// update $device array status
|
|
||||||
$this->deviceArray['status'] = $this->device->status;
|
|
||||||
$this->deviceArray['status_reason'] = $this->device->status_reason;
|
|
||||||
|
|
||||||
// import legacy garbage
|
|
||||||
include_once base_path('includes/functions.php');
|
|
||||||
include_once base_path('includes/common.php');
|
|
||||||
include_once base_path('includes/polling/functions.inc.php');
|
|
||||||
include_once base_path('includes/snmp.inc.php');
|
|
||||||
include_once base_path('includes/datastore.inc.php'); // remove me
|
|
||||||
|
|
||||||
foreach (Config::get('poller_modules') as $module => $module_status) {
|
|
||||||
if ($this->isModuleEnabled($module, $module_status)) {
|
|
||||||
$start_memory = memory_get_usage();
|
|
||||||
$module_start = microtime(true);
|
|
||||||
$this->logger->info("\n#### Load poller module $module ####");
|
|
||||||
|
|
||||||
try {
|
|
||||||
$module_class = StringHelpers::toClass($module, '\\LibreNMS\\Modules\\');
|
|
||||||
$instance = class_exists($module_class) ? new $module_class : new LegacyModule($module);
|
|
||||||
$instance->poll($this->os);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
// isolate module exceptions so they don't disrupt the polling process
|
|
||||||
$this->logger->error("Error in $module module. " . $e->getMessage() . PHP_EOL . $e->getTraceAsString() . PHP_EOL);
|
|
||||||
}
|
|
||||||
|
|
||||||
app(MeasurementManager::class)->printChangedStats();
|
|
||||||
$this->saveModulePerformance($module, $module_start, $start_memory);
|
|
||||||
$this->logger->info("#### Unload poller module $module ####\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function saveModulePerformance(string $module, float $start_time, int $start_memory): void
|
|
||||||
{
|
|
||||||
$module_time = microtime(true) - $start_time;
|
|
||||||
$module_mem = (memory_get_usage() - $start_memory);
|
|
||||||
|
|
||||||
$this->logger->info(sprintf(">> Runtime for poller module '%s': %.4f seconds with %s bytes", $module, $module_time, $module_mem));
|
|
||||||
|
|
||||||
app('Datastore')->put($this->deviceArray, 'poller-perf', [
|
|
||||||
'module' => $module,
|
|
||||||
'rrd_def' => RrdDefinition::make()->addDataset('poller', 'GAUGE', 0),
|
|
||||||
'rrd_name' => ['poller-perf', $module],
|
|
||||||
], [
|
|
||||||
'poller' => $module_time,
|
|
||||||
]);
|
|
||||||
$this->os->enableGraph('poller_modules_perf');
|
|
||||||
}
|
|
||||||
|
|
||||||
private function isModuleEnabled(string $module, bool $global_status): bool
|
|
||||||
{
|
|
||||||
if (! empty($this->module_override)) {
|
|
||||||
if (in_array($module, $this->module_override)) {
|
|
||||||
$this->logger->debug("Module $module manually enabled");
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$os_module_status = Config::get("os.{$this->device->os}.poller_modules.$module");
|
|
||||||
$device_attrib = $this->device->getAttrib('poll_' . $module);
|
|
||||||
$this->logger->debug(sprintf('Modules status: Global %s OS %s Device %s',
|
|
||||||
$global_status ? '+' : '-',
|
|
||||||
$os_module_status === null ? ' ' : ($os_module_status ? '+' : '-'),
|
|
||||||
$device_attrib === null ? ' ' : ($device_attrib ? '+' : '-')
|
|
||||||
));
|
|
||||||
|
|
||||||
if ($device_attrib
|
|
||||||
|| ($os_module_status && $device_attrib === null)
|
|
||||||
|| ($global_status && $os_module_status === null && $device_attrib === null)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$reason = $device_attrib !== null ? 'by device'
|
|
||||||
: ($os_module_status === null || $os_module_status ? 'globally' : 'by OS');
|
|
||||||
$this->logger->debug("Module [ $module ] disabled $reason");
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function moduleExists(string $module): bool
|
|
||||||
{
|
|
||||||
return class_exists(StringHelpers::toClass($module, '\\LibreNMS\\Modules\\'))
|
|
||||||
|| is_file("includes/polling/$module.inc.php");
|
|
||||||
}
|
|
||||||
|
|
||||||
private function buildDeviceQuery(): Builder
|
|
||||||
{
|
|
||||||
$query = Device::query();
|
|
||||||
|
|
||||||
if (empty($this->device_spec)) {
|
|
||||||
throw new PollerException('Invalid device spec');
|
|
||||||
} elseif ($this->device_spec == 'all') {
|
|
||||||
return $query;
|
|
||||||
} elseif ($this->device_spec == 'even') {
|
|
||||||
return $query->where(DB::raw('device_id % 2'), 0);
|
|
||||||
} elseif ($this->device_spec == 'odd') {
|
|
||||||
return $query->where(DB::raw('device_id % 2'), 1);
|
|
||||||
} elseif (is_numeric($this->device_spec)) {
|
|
||||||
return $query->where('device_id', $this->device_spec);
|
|
||||||
} elseif (Str::contains($this->device_spec, '*')) {
|
|
||||||
return $query->where('hostname', 'like', str_replace('*', '%', $this->device_spec));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $query->where('hostname', $this->device_spec);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function initDevice(int $device_id): void
|
|
||||||
{
|
|
||||||
\DeviceCache::setPrimary($device_id);
|
|
||||||
$this->device = \DeviceCache::getPrimary();
|
|
||||||
$this->device->ip = $this->device->overwrite_ip ?: Dns::lookupIp($this->device);
|
|
||||||
|
|
||||||
$this->deviceArray = $this->device->toArray();
|
|
||||||
if ($os_group = Config::get("os.{$this->device->os}.group")) {
|
|
||||||
$this->deviceArray['os_group'] = $os_group;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->printDeviceInfo($os_group);
|
|
||||||
$this->initRrdDirectory();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function initRrdDirectory(): void
|
|
||||||
{
|
|
||||||
$host_rrd = \Rrd::name($this->device->hostname, '', '');
|
|
||||||
if (Config::get('rrd.enable', true) && ! is_dir($host_rrd)) {
|
|
||||||
mkdir($host_rrd);
|
|
||||||
$this->logger->info("Created directory : $host_rrd");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function parseModules(): void
|
|
||||||
{
|
|
||||||
foreach ($this->module_override as $index => $module) {
|
|
||||||
// parse submodules (only supported by some modules)
|
|
||||||
if (Str::contains($module, '/')) {
|
|
||||||
[$module, $submodule] = explode('/', $module, 2);
|
|
||||||
$existing_submodules = Config::get("poller_submodules.$module", []);
|
|
||||||
$existing_submodules[] = $submodule;
|
|
||||||
Config::set("poller_submodules.$module", $existing_submodules);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $this->moduleExists($module)) {
|
|
||||||
unset($this->module_override[$index]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Config::set("poller_modules.$module", 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->printModules();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function filterModules(): void
|
|
||||||
{
|
|
||||||
if ($this->device->snmp_disable) {
|
|
||||||
// only non-snmp modules
|
|
||||||
Config::set('poller_modules', array_intersect_key(Config::get('poller_modules'), [
|
|
||||||
'availability' => true,
|
|
||||||
'ipmi' => true,
|
|
||||||
'unix-agent' => true,
|
|
||||||
]));
|
|
||||||
} else {
|
|
||||||
// we always want the core module to be included, prepend it
|
|
||||||
Config::set('poller_modules', ['core' => true] + Config::get('poller_modules'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function printDeviceInfo(?string $group): void
|
|
||||||
{
|
|
||||||
$this->logger->info(sprintf(<<<'EOH'
|
|
||||||
Hostname: %s %s
|
|
||||||
ID: %s
|
|
||||||
OS: %s
|
|
||||||
IP: %s
|
|
||||||
|
|
||||||
EOH, $this->device->hostname, $group ? " ($group)" : '', $this->device->device_id, $this->device->os, $this->device->ip));
|
|
||||||
}
|
|
||||||
|
|
||||||
private function printModules(): void
|
|
||||||
{
|
|
||||||
$modules = array_map(function ($module) {
|
|
||||||
$submodules = Config::get("poller_submodules.$module");
|
|
||||||
|
|
||||||
return $module . ($submodules ? '(' . implode(',', $submodules) . ')' : '');
|
|
||||||
}, array_keys(Config::get('poller_modules', [])));
|
|
||||||
|
|
||||||
$this->logger->debug('Override poller modules: ' . implode(', ', $modules));
|
|
||||||
}
|
|
||||||
|
|
||||||
private function printHeader(): void
|
|
||||||
{
|
|
||||||
if (Debug::isEnabled() || Debug::isVerbose()) {
|
|
||||||
$version = \LibreNMS\Util\Version::get();
|
|
||||||
$this->logger->info(sprintf(<<<'EOH'
|
|
||||||
===================================
|
|
||||||
Version info:
|
|
||||||
Commit SHA: %s
|
|
||||||
Commit Date: %s
|
|
||||||
DB Schema: %s
|
|
||||||
PHP: %s
|
|
||||||
MySQL: %s
|
|
||||||
RRDTool: %s
|
|
||||||
SNMP: %s
|
|
||||||
==================================
|
|
||||||
EOH,
|
|
||||||
Git::localCommit(),
|
|
||||||
Git::localDate(),
|
|
||||||
vsprintf('%s (%s)', $version->database()),
|
|
||||||
phpversion(),
|
|
||||||
\LibreNMS\DB\Eloquent::isConnected() ? \LibreNMS\DB\Eloquent::version() : '?',
|
|
||||||
$version->rrdtool(),
|
|
||||||
$version->netSnmp()
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -32,13 +32,7 @@ use Log;
|
|||||||
|
|
||||||
class Debug
|
class Debug
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private static $debug = false;
|
private static $debug = false;
|
||||||
/**
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private static $verbose = false;
|
private static $verbose = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,12 +49,20 @@ class Debug
|
|||||||
restore_error_handler(); // disable Laravel error handler
|
restore_error_handler(); // disable Laravel error handler
|
||||||
|
|
||||||
if (self::$debug) {
|
if (self::$debug) {
|
||||||
self::enableErrorReporting();
|
ini_set('display_errors', '1');
|
||||||
|
ini_set('display_startup_errors', '1');
|
||||||
|
ini_set('log_errors', '0');
|
||||||
|
error_reporting(E_ALL & ~E_NOTICE);
|
||||||
|
|
||||||
self::enableCliDebugOutput();
|
self::enableCliDebugOutput();
|
||||||
self::enableQueryDebug();
|
self::enableQueryDebug();
|
||||||
} else {
|
} else {
|
||||||
self::disableErrorReporting($silence);
|
ini_set('display_errors', '0');
|
||||||
self::disableCliDebugOutput($silence);
|
ini_set('display_startup_errors', '0');
|
||||||
|
ini_set('log_errors', '1');
|
||||||
|
error_reporting($silence ? 0 : E_ERROR);
|
||||||
|
|
||||||
|
self::disableCliDebugOutput();
|
||||||
self::disableQueryDebug();
|
self::disableQueryDebug();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +92,7 @@ class Debug
|
|||||||
return self::$verbose;
|
return self::$verbose;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function disableQueryDebug(): void
|
public static function disableQueryDebug()
|
||||||
{
|
{
|
||||||
$db = Eloquent::DB();
|
$db = Eloquent::DB();
|
||||||
|
|
||||||
@@ -100,21 +102,21 @@ class Debug
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function enableCliDebugOutput(): void
|
public static function enableCliDebugOutput()
|
||||||
{
|
{
|
||||||
if (Laravel::isBooted() && App::runningInConsole()) {
|
if (Laravel::isBooted() && App::runningInConsole()) {
|
||||||
Log::setDefaultDriver('console_debug');
|
Log::setDefaultDriver('console');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function disableCliDebugOutput(bool $silence): void
|
public static function disableCliDebugOutput()
|
||||||
{
|
{
|
||||||
if (Laravel::isBooted() && Log::getDefaultDriver() !== 'stack') {
|
if (Laravel::isBooted()) {
|
||||||
Log::setDefaultDriver(app()->runningInConsole() && ! $silence ? 'console' : 'stack');
|
Log::setDefaultDriver('stack');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function enableQueryDebug(): void
|
public static function enableQueryDebug()
|
||||||
{
|
{
|
||||||
static $sql_debug_enabled;
|
static $sql_debug_enabled;
|
||||||
$db = Eloquent::DB();
|
$db = Eloquent::DB();
|
||||||
@@ -139,26 +141,4 @@ class Debug
|
|||||||
$sql_debug_enabled = true;
|
$sql_debug_enabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Disable error reporting, do not use with new code
|
|
||||||
*/
|
|
||||||
public static function disableErrorReporting(bool $silence = false): void
|
|
||||||
{
|
|
||||||
ini_set('display_errors', '0');
|
|
||||||
ini_set('display_startup_errors', '0');
|
|
||||||
ini_set('log_errors', '1');
|
|
||||||
error_reporting($silence ? 0 : E_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enable error reporting. Please call after disabling for legacy code
|
|
||||||
*/
|
|
||||||
public static function enableErrorReporting(): void
|
|
||||||
{
|
|
||||||
ini_set('display_errors', '1');
|
|
||||||
ini_set('display_startup_errors', '1');
|
|
||||||
ini_set('log_errors', '0');
|
|
||||||
error_reporting(E_ALL & ~E_NOTICE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
namespace LibreNMS\Util;
|
namespace LibreNMS\Util;
|
||||||
|
|
||||||
use App\Models\Device;
|
|
||||||
use LibreNMS\Interfaces\Geocoder;
|
use LibreNMS\Interfaces\Geocoder;
|
||||||
|
|
||||||
class Dns implements Geocoder
|
class Dns implements Geocoder
|
||||||
@@ -37,19 +36,6 @@ class Dns implements Geocoder
|
|||||||
$this->resolver = new \Net_DNS2_Resolver();
|
$this->resolver = new \Net_DNS2_Resolver();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function lookupIp(Device $device): ?string
|
|
||||||
{
|
|
||||||
if (IP::isValid($device->hostname)) {
|
|
||||||
return $device->hostname;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($device->transport == 'udp6' || $device->transport == 'tcp6') {
|
|
||||||
return dns_get_record($device['hostname'], DNS_AAAA)[0]['ipv6'] ?? null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return dns_get_record($device['hostname'], DNS_A)[0]['ip'] ?? null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $domain Domain which has to be parsed
|
* @param string $domain Domain which has to be parsed
|
||||||
* @param string $record DNS Record which should be searched
|
* @param string $record DNS Record which should be searched
|
||||||
|
@@ -25,32 +25,21 @@
|
|||||||
|
|
||||||
namespace LibreNMS\Util;
|
namespace LibreNMS\Util;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use LibreNMS\Config;
|
use LibreNMS\Config;
|
||||||
|
|
||||||
class Git
|
class Git
|
||||||
{
|
{
|
||||||
public static function repoPresent(): bool
|
public static function repoPresent()
|
||||||
{
|
{
|
||||||
$install_dir = Config::get('install_dir', realpath(__DIR__ . '/../..'));
|
$install_dir = Config::get('install_dir', realpath(__DIR__ . '/../..'));
|
||||||
|
|
||||||
return file_exists("$install_dir/.git");
|
return file_exists("$install_dir/.git");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function binaryExists(): bool
|
public static function binaryExists()
|
||||||
{
|
{
|
||||||
exec('git > /dev/null 2>&1', $response, $exit_code);
|
exec('git > /dev/null 2>&1', $response, $exit_code);
|
||||||
|
|
||||||
return $exit_code === 1;
|
return $exit_code === 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function localCommit(): string
|
|
||||||
{
|
|
||||||
return rtrim(exec("git show --pretty='%H' -s HEAD"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function localDate(): Carbon
|
|
||||||
{
|
|
||||||
return \Date::createFromTimestamp(exec("git show --pretty='%ct' -s HEAD"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -33,7 +33,6 @@ use LibreNMS\Config;
|
|||||||
use LibreNMS\Data\Source\SnmpResponse;
|
use LibreNMS\Data\Source\SnmpResponse;
|
||||||
use LibreNMS\Exceptions\FileNotFoundException;
|
use LibreNMS\Exceptions\FileNotFoundException;
|
||||||
use LibreNMS\Exceptions\InvalidModuleException;
|
use LibreNMS\Exceptions\InvalidModuleException;
|
||||||
use LibreNMS\Poller;
|
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
class ModuleTestHelper
|
class ModuleTestHelper
|
||||||
@@ -80,6 +79,8 @@ class ModuleTestHelper
|
|||||||
*/
|
*/
|
||||||
public function __construct($modules, $os, $variant = '')
|
public function __construct($modules, $os, $variant = '')
|
||||||
{
|
{
|
||||||
|
global $influxdb;
|
||||||
|
|
||||||
$this->modules = self::resolveModuleDependencies((array) $modules);
|
$this->modules = self::resolveModuleDependencies((array) $modules);
|
||||||
$this->os = strtolower($os);
|
$this->os = strtolower($os);
|
||||||
$this->variant = strtolower($variant);
|
$this->variant = strtolower($variant);
|
||||||
@@ -195,10 +196,8 @@ class ModuleTestHelper
|
|||||||
$save_vdebug = Debug::isVerbose();
|
$save_vdebug = Debug::isVerbose();
|
||||||
Debug::set();
|
Debug::set();
|
||||||
Debug::setVerbose(false);
|
Debug::setVerbose(false);
|
||||||
\Log::setDefaultDriver('console');
|
|
||||||
discover_device($device, $this->parseArgs('discovery'));
|
discover_device($device, $this->parseArgs('discovery'));
|
||||||
$poller = app(Poller::class, ['device_spec' => $device_id, 'module_override' => $this->modules]);
|
poll_device($device, $this->parseArgs('poller'));
|
||||||
$poller->poll();
|
|
||||||
Debug::set($save_debug);
|
Debug::set($save_debug);
|
||||||
Debug::setVerbose($save_vdebug);
|
Debug::setVerbose($save_vdebug);
|
||||||
$collection_output = ob_get_contents();
|
$collection_output = ob_get_contents();
|
||||||
@@ -534,7 +533,6 @@ class ModuleTestHelper
|
|||||||
{
|
{
|
||||||
global $device;
|
global $device;
|
||||||
Config::set('rrd.enable', false); // disable rrd
|
Config::set('rrd.enable', false); // disable rrd
|
||||||
Config::set('rrdtool_version', '1.7.2'); // don't detect rrdtool version, rrdtool is not install on ci
|
|
||||||
|
|
||||||
if (! is_file($this->snmprec_file)) {
|
if (! is_file($this->snmprec_file)) {
|
||||||
throw new FileNotFoundException("$this->snmprec_file does not exist!");
|
throw new FileNotFoundException("$this->snmprec_file does not exist!");
|
||||||
@@ -594,7 +592,7 @@ class ModuleTestHelper
|
|||||||
|
|
||||||
// Dump the discovered data
|
// Dump the discovered data
|
||||||
$data = array_merge_recursive($data, $this->dumpDb($device['device_id'], $discovered_modules, 'discovery'));
|
$data = array_merge_recursive($data, $this->dumpDb($device['device_id'], $discovered_modules, 'discovery'));
|
||||||
DeviceCache::get($device_id)->refresh(); // refresh the device
|
$device = device_by_id_cache($device_id, true); // refresh the device array
|
||||||
|
|
||||||
// Run the poller
|
// Run the poller
|
||||||
if ($this->quiet) {
|
if ($this->quiet) {
|
||||||
@@ -603,9 +601,7 @@ class ModuleTestHelper
|
|||||||
}
|
}
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
\Log::setDefaultDriver('console');
|
poll_device($device, $this->parseArgs('poller'));
|
||||||
$poller = app(Poller::class, ['device_spec' => $device_id, 'module_override' => $this->modules]);
|
|
||||||
$poller->poll();
|
|
||||||
|
|
||||||
$this->poller_output = ob_get_contents();
|
$this->poller_output = ob_get_contents();
|
||||||
if ($this->quiet) {
|
if ($this->quiet) {
|
||||||
@@ -621,12 +617,12 @@ class ModuleTestHelper
|
|||||||
$polled_modules = array_keys($this->poller_module_output);
|
$polled_modules = array_keys($this->poller_module_output);
|
||||||
|
|
||||||
// Dump polled data
|
// Dump polled data
|
||||||
$data = array_merge_recursive($data, $this->dumpDb($device_id, $polled_modules, 'poller'));
|
$data = array_merge_recursive($data, $this->dumpDb($device['device_id'], $polled_modules, 'poller'));
|
||||||
|
|
||||||
// Remove the test device, we don't need the debug from this
|
// Remove the test device, we don't need the debug from this
|
||||||
if ($device['hostname'] == $snmpsim->getIp()) {
|
if ($device['hostname'] == $snmpsim->getIp()) {
|
||||||
Debug::set(false);
|
Debug::set(false);
|
||||||
delete_device($device_id);
|
delete_device($device['device_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $no_save) {
|
if (! $no_save) {
|
||||||
@@ -725,7 +721,7 @@ class ModuleTestHelper
|
|||||||
// build joins
|
// build joins
|
||||||
$join = '';
|
$join = '';
|
||||||
$select = ["`$table`.*"];
|
$select = ["`$table`.*"];
|
||||||
foreach ($info['joins'] ?? [] as $join_info) {
|
foreach ($info['joins'] ?: [] as $join_info) {
|
||||||
if (isset($join_info['custom'])) {
|
if (isset($join_info['custom'])) {
|
||||||
$join .= ' ' . $join_info['custom'];
|
$join .= ' ' . $join_info['custom'];
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* StringHelpers.php
|
* Text.php
|
||||||
*
|
*
|
||||||
* -Description-
|
* -Description-
|
||||||
*
|
*
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
*
|
*
|
||||||
* @link https://www.librenms.org
|
* @link https://www.librenms.org
|
||||||
*
|
*
|
||||||
* @copyright 2021 Tony Murray
|
* @copyright 2018 Tony Murray
|
||||||
* @author Tony Murray <murraytony@gmail.com>
|
* @author Tony Murray <murraytony@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
namespace LibreNMS\Util;
|
namespace LibreNMS\Util;
|
||||||
|
|
||||||
use LibreNMS\Config;
|
|
||||||
use LibreNMS\DB\Eloquent;
|
use LibreNMS\DB\Eloquent;
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
@@ -34,9 +33,6 @@ class Version
|
|||||||
// Update this on release
|
// Update this on release
|
||||||
const VERSION = '21.11.0';
|
const VERSION = '21.11.0';
|
||||||
|
|
||||||
/**
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
protected $is_git_install = false;
|
protected $is_git_install = false;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
@@ -44,12 +40,12 @@ class Version
|
|||||||
$this->is_git_install = Git::repoPresent() && Git::binaryExists();
|
$this->is_git_install = Git::repoPresent() && Git::binaryExists();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function get(): Version
|
public static function get()
|
||||||
{
|
{
|
||||||
return new static;
|
return new static;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function local(): string
|
public function local()
|
||||||
{
|
{
|
||||||
if ($this->is_git_install && $version = $this->fromGit()) {
|
if ($this->is_git_install && $version = $this->fromGit()) {
|
||||||
return $version;
|
return $version;
|
||||||
@@ -58,7 +54,7 @@ class Version
|
|||||||
return self::VERSION;
|
return self::VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function database(): array
|
public function database()
|
||||||
{
|
{
|
||||||
if (Eloquent::isConnected()) {
|
if (Eloquent::isConnected()) {
|
||||||
try {
|
try {
|
||||||
@@ -76,52 +72,34 @@ class Version
|
|||||||
return ['last' => 'Not Connected', 'total' => 0];
|
return ['last' => 'Not Connected', 'total' => 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function fromGit(): string
|
private function fromGit()
|
||||||
{
|
{
|
||||||
return rtrim(shell_exec('git describe --tags 2>/dev/null'));
|
return rtrim(shell_exec('git describe --tags 2>/dev/null'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function gitChangelog(): string
|
public function gitChangelog()
|
||||||
{
|
{
|
||||||
return $this->is_git_install
|
return $this->is_git_install
|
||||||
? rtrim(shell_exec('git log -10'))
|
? rtrim(shell_exec('git log -10'))
|
||||||
: '';
|
: '';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function gitDate(): string
|
public function gitDate()
|
||||||
{
|
{
|
||||||
return $this->is_git_install
|
return $this->is_git_install
|
||||||
? rtrim(shell_exec("git show --pretty='%ct' -s HEAD"))
|
? rtrim(shell_exec("git show --pretty='%ct' -s HEAD"))
|
||||||
: '';
|
: '';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function python(): string
|
public static function python()
|
||||||
{
|
{
|
||||||
$proc = new Process(['python3', '--version']);
|
$proc = new Process(['python3', '--version']);
|
||||||
$proc->run();
|
$proc->run();
|
||||||
|
|
||||||
if ($proc->getExitCode() !== 0) {
|
if ($proc->getExitCode() !== 0) {
|
||||||
return '';
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return explode(' ', rtrim($proc->getOutput()), 2)[1] ?? '';
|
return explode(' ', rtrim($proc->getOutput()), 2)[1] ?? null;
|
||||||
}
|
|
||||||
|
|
||||||
public function rrdtool(): string
|
|
||||||
{
|
|
||||||
$process = new Process([Config::get('rrdtool', 'rrdtool'), '--version']);
|
|
||||||
$process->run();
|
|
||||||
preg_match('/^RRDtool ([\w.]+) /', $process->getOutput(), $matches);
|
|
||||||
|
|
||||||
return str_replace('1.7.01.7.0', '1.7.0', $matches[1] ?? '');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function netSnmp(): string
|
|
||||||
{
|
|
||||||
$process = new Process([Config::get('snmpget', 'snmpget'), '-V']);
|
|
||||||
$process->run();
|
|
||||||
preg_match('/[\w.]+$/', $process->getErrorOutput(), $matches);
|
|
||||||
|
|
||||||
return $matches[0] ?? '';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -42,7 +42,7 @@ class Python extends BaseValidation
|
|||||||
*/
|
*/
|
||||||
public function validate(Validator $validator)
|
public function validate(Validator $validator)
|
||||||
{
|
{
|
||||||
$version = Version::get()->python();
|
$version = Version::python();
|
||||||
|
|
||||||
if (empty($version)) {
|
if (empty($version)) {
|
||||||
$validator->fail('python3 not found', 'Install Python 3 for your system.');
|
$validator->fail('python3 not found', 'Install Python 3 for your system.');
|
||||||
|
@@ -1,41 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* Action.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 <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* @package LibreNMS
|
|
||||||
* @link http://librenms.org
|
|
||||||
* @copyright 2021 Tony Murray
|
|
||||||
* @author Tony Murray <murraytony@gmail.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace App;
|
|
||||||
|
|
||||||
class Action
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Execute an action and return the results
|
|
||||||
*
|
|
||||||
* @param string $action
|
|
||||||
* @param mixed ...$parameters
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function execute(string $action, ...$parameters)
|
|
||||||
{
|
|
||||||
return app($action, $parameters)->execute();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,55 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* RunAlertRulesAction.php
|
|
||||||
*
|
|
||||||
* Check alert rules for status changes
|
|
||||||
*
|
|
||||||
* 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 http://librenms.org
|
|
||||||
*
|
|
||||||
* @copyright 2021 Tony Murray
|
|
||||||
* @author Tony Murray <murraytony@gmail.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace App\Actions\Alerts;
|
|
||||||
|
|
||||||
use App\Models\Device;
|
|
||||||
use LibreNMS\Alert\AlertRules;
|
|
||||||
|
|
||||||
class RunAlertRulesAction
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var \LibreNMS\Alert\AlertRules
|
|
||||||
*/
|
|
||||||
private $rules;
|
|
||||||
/**
|
|
||||||
* @var \App\Models\Device
|
|
||||||
*/
|
|
||||||
private $device;
|
|
||||||
|
|
||||||
public function __construct(Device $device, AlertRules $rules)
|
|
||||||
{
|
|
||||||
$this->rules = $rules;
|
|
||||||
$this->device = $device;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function execute(): void
|
|
||||||
{
|
|
||||||
// TODO inline logic
|
|
||||||
include_once base_path('includes/common.php');
|
|
||||||
include_once base_path('includes/dbFacile.php');
|
|
||||||
$this->rules->runRules($this->device->device_id);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,85 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* UpdateDeviceGroupsAction.php
|
|
||||||
*
|
|
||||||
* Update device group associations by re-checking rules
|
|
||||||
*
|
|
||||||
* 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 http://librenms.org
|
|
||||||
*
|
|
||||||
* @copyright 2021 Tony Murray
|
|
||||||
* @author Tony Murray <murraytony@gmail.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace App\Actions\Device;
|
|
||||||
|
|
||||||
use App\Models\Device;
|
|
||||||
use App\Models\DeviceGroup;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
class UpdateDeviceGroupsAction
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var \App\Models\Device
|
|
||||||
*/
|
|
||||||
private $device;
|
|
||||||
|
|
||||||
public function __construct(Device $device)
|
|
||||||
{
|
|
||||||
$this->device = $device;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array[]
|
|
||||||
*/
|
|
||||||
public function execute(): array
|
|
||||||
{
|
|
||||||
if (! $this->device->exists) {
|
|
||||||
// Device not saved to DB, cowardly refusing
|
|
||||||
return [
|
|
||||||
'attached' => [],
|
|
||||||
'detached' => [],
|
|
||||||
'updated' => [],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$device_group_ids = DeviceGroup::query()
|
|
||||||
->with(['devices' => function ($query) {
|
|
||||||
$query->select('devices.device_id');
|
|
||||||
}])
|
|
||||||
->get()
|
|
||||||
->filter(function (DeviceGroup $device_group) {
|
|
||||||
if ($device_group->type == 'dynamic') {
|
|
||||||
try {
|
|
||||||
return $device_group->getParser()
|
|
||||||
->toQuery()
|
|
||||||
->where('devices.device_id', $this->device->device_id)
|
|
||||||
->exists();
|
|
||||||
} catch (\Illuminate\Database\QueryException $e) {
|
|
||||||
Log::error("Device Group '$device_group->name' generates invalid query: " . $e->getMessage());
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// for static, if this device is include, keep it.
|
|
||||||
return $device_group->devices
|
|
||||||
->where('device_id', $this->device->device_id)
|
|
||||||
->isNotEmpty();
|
|
||||||
})->pluck('id');
|
|
||||||
|
|
||||||
return $this->device->groups()->sync($device_group_ids);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,76 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
|
||||||
|
|
||||||
use App\Console\LnmsCommand;
|
|
||||||
use App\Polling\Measure\MeasurementManager;
|
|
||||||
use Illuminate\Database\QueryException;
|
|
||||||
use LibreNMS\Config;
|
|
||||||
use LibreNMS\Poller;
|
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
|
||||||
|
|
||||||
class DevicePoll extends LnmsCommand
|
|
||||||
{
|
|
||||||
protected $name = 'device:poll';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
$this->addArgument('device spec', InputArgument::REQUIRED);
|
|
||||||
$this->addOption('modules', 'm', InputOption::VALUE_REQUIRED);
|
|
||||||
$this->addOption('no-data', 'x', InputOption::VALUE_NONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handle(MeasurementManager $measurements): int
|
|
||||||
{
|
|
||||||
$this->configureOutputOptions();
|
|
||||||
|
|
||||||
if ($this->option('no-data')) {
|
|
||||||
Config::set('rrd.enable', false);
|
|
||||||
Config::set('influxdb.enable', false);
|
|
||||||
Config::set('prometheus.enable', false);
|
|
||||||
Config::set('graphite.enable', false);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$poller = app(Poller::class, ['device_spec' => $this->argument('device spec'), 'module_override' => explode(',', $this->option('modules'))]);
|
|
||||||
$polled = $poller->poll();
|
|
||||||
|
|
||||||
if ($polled > 0) {
|
|
||||||
if (! $this->output->isQuiet()) {
|
|
||||||
if ($polled > 1) {
|
|
||||||
$this->output->newLine();
|
|
||||||
$this->line(sprintf('Polled %d devices in %0.3fs', $polled, $measurements->getCategory('device')->getSummary('poll')->getDuration()));
|
|
||||||
}
|
|
||||||
$this->output->newLine();
|
|
||||||
$measurements->printStats();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} catch (QueryException $e) {
|
|
||||||
if ($e->getCode() == 2002) {
|
|
||||||
$this->error(trans('commands.device:poll.errors.db_connect'));
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
} elseif ($e->getCode() == 1045) {
|
|
||||||
// auth failed, don't need to include the query
|
|
||||||
$this->error(trans('commands.device:poll.errors.db_auth', ['error' => $e->getPrevious()->getMessage()]));
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->error($e->getMessage());
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1; // failed to poll
|
|
||||||
}
|
|
||||||
}
|
|
@@ -27,7 +27,6 @@ namespace App\Console;
|
|||||||
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
use LibreNMS\Util\Debug;
|
|
||||||
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
use Validator;
|
use Validator;
|
||||||
|
|
||||||
@@ -46,7 +45,7 @@ abstract class LnmsCommand extends Command
|
|||||||
$this->setDescription(__('commands.' . $this->getName() . '.description'));
|
$this->setDescription(__('commands.' . $this->getName() . '.description'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isHidden(): bool
|
public function isHidden()
|
||||||
{
|
{
|
||||||
$env = $this->getLaravel() ? $this->getLaravel()->environment() : getenv('APP_ENV');
|
$env = $this->getLaravel() ? $this->getLaravel()->environment() : getenv('APP_ENV');
|
||||||
|
|
||||||
@@ -126,15 +125,4 @@ abstract class LnmsCommand extends Command
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function configureOutputOptions(): void
|
|
||||||
{
|
|
||||||
\Log::setDefaultDriver($this->getOutput()->isQuiet() ? 'stack' : 'console');
|
|
||||||
if (($verbosity = $this->getOutput()->getVerbosity()) >= 128) {
|
|
||||||
Debug::set();
|
|
||||||
if ($verbosity >= 256) {
|
|
||||||
Debug::setVerbose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -1,39 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Events;
|
|
||||||
|
|
||||||
use App\Models\Device;
|
|
||||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
|
||||||
use Illuminate\Broadcasting\PrivateChannel;
|
|
||||||
use Illuminate\Foundation\Events\Dispatchable;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
class DevicePolled
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \App\Models\Device
|
|
||||||
*/
|
|
||||||
public $device;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new event instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(Device $device)
|
|
||||||
{
|
|
||||||
$this->device = $device;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the channels the event should broadcast on.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Broadcasting\Channel|array
|
|
||||||
*/
|
|
||||||
public function broadcastOn()
|
|
||||||
{
|
|
||||||
return new PrivateChannel('channel-name');
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,39 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Events;
|
|
||||||
|
|
||||||
use App\Models\Device;
|
|
||||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
|
||||||
use Illuminate\Broadcasting\PrivateChannel;
|
|
||||||
use Illuminate\Foundation\Events\Dispatchable;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
class PollingDevice
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \App\Models\Device
|
|
||||||
*/
|
|
||||||
public $device;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new event instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(Device $device)
|
|
||||||
{
|
|
||||||
$this->device = $device;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the channels the event should broadcast on.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Broadcasting\Channel|array
|
|
||||||
*/
|
|
||||||
public function broadcastOn()
|
|
||||||
{
|
|
||||||
return new PrivateChannel('channel-name');
|
|
||||||
}
|
|
||||||
}
|
|
@@ -76,7 +76,7 @@ class AboutController extends Controller
|
|||||||
'version_mysql' => Eloquent::version(),
|
'version_mysql' => Eloquent::version(),
|
||||||
'version_php' => phpversion(),
|
'version_php' => phpversion(),
|
||||||
'version_laravel' => App::VERSION(),
|
'version_laravel' => App::VERSION(),
|
||||||
'version_python' => $version->python(),
|
'version_python' => Version::python(),
|
||||||
'version_webserver' => $request->server('SERVER_SOFTWARE'),
|
'version_webserver' => $request->server('SERVER_SOFTWARE'),
|
||||||
'version_rrdtool' => Rrd::version(),
|
'version_rrdtool' => Rrd::version(),
|
||||||
'version_netsnmp' => str_replace('version: ', '', rtrim(shell_exec(Config::get('snmpget', 'snmpget') . ' -V 2>&1'))),
|
'version_netsnmp' => str_replace('version: ', '', rtrim(shell_exec(Config::get('snmpget', 'snmpget') . ' -V 2>&1'))),
|
||||||
|
@@ -1,37 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Listeners;
|
|
||||||
|
|
||||||
use App\Action;
|
|
||||||
use App\Actions\Alerts\RunAlertRulesAction;
|
|
||||||
use App\Events\DevicePolled;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
class CheckAlerts
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Create the event listener.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle the event.
|
|
||||||
*
|
|
||||||
* @param DevicePolled $event
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle(DevicePolled $event)
|
|
||||||
{
|
|
||||||
Log::info('#### Start Alerts ####');
|
|
||||||
$start = microtime(true);
|
|
||||||
|
|
||||||
Action::execute(RunAlertRulesAction::class, $event->device);
|
|
||||||
|
|
||||||
$end = round(microtime(true) - $start, 4);
|
|
||||||
Log::info("#### End Alerts ({$end}s) ####\n");
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,43 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Listeners;
|
|
||||||
|
|
||||||
use App\Action;
|
|
||||||
use App\Actions\Device\UpdateDeviceGroupsAction;
|
|
||||||
use App\Events\DevicePolled;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
class UpdateDeviceGroups
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Create the event listener.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle the event.
|
|
||||||
*
|
|
||||||
* @param DevicePolled $event
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle(DevicePolled $event)
|
|
||||||
{
|
|
||||||
Log::info('### Start Device Groups ###');
|
|
||||||
$dg_start = microtime(true);
|
|
||||||
|
|
||||||
// update device groups
|
|
||||||
$group_changes = Action::execute(UpdateDeviceGroupsAction::class, $event->device);
|
|
||||||
|
|
||||||
$added = implode(',', $group_changes['attached']);
|
|
||||||
$removed = implode(',', $group_changes['detached']);
|
|
||||||
$elapsed = round(microtime(true) - $dg_start, 4);
|
|
||||||
|
|
||||||
Log::debug("Groups Added: $added Removed: $removed");
|
|
||||||
Log::info("### End Device Groups ({$elapsed}s) ### \n");
|
|
||||||
}
|
|
||||||
}
|
|
@@ -27,6 +27,7 @@ namespace App\Models;
|
|||||||
|
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
use LibreNMS\Alerting\QueryBuilderFluentParser;
|
use LibreNMS\Alerting\QueryBuilderFluentParser;
|
||||||
|
use Log;
|
||||||
use Permissions;
|
use Permissions;
|
||||||
|
|
||||||
class DeviceGroup extends BaseModel
|
class DeviceGroup extends BaseModel
|
||||||
@@ -69,6 +70,53 @@ class DeviceGroup extends BaseModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the device groups for the given device or device_id
|
||||||
|
*
|
||||||
|
* @param Device|int $device
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function updateGroupsFor($device)
|
||||||
|
{
|
||||||
|
$device = ($device instanceof Device ? $device : Device::find($device));
|
||||||
|
if (! $device instanceof Device) {
|
||||||
|
// could not load device
|
||||||
|
return [
|
||||||
|
'attached' => [],
|
||||||
|
'detached' => [],
|
||||||
|
'updated' => [],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$device_group_ids = static::query()
|
||||||
|
->with(['devices' => function ($query) {
|
||||||
|
$query->select('devices.device_id');
|
||||||
|
}])
|
||||||
|
->get()
|
||||||
|
->filter(function ($device_group) use ($device) {
|
||||||
|
/** @var DeviceGroup $device_group */
|
||||||
|
if ($device_group->type == 'dynamic') {
|
||||||
|
try {
|
||||||
|
return $device_group->getParser()
|
||||||
|
->toQuery()
|
||||||
|
->where('devices.device_id', $device->device_id)
|
||||||
|
->exists();
|
||||||
|
} catch (\Illuminate\Database\QueryException $e) {
|
||||||
|
Log::error("Device Group '$device_group->name' generates invalid query: " . $e->getMessage());
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// for static, if this device is include, keep it.
|
||||||
|
return $device_group->devices
|
||||||
|
->where('device_id', $device->device_id)
|
||||||
|
->isNotEmpty();
|
||||||
|
})->pluck('id');
|
||||||
|
|
||||||
|
return $device->groups()->sync($device_group_ids);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a query builder parser instance from this device group
|
* Get a query builder parser instance from this device group
|
||||||
*
|
*
|
||||||
|
@@ -39,7 +39,7 @@ class DeviceObserver
|
|||||||
}
|
}
|
||||||
|
|
||||||
// key attribute changes
|
// key attribute changes
|
||||||
foreach (['os', 'sysName', 'version', 'hardware', 'features', 'serial', 'icon', 'type', 'ip'] as $attribute) {
|
foreach (['os', 'sysName', 'version', 'hardware', 'features', 'serial', 'icon', 'type'] as $attribute) {
|
||||||
if ($device->isDirty($attribute)) {
|
if ($device->isDirty($attribute)) {
|
||||||
Log::event(self::attributeChangedMessage($attribute, $device->$attribute, $device->getOriginal($attribute)), $device, 'system', 3);
|
Log::event(self::attributeChangedMessage($attribute, $device->$attribute, $device->getOriginal($attribute)), $device, 'system', 3);
|
||||||
}
|
}
|
||||||
|
@@ -27,8 +27,6 @@ namespace App\Polling\Measure;
|
|||||||
|
|
||||||
use DB;
|
use DB;
|
||||||
use Illuminate\Database\Events\QueryExecuted;
|
use Illuminate\Database\Events\QueryExecuted;
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
class MeasurementManager
|
class MeasurementManager
|
||||||
{
|
{
|
||||||
@@ -38,16 +36,20 @@ class MeasurementManager
|
|||||||
const NO_COLOR = "\e[0m";
|
const NO_COLOR = "\e[0m";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Illuminate\Support\Collection<MeasurementCollection>
|
* @var MeasurementCollection
|
||||||
*/
|
*/
|
||||||
private static $categories;
|
private static $snmp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var MeasurementCollection
|
||||||
|
*/
|
||||||
|
private static $db;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
if (self::$categories === null) {
|
if (self::$snmp === null) {
|
||||||
self::$categories = new Collection;
|
self::$snmp = new MeasurementCollection();
|
||||||
self::$categories->put('snmp', new MeasurementCollection());
|
self::$db = new MeasurementCollection();
|
||||||
self::$categories->put('db', new MeasurementCollection());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,20 +64,12 @@ class MeasurementManager
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Update statistics for the given category
|
|
||||||
*/
|
|
||||||
public function record(string $category, Measurement $measurement): void
|
|
||||||
{
|
|
||||||
$this->getCategory($category)->record($measurement);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update statistics for db operations
|
* Update statistics for db operations
|
||||||
*/
|
*/
|
||||||
public function recordDb(Measurement $measurement): void
|
public function recordDb(Measurement $measurement): void
|
||||||
{
|
{
|
||||||
$this->record('db', $measurement);
|
self::$db->record($measurement);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,24 +77,25 @@ class MeasurementManager
|
|||||||
*/
|
*/
|
||||||
public function printChangedStats(): void
|
public function printChangedStats(): void
|
||||||
{
|
{
|
||||||
$dsStats = app('Datastore')->getStats()->map(function (MeasurementCollection $stats, $datastore) {
|
printf(
|
||||||
return sprintf('%s%s%s: [%d/%.2fs]', self::DATASTORE_COLOR, $datastore, self::NO_COLOR, $stats->getCountDiff(), $stats->getDurationDiff());
|
'>> %sSNMP%s: [%d/%.2fs] %sMySQL%s: [%d/%.2fs]',
|
||||||
});
|
|
||||||
|
|
||||||
Log::info(sprintf(
|
|
||||||
'>> %sSNMP%s: [%d/%.2fs] %sMySQL%s: [%d/%.2fs] %s',
|
|
||||||
self::SNMP_COLOR,
|
self::SNMP_COLOR,
|
||||||
self::NO_COLOR,
|
self::NO_COLOR,
|
||||||
$this->getCategory('snmp')->getCountDiff(),
|
self::$snmp->getCountDiff(),
|
||||||
$this->getCategory('snmp')->getDurationDiff(),
|
self::$snmp->getDurationDiff(),
|
||||||
self::DB_COLOR,
|
self::DB_COLOR,
|
||||||
self::NO_COLOR,
|
self::NO_COLOR,
|
||||||
$this->getCategory('db')->getCountDiff(),
|
self::$db->getCountDiff(),
|
||||||
$this->getCategory('db')->getDurationDiff(),
|
self::$db->getDurationDiff()
|
||||||
$dsStats->implode(' ')
|
);
|
||||||
));
|
|
||||||
|
app('Datastore')->getStats()->each(function (MeasurementCollection $stats, $datastore) {
|
||||||
|
printf(' %s%s%s: [%d/%.2fs]', self::DATASTORE_COLOR, $datastore, self::NO_COLOR, $stats->getCountDiff(), $stats->getDurationDiff());
|
||||||
|
});
|
||||||
|
|
||||||
$this->checkpoint();
|
$this->checkpoint();
|
||||||
|
|
||||||
|
echo PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -108,7 +103,8 @@ class MeasurementManager
|
|||||||
*/
|
*/
|
||||||
public function checkpoint(): void
|
public function checkpoint(): void
|
||||||
{
|
{
|
||||||
self::$categories->each->checkpoint();
|
self::$snmp->checkpoint();
|
||||||
|
self::$db->checkpoint();
|
||||||
app('Datastore')->getStats()->each->checkpoint();
|
app('Datastore')->getStats()->each->checkpoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +113,7 @@ class MeasurementManager
|
|||||||
*/
|
*/
|
||||||
public function recordSnmp(Measurement $measurement): void
|
public function recordSnmp(Measurement $measurement): void
|
||||||
{
|
{
|
||||||
$this->record('snmp', $measurement);
|
self::$snmp->record($measurement);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -125,36 +121,22 @@ class MeasurementManager
|
|||||||
*/
|
*/
|
||||||
public function printStats(): void
|
public function printStats(): void
|
||||||
{
|
{
|
||||||
$this->printSummary('SNMP', $this->getCategory('snmp'), self::SNMP_COLOR);
|
$this->printSummary('SNMP', self::$snmp, self::SNMP_COLOR);
|
||||||
$this->printSummary('SQL', $this->getCategory('db'), self::DB_COLOR);
|
$this->printSummary('SQL', self::$db, self::DB_COLOR);
|
||||||
|
|
||||||
app('Datastore')->getStats()->each(function (MeasurementCollection $stats, string $datastore) {
|
app('Datastore')->getStats()->each(function (MeasurementCollection $stats, string $datastore) {
|
||||||
$this->printSummary($datastore, $stats, self::DATASTORE_COLOR);
|
$this->printSummary($datastore, $stats, self::DATASTORE_COLOR);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCategory(string $category): MeasurementCollection
|
private function printSummary(string $name, MeasurementCollection $collection, string $color = ''): void
|
||||||
{
|
{
|
||||||
if (! self::$categories->has($category)) {
|
printf('%s%s%s [%d/%.2fs]:', $color, $name, $color ? self::NO_COLOR : '', $collection->getTotalCount(), $collection->getTotalDuration());
|
||||||
self::$categories->put($category, new MeasurementCollection());
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::$categories->get($category);
|
$collection->each(function (MeasurementSummary $stat) {
|
||||||
}
|
printf(' %s[%d/%.2fs]', ucfirst($stat->getType()), $stat->getCount(), $stat->getDuration());
|
||||||
|
|
||||||
public function printSummary(string $name, MeasurementCollection $collection, string $color = ''): void
|
|
||||||
{
|
|
||||||
$summaries = $collection->map(function (MeasurementSummary $stat) {
|
|
||||||
return sprintf('%s[%d/%.2fs]', ucfirst($stat->getType()), $stat->getCount(), $stat->getDuration());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Log::info(sprintf('%s%s%s [%d/%.2fs]: %s',
|
echo PHP_EOL;
|
||||||
$color,
|
|
||||||
$name,
|
|
||||||
$color ? self::NO_COLOR : '',
|
|
||||||
$collection->getTotalCount(),
|
|
||||||
$collection->getTotalDuration(),
|
|
||||||
$summaries->implode(' ')
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -32,13 +32,6 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
$this->app->singleton('device-cache', function ($app) {
|
$this->app->singleton('device-cache', function ($app) {
|
||||||
return new \LibreNMS\Cache\Device();
|
return new \LibreNMS\Cache\Device();
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->app->bind(\App\Models\Device::class, function () {
|
|
||||||
/** @var \LibreNMS\Cache\Device $cache */
|
|
||||||
$cache = $this->app->make('device-cache');
|
|
||||||
|
|
||||||
return $cache->hasPrimary() ? $cache->getPrimary() : new \App\Models\Device;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Listeners\MarkNotificationsRead;
|
||||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||||
|
|
||||||
class EventServiceProvider extends ServiceProvider
|
class EventServiceProvider extends ServiceProvider
|
||||||
@@ -14,15 +15,7 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
protected $listen = [
|
protected $listen = [
|
||||||
\Illuminate\Auth\Events\Login::class => ['App\Listeners\AuthEventListener@login'],
|
\Illuminate\Auth\Events\Login::class => ['App\Listeners\AuthEventListener@login'],
|
||||||
\Illuminate\Auth\Events\Logout::class => ['App\Listeners\AuthEventListener@logout'],
|
\Illuminate\Auth\Events\Logout::class => ['App\Listeners\AuthEventListener@logout'],
|
||||||
\App\Events\UserCreated::class => [
|
\App\Events\UserCreated::class => [MarkNotificationsRead::class],
|
||||||
\App\Listeners\MarkNotificationsRead::class,
|
|
||||||
],
|
|
||||||
\App\Events\PollingDevice::class => [
|
|
||||||
],
|
|
||||||
\App\Events\DevicePolled::class => [
|
|
||||||
\App\Listeners\CheckAlerts::class,
|
|
||||||
\App\Listeners\UpdateDeviceGroups::class,
|
|
||||||
],
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -55,12 +55,6 @@ return [
|
|||||||
'ignore_exceptions' => false,
|
'ignore_exceptions' => false,
|
||||||
],
|
],
|
||||||
|
|
||||||
'console_debug' => [
|
|
||||||
'driver' => 'stack',
|
|
||||||
'channels' => ['single', 'stdout_debug'],
|
|
||||||
'ignore_exceptions' => false,
|
|
||||||
],
|
|
||||||
|
|
||||||
'single' => [
|
'single' => [
|
||||||
'driver' => 'single',
|
'driver' => 'single',
|
||||||
'path' => env('APP_LOG', \LibreNMS\Config::get('log_file', base_path('logs/librenms.log'))),
|
'path' => env('APP_LOG', \LibreNMS\Config::get('log_file', base_path('logs/librenms.log'))),
|
||||||
@@ -102,16 +96,6 @@ return [
|
|||||||
'level' => 'debug',
|
'level' => 'debug',
|
||||||
],
|
],
|
||||||
|
|
||||||
'stdout_debug' => [
|
|
||||||
'driver' => 'monolog',
|
|
||||||
'handler' => StreamHandler::class,
|
|
||||||
'formatter' => \LibreNMS\Util\CliColorFormatter::class,
|
|
||||||
'with' => [
|
|
||||||
'stream' => 'php://output',
|
|
||||||
],
|
|
||||||
'level' => 'debug',
|
|
||||||
],
|
|
||||||
|
|
||||||
'stdout' => [
|
'stdout' => [
|
||||||
'driver' => 'monolog',
|
'driver' => 'monolog',
|
||||||
'handler' => StreamHandler::class,
|
'handler' => StreamHandler::class,
|
||||||
@@ -119,7 +103,7 @@ return [
|
|||||||
'with' => [
|
'with' => [
|
||||||
'stream' => 'php://output',
|
'stream' => 'php://output',
|
||||||
],
|
],
|
||||||
'level' => 'info',
|
'level' => 'debug',
|
||||||
],
|
],
|
||||||
|
|
||||||
'syslog' => [
|
'syslog' => [
|
||||||
|
@@ -15,7 +15,6 @@ $init_modules = ['discovery'];
|
|||||||
require __DIR__ . '/includes/init.php';
|
require __DIR__ . '/includes/init.php';
|
||||||
|
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
Log::setDefaultDriver('console');
|
|
||||||
$sqlparams = [];
|
$sqlparams = [];
|
||||||
$options = getopt('h:m:i:n:d::v::a::q', ['os:', 'type:']);
|
$options = getopt('h:m:i:n:d::v::a::q', ['os:', 'type:']);
|
||||||
|
|
||||||
|
@@ -623,10 +623,14 @@ function version_info($remote = false)
|
|||||||
}
|
}
|
||||||
$output['db_schema'] = vsprintf('%s (%s)', $version->database());
|
$output['db_schema'] = vsprintf('%s (%s)', $version->database());
|
||||||
$output['php_ver'] = phpversion();
|
$output['php_ver'] = phpversion();
|
||||||
$output['python_ver'] = $version->python();
|
$output['python_ver'] = \LibreNMS\Util\Version::python();
|
||||||
$output['mysql_ver'] = \LibreNMS\DB\Eloquent::isConnected() ? \LibreNMS\DB\Eloquent::version() : '?';
|
$output['mysql_ver'] = \LibreNMS\DB\Eloquent::isConnected() ? \LibreNMS\DB\Eloquent::version() : '?';
|
||||||
$output['rrdtool_ver'] = $version->rrdtool();
|
$output['rrdtool_ver'] = str_replace('1.7.01.7.0', '1.7.0', implode(' ', array_slice(explode(' ', shell_exec(
|
||||||
$output['netsnmp_ver'] = $version->netSnmp();
|
Config::get('rrdtool', 'rrdtool') . ' --version |head -n1'
|
||||||
|
)), 1, 1)));
|
||||||
|
$output['netsnmp_ver'] = str_replace('version: ', '', rtrim(shell_exec(
|
||||||
|
Config::get('snmpget', 'snmpget') . ' -V 2>&1'
|
||||||
|
)));
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
}//end version_info()
|
}//end version_info()
|
||||||
|
@@ -1,3 +1,3 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
(new \LibreNMS\Modules\Os())->discover($os);
|
(new \LibreNMS\Modules\OS())->discover($os);
|
||||||
|
@@ -74,7 +74,7 @@ function parse_modules($type, $options)
|
|||||||
{
|
{
|
||||||
$override = false;
|
$override = false;
|
||||||
|
|
||||||
if (! empty($options['m'])) {
|
if ($options['m']) {
|
||||||
Config::set("{$type}_modules", []);
|
Config::set("{$type}_modules", []);
|
||||||
foreach (explode(',', $options['m']) as $module) {
|
foreach (explode(',', $options['m']) as $module) {
|
||||||
// parse submodules (only supported by some modules)
|
// parse submodules (only supported by some modules)
|
||||||
|
@@ -5,4 +5,4 @@ use LibreNMS\OS;
|
|||||||
if (! $os instanceof OS) {
|
if (! $os instanceof OS) {
|
||||||
$os = OS::make($device);
|
$os = OS::make($device);
|
||||||
}
|
}
|
||||||
(new \LibreNMS\Modules\Os())->poll($os);
|
(new \LibreNMS\Modules\OS())->poll($os);
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
* the source code distribution for details.
|
* the source code distribution for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use App\Models\Device;
|
||||||
use App\Polling\Measure\Measurement;
|
use App\Polling\Measure\Measurement;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use LibreNMS\Config;
|
use LibreNMS\Config;
|
||||||
@@ -176,7 +177,7 @@ function gen_snmp_cmd($cmd, $device, $oids, $options = null, $mib = null, $mibdi
|
|||||||
array_push($cmd, '-r', $retries);
|
array_push($cmd, '-r', $retries);
|
||||||
}
|
}
|
||||||
|
|
||||||
$pollertarget = \LibreNMS\Util\Rewrite::addIpv6Brackets((string) ($device['overwrite_ip'] ?? $device['hostname']));
|
$pollertarget = \LibreNMS\Util\Rewrite::addIpv6Brackets(Device::pollerTarget($device));
|
||||||
$cmd[] = $device['transport'] . ':' . $pollertarget . ':' . $device['port'];
|
$cmd[] = $device['transport'] . ':' . $pollertarget . ':' . $device['port'];
|
||||||
$cmd = array_merge($cmd, (array) $oids);
|
$cmd = array_merge($cmd, (array) $oids);
|
||||||
|
|
||||||
|
@@ -3665,30 +3665,60 @@ parameters:
|
|||||||
count: 1
|
count: 1
|
||||||
path: LibreNMS/Modules/Nac.php
|
path: LibreNMS/Modules/Nac.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Method LibreNMS\\\\Modules\\\\OS\\:\\:cleanup\\(\\) has no return type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/Modules/OS.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Method LibreNMS\\\\Modules\\\\OS\\:\\:discover\\(\\) has no return type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/Modules/OS.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Method LibreNMS\\\\Modules\\\\OS\\:\\:handleChanges\\(\\) has no return type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/Modules/OS.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Method LibreNMS\\\\Modules\\\\OS\\:\\:poll\\(\\) has no return type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/Modules/OS.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Method LibreNMS\\\\Modules\\\\OS\\:\\:sysContact\\(\\) has no return type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/Modules/OS.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Method LibreNMS\\\\Modules\\\\OS\\:\\:updateLocation\\(\\) has no return type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/Modules/OS.php
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Variable \\$features on left side of \\?\\? is never defined\\.$#"
|
message: "#^Variable \\$features on left side of \\?\\? is never defined\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
path: LibreNMS/Modules/Os.php
|
path: LibreNMS/Modules/OS.php
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Variable \\$hardware on left side of \\?\\? is never defined\\.$#"
|
message: "#^Variable \\$hardware on left side of \\?\\? is never defined\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
path: LibreNMS/Modules/Os.php
|
path: LibreNMS/Modules/OS.php
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Variable \\$location in empty\\(\\) always exists and is always falsy\\.$#"
|
message: "#^Variable \\$location in empty\\(\\) always exists and is always falsy\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
path: LibreNMS/Modules/Os.php
|
path: LibreNMS/Modules/OS.php
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Variable \\$serial on left side of \\?\\? is never defined\\.$#"
|
message: "#^Variable \\$serial on left side of \\?\\? is never defined\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
path: LibreNMS/Modules/Os.php
|
path: LibreNMS/Modules/OS.php
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Variable \\$version on left side of \\?\\? is never defined\\.$#"
|
message: "#^Variable \\$version on left side of \\?\\? is never defined\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
path: LibreNMS/Modules/Os.php
|
path: LibreNMS/Modules/OS.php
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Method LibreNMS\\\\Modules\\\\PrinterSupplies\\:\\:cleanup\\(\\) has no return type specified\\.$#"
|
message: "#^Method LibreNMS\\\\Modules\\\\PrinterSupplies\\:\\:cleanup\\(\\) has no return type specified\\.$#"
|
||||||
@@ -3885,6 +3915,11 @@ parameters:
|
|||||||
count: 1
|
count: 1
|
||||||
path: LibreNMS/OS.php
|
path: LibreNMS/OS.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Method LibreNMS\\\\OS\\:\\:persistGraphs\\(\\) has no return type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/OS.php
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Method LibreNMS\\\\OS\\:\\:preCache\\(\\) has no return type specified\\.$#"
|
message: "#^Method LibreNMS\\\\OS\\:\\:preCache\\(\\) has no return type specified\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
@@ -5405,6 +5440,36 @@ parameters:
|
|||||||
count: 1
|
count: 1
|
||||||
path: LibreNMS/Util/Colors.php
|
path: LibreNMS/Util/Colors.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Method LibreNMS\\\\Util\\\\Debug\\:\\:disableCliDebugOutput\\(\\) has no return type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/Util/Debug.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Method LibreNMS\\\\Util\\\\Debug\\:\\:disableQueryDebug\\(\\) has no return type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/Util/Debug.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Method LibreNMS\\\\Util\\\\Debug\\:\\:enableCliDebugOutput\\(\\) has no return type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/Util/Debug.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Method LibreNMS\\\\Util\\\\Debug\\:\\:enableQueryDebug\\(\\) has no return type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/Util/Debug.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Property LibreNMS\\\\Util\\\\Debug\\:\\:\\$debug has no type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/Util/Debug.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Property LibreNMS\\\\Util\\\\Debug\\:\\:\\$verbose has no type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/Util/Debug.php
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Property LibreNMS\\\\Util\\\\Dns\\:\\:\\$resolver has no type specified\\.$#"
|
message: "#^Property LibreNMS\\\\Util\\\\Dns\\:\\:\\$resolver has no type specified\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
@@ -5700,6 +5765,16 @@ parameters:
|
|||||||
count: 1
|
count: 1
|
||||||
path: LibreNMS/Util/FileCategorizer.php
|
path: LibreNMS/Util/FileCategorizer.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Method LibreNMS\\\\Util\\\\Git\\:\\:binaryExists\\(\\) has no return type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/Util/Git.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Method LibreNMS\\\\Util\\\\Git\\:\\:repoPresent\\(\\) has no return type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/Util/Git.php
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Method LibreNMS\\\\Util\\\\GitHub\\:\\:__construct\\(\\) has parameter \\$file with no type specified\\.$#"
|
message: "#^Method LibreNMS\\\\Util\\\\GitHub\\:\\:__construct\\(\\) has parameter \\$file with no type specified\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
@@ -6770,6 +6845,46 @@ parameters:
|
|||||||
count: 1
|
count: 1
|
||||||
path: LibreNMS/Util/Validate.php
|
path: LibreNMS/Util/Validate.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Method LibreNMS\\\\Util\\\\Version\\:\\:database\\(\\) has no return type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/Util/Version.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Method LibreNMS\\\\Util\\\\Version\\:\\:fromGit\\(\\) has no return type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/Util/Version.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Method LibreNMS\\\\Util\\\\Version\\:\\:get\\(\\) has no return type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/Util/Version.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Method LibreNMS\\\\Util\\\\Version\\:\\:gitChangelog\\(\\) has no return type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/Util/Version.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Method LibreNMS\\\\Util\\\\Version\\:\\:gitDate\\(\\) has no return type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/Util/Version.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Method LibreNMS\\\\Util\\\\Version\\:\\:local\\(\\) has no return type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/Util/Version.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Method LibreNMS\\\\Util\\\\Version\\:\\:python\\(\\) has no return type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/Util/Version.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Property LibreNMS\\\\Util\\\\Version\\:\\:\\$is_git_install has no type specified\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: LibreNMS/Util/Version.php
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Method LibreNMS\\\\ValidationResult\\:\\:consolePrint\\(\\) has no return type specified\\.$#"
|
message: "#^Method LibreNMS\\\\ValidationResult\\:\\:consolePrint\\(\\) has no return type specified\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
|
@@ -24,8 +24,6 @@
|
|||||||
* @author Heath Barnhart <hbarnhart@kanren.net>
|
* @author Heath Barnhart <hbarnhart@kanren.net>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use App\Action;
|
|
||||||
use App\Actions\Device\UpdateDeviceGroupsAction;
|
|
||||||
use LibreNMS\Alert\AlertRules;
|
use LibreNMS\Alert\AlertRules;
|
||||||
use LibreNMS\Config;
|
use LibreNMS\Config;
|
||||||
use LibreNMS\Data\Store\Datastore;
|
use LibreNMS\Data\Store\Datastore;
|
||||||
@@ -35,7 +33,6 @@ $init_modules = ['polling', 'alerts', 'laravel'];
|
|||||||
require __DIR__ . '/includes/init.php';
|
require __DIR__ . '/includes/init.php';
|
||||||
|
|
||||||
$poller_start = microtime(true);
|
$poller_start = microtime(true);
|
||||||
Log::setDefaultDriver('console');
|
|
||||||
echo Config::get('project_name') . " Poller\n";
|
echo Config::get('project_name') . " Poller\n";
|
||||||
|
|
||||||
$options = getopt('h:m:i:n:r::d::v::a::f::q');
|
$options = getopt('h:m:i:n:r::d::v::a::f::q');
|
||||||
@@ -142,7 +139,7 @@ foreach (dbFetch($query) as $device) {
|
|||||||
// Update device_groups
|
// Update device_groups
|
||||||
echo "### Start Device Groups ###\n";
|
echo "### Start Device Groups ###\n";
|
||||||
$dg_start = microtime(true);
|
$dg_start = microtime(true);
|
||||||
$group_changes = Action::execute(UpdateDeviceGroupsAction::class);
|
$group_changes = \App\Models\DeviceGroup::updateGroupsFor($device['device_id']);
|
||||||
d_echo('Groups Added: ' . implode(',', $group_changes['attached']) . PHP_EOL);
|
d_echo('Groups Added: ' . implode(',', $group_changes['attached']) . PHP_EOL);
|
||||||
d_echo('Groups Removed: ' . implode(',', $group_changes['detached']) . PHP_EOL);
|
d_echo('Groups Removed: ' . implode(',', $group_changes['detached']) . PHP_EOL);
|
||||||
echo '### End Device Groups, runtime: ' . round(microtime(true) - $dg_start, 4) . "s ### \n\n";
|
echo '### End Device Groups, runtime: ' . round(microtime(true) - $dg_start, 4) . "s ### \n\n";
|
||||||
|
@@ -69,20 +69,6 @@ return [
|
|||||||
'device spec' => 'Device to ping one of: <Device ID>, <Hostname/IP>, all',
|
'device spec' => 'Device to ping one of: <Device ID>, <Hostname/IP>, all',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'device:poll' => [
|
|
||||||
'description' => 'Poll data from device(s) as defined by discovery',
|
|
||||||
'arguments' => [
|
|
||||||
'device spec' => 'Device spec to poll: device_id, hostname, wildcard, odd, even, all',
|
|
||||||
],
|
|
||||||
'options' => [
|
|
||||||
'modules' => 'Specify single module to be run. Comma separate modules, submodules may be added with /',
|
|
||||||
'no-data' => 'Do not update datastores (RRD, InfluxDB, etc)',
|
|
||||||
],
|
|
||||||
'errors' => [
|
|
||||||
'db_connect' => 'Failed to connect to database. Verify database service is running and connection settings.',
|
|
||||||
'db_auth' => 'Failed to connect to database. Verify credentials: :error',
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'key:rotate' => [
|
'key:rotate' => [
|
||||||
'description' => 'Rotate APP_KEY, this decrypts all encrypted data with the given old key and stores it with the new key in APP_KEY.',
|
'description' => 'Rotate APP_KEY, this decrypts all encrypted data with the given old key and stores it with the new key in APP_KEY.',
|
||||||
'arguments' => [
|
'arguments' => [
|
||||||
|
@@ -111,7 +111,8 @@ Artisan::command('device:add
|
|||||||
if (($verbosity = $this->getOutput()->getVerbosity()) >= 128) {
|
if (($verbosity = $this->getOutput()->getVerbosity()) >= 128) {
|
||||||
Debug::set();
|
Debug::set();
|
||||||
if ($verbosity >= 256) {
|
if ($verbosity >= 256) {
|
||||||
Debug::setVerbose();
|
global $verbose;
|
||||||
|
$verbose = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -100,8 +100,10 @@ class OSModulesTest extends DBTestCase
|
|||||||
$filename = $helper->getJsonFilepath(true);
|
$filename = $helper->getJsonFilepath(true);
|
||||||
$expected_data = $helper->getTestData();
|
$expected_data = $helper->getTestData();
|
||||||
$results = $helper->generateTestData($this->getSnmpsim(), true);
|
$results = $helper->generateTestData($this->getSnmpsim(), true);
|
||||||
} catch (FileNotFoundException|InvalidModuleException $e) {
|
} catch (FileNotFoundException $e) {
|
||||||
$this->fail($e->getMessage());
|
return $this->fail($e->getMessage());
|
||||||
|
} catch (InvalidModuleException $e) {
|
||||||
|
return $this->fail($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($results)) {
|
if (is_null($results)) {
|
||||||
@@ -166,10 +168,8 @@ class OSModulesTest extends DBTestCase
|
|||||||
private function stubClasses(): void
|
private function stubClasses(): void
|
||||||
{
|
{
|
||||||
$this->app->bind('log', function ($app) {
|
$this->app->bind('log', function ($app) {
|
||||||
$mock = \Mockery::mock('\App\Facades\LogManager[event]', [$app]);
|
return \Mockery::mock('\App\Facades\LogManager[event]', [$app])
|
||||||
$mock->shouldReceive('event');
|
->shouldReceive('event');
|
||||||
|
|
||||||
return $mock;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->app->bind(Fping::class, function ($app) {
|
$this->app->bind(Fping::class, function ($app) {
|
||||||
|
Reference in New Issue
Block a user