diff --git a/LibreNMS/Alert/Transport/Canopsis.php b/LibreNMS/Alert/Transport/Canopsis.php index e3e7895460..9bee95d182 100644 --- a/LibreNMS/Alert/Transport/Canopsis.php +++ b/LibreNMS/Alert/Transport/Canopsis.php @@ -69,12 +69,9 @@ class Canopsis extends Transport $msg_raw = json_encode($msg_body); // Build routing key - $msg_rk = ''; - if ($msg_body['source_type'] == 'resource') { - $msg_rk = $msg_rk . '.' . $msg_body['resource']; - } else { - $msg_rk = $msg_body['connector'] . '.' . $msg_body['connector_name'] . '.' . $msg_body['event_type'] . '.' . $msg_body['source_type'] . '.' . $msg_body['component']; - } + $msg_rk = '.' . $msg_body['resource']; + // non-resource key example + // $msg_rk = $msg_body['connector'] . '.' . $msg_body['connector_name'] . '.' . $msg_body['event_type'] . '.' . $msg_body['source_type'] . '.' . $msg_body['component']; // Publish Event $msg = new AMQPMessage($msg_raw, ['content_type' => 'application/json', 'delivery_mode' => 2]); diff --git a/LibreNMS/Alert/Transport/Googlechat.php b/LibreNMS/Alert/Transport/Googlechat.php index 50648d4b77..6863dabd86 100755 --- a/LibreNMS/Alert/Transport/Googlechat.php +++ b/LibreNMS/Alert/Transport/Googlechat.php @@ -65,7 +65,7 @@ class Googlechat extends Transport $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); - Log::debug($code); + Log::debug("$code"); if ($code != 200) { Log::error('Google Chat Transport Error'); diff --git a/LibreNMS/OS/Ceraos.php b/LibreNMS/OS/Ceraos.php index 59a9fec45f..2caaa21f19 100644 --- a/LibreNMS/OS/Ceraos.php +++ b/LibreNMS/OS/Ceraos.php @@ -50,7 +50,7 @@ class Ceraos extends OS implements OSDiscovery, WirelessXpiDiscovery, WirelessFr $device->version = $data[1]['MWRM-UNIT-MIB::genEquipMngSwIDUVersionsRunningVersion'] ?? null; // update location lat/lng - if ($device->location && (! empty($multi_get_array[0]['MWRM-UNIT-MIB::genEquipUnitLatitude']) || ! empty($multi_get_array[0]['MWRM-UNIT-MIB::genEquipUnitLongitude']))) { + if ($device->location) { $device->location->lat = $multi_get_array[0]['MWRM-UNIT-MIB::genEquipUnitLatitude'] ?? $device->location->lat; $device->location->lng = $multi_get_array[0]['MWRM-UNIT-MIB::genEquipUnitLongitude'] ?? $device->location->lng; $device->location->save(); diff --git a/LibreNMS/Snmptrap/Handlers/UpsTrapOnBattery.php b/LibreNMS/Snmptrap/Handlers/UpsTrapOnBattery.php index a88ed152a5..e42b885f37 100644 --- a/LibreNMS/Snmptrap/Handlers/UpsTrapOnBattery.php +++ b/LibreNMS/Snmptrap/Handlers/UpsTrapOnBattery.php @@ -42,8 +42,8 @@ class UpsTrapOnBattery implements SnmptrapHandler */ public function handle(Device $device, Trap $trap) { - $min_remaining = Str::before($trap->getOidData($trap->findOid('UPS-MIB::upsEstimatedMinutesRemaining')), ' '); - $sec_time = Str::before($trap->getOidData($trap->findOid('UPS-MIB::upsSecondsOnBattery')), ' '); + $min_remaining = (int) Str::before($trap->getOidData($trap->findOid('UPS-MIB::upsEstimatedMinutesRemaining')), ' '); + $sec_time = (int) Str::before($trap->getOidData($trap->findOid('UPS-MIB::upsSecondsOnBattery')), ' '); Log::event("UPS running on battery for $sec_time seconds. Estimated $min_remaining minutes remaining", $device->device_id, 'trap', 5); $sensor_remaining = $device->sensors()->where('sensor_index', '200')->where('sensor_type', 'rfc1628')->first(); if (! $sensor_remaining) { diff --git a/LibreNMS/Snmptrap/Handlers/UpsTrapsOnBattery.php b/LibreNMS/Snmptrap/Handlers/UpsTrapsOnBattery.php deleted file mode 100644 index eb055e64a8..0000000000 --- a/LibreNMS/Snmptrap/Handlers/UpsTrapsOnBattery.php +++ /dev/null @@ -1,75 +0,0 @@ -. - * - * @link https://www.librenms.org - * - * @author TheGreatDoc - */ - -namespace LibreNMS\Snmptrap\Handlers; - -use App\Models\Device; -use Illuminate\Support\Str; -use LibreNMS\Interfaces\SnmptrapHandler; -use LibreNMS\Snmptrap\Trap; -use Log; - -class UpsTrapsOnBattery implements SnmptrapHandler -{ - /** - * Handle snmptrap. - * Data is pre-parsed and delivered as a Trap. - * - * @param Device $device - * @param Trap $trap - * @return void - */ - public function handle(Device $device, Trap $trap) - { - $min_remaining = Str::before($trap->getOidData($trap->findOid('UPS-MIB::upsEstimatedMinutesRemaining.0')), ' '); - $sec_time = Str::before($trap->getOidData($trap->findOid('UPS-MIB::upsSecondsOnBattery.0')), ' '); - Log::event("UPS running on battery for $sec_time seconds. Estimated $min_remaining minutes remaining", $device->device_id, 'trap', 5); - $sensor_remaining = $device->sensors()->where('sensor_index', '200')->where('sensor_type', 'rfc1628')->first(); - if (! $sensor_remaining) { - Log::warning("Snmptrap UpsTraps: Could not find matching sensor \'Estimated battery time remaining\' for device: " . $device->hostname); - - return; - } - $sensor_remaining->sensor_current = $min_remaining / $sensor_remaining->sensor_divisor; - $sensor_remaining->save(); - - $sensor_time = $device->sensors()->where('sensor_index', '100')->where('sensor_type', 'rfc1628')->first(); - if (! $sensor_time) { - Log::warning("Snmptrap UpsTraps: Could not find matching sensor \'Time on battery\' for device: " . $device->hostname); - - return; - } - $sensor_time->sensor_current = $sec_time / $sensor_time->sensor_divisor; - $sensor_time->save(); - - $sensor_output = $device->sensors()->where('sensor_type', 'upsOutputSourceState')->first(); - if (! $sensor_output) { - Log::warning("Snmptrap UpsTraps: Could not find matching sensor \'upsOutputSourceState\' for device: " . $device->hostname); - - return; - } - $sensor_output->sensor_current = 5; - $sensor_output->save(); - } -} diff --git a/app/Facades/LogManager.php b/app/Facades/LogManager.php index c4d48629e3..ca1b04774a 100644 --- a/app/Facades/LogManager.php +++ b/app/Facades/LogManager.php @@ -37,7 +37,7 @@ class LogManager extends \Illuminate\Log\LogManager * @param \App\Models\Device|int $device device array or device_id * @param string $type brief category for this event. Examples: sensor, state, stp, system, temperature, interface * @param int $severity 1: ok, 2: info, 3: notice, 4: warning, 5: critical, 0: unknown - * @param int $reference the id of the referenced entity. Supported types: interface + * @param int|string|null $reference the id of the referenced entity. Supported types: interface, bgpPeer */ public function event($text, $device = null, $type = null, $severity = Alert::INFO, $reference = null) { diff --git a/composer.json b/composer.json index 551a5e1397..247b0a4eb0 100644 --- a/composer.json +++ b/composer.json @@ -63,8 +63,7 @@ "laravel/dusk": "^6.15", "mockery/mockery": "^1.4.2", "nunomaduro/collision": "^5.0", - "nunomaduro/larastan": "1.0.2", - "phpstan/phpstan": "1.4.2", + "nunomaduro/larastan": "^1.0", "php-parallel-lint/php-parallel-lint": "^1.1", "phpstan/phpstan-deprecation-rules": "^1.0", "phpstan/phpstan-mockery": "^1.0", diff --git a/composer.lock b/composer.lock index 144215c315..1172f3abf5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "aaf35a5b25ee679d27efef41a397db86", + "content-hash": "6ae226d7d02a5cc5c60bb124d43a4f6c", "packages": [ { "name": "amenadiel/jpgraph", @@ -9855,16 +9855,16 @@ }, { "name": "nunomaduro/larastan", - "version": "1.0.2", + "version": "1.0.3", "source": { "type": "git", "url": "https://github.com/nunomaduro/larastan.git", - "reference": "3e0beabe8cf98373700f4d30cdfb2aa6badb9144" + "reference": "f5ce15319da184a5e461ef12c60489c15a9cf65b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nunomaduro/larastan/zipball/3e0beabe8cf98373700f4d30cdfb2aa6badb9144", - "reference": "3e0beabe8cf98373700f4d30cdfb2aa6badb9144", + "url": "https://api.github.com/repos/nunomaduro/larastan/zipball/f5ce15319da184a5e461ef12c60489c15a9cf65b", + "reference": "f5ce15319da184a5e461ef12c60489c15a9cf65b", "shasum": "" }, "require": { @@ -9929,7 +9929,7 @@ ], "support": { "issues": "https://github.com/nunomaduro/larastan/issues", - "source": "https://github.com/nunomaduro/larastan/tree/1.0.2" + "source": "https://github.com/nunomaduro/larastan/tree/1.0.3" }, "funding": [ { @@ -9949,7 +9949,7 @@ "type": "patreon" } ], - "time": "2021-11-23T10:50:03+00:00" + "time": "2022-01-20T19:33:48+00:00" }, { "name": "phar-io/manifest", @@ -10468,20 +10468,20 @@ }, { "name": "phpstan/phpstan", - "version": "1.4.2", + "version": "1.7.12", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "1dd8f3e40bf7aa30031a75c65cece99220a161b8" + "reference": "32f10779d9cd88a9cbd972ec611a4148a3cbbc7e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/1dd8f3e40bf7aa30031a75c65cece99220a161b8", - "reference": "1dd8f3e40bf7aa30031a75c65cece99220a161b8", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/32f10779d9cd88a9cbd972ec611a4148a3cbbc7e", + "reference": "32f10779d9cd88a9cbd972ec611a4148a3cbbc7e", "shasum": "" }, "require": { - "php": "^7.1|^8.0" + "php": "^7.2|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -10491,11 +10491,6 @@ "phpstan.phar" ], "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4-dev" - } - }, "autoload": { "files": [ "bootstrap.php" @@ -10508,7 +10503,7 @@ "description": "PHPStan - PHP Static Analysis Tool", "support": { "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/1.4.2" + "source": "https://github.com/phpstan/phpstan/tree/1.7.12" }, "funding": [ { @@ -10528,7 +10523,7 @@ "type": "tidelift" } ], - "time": "2022-01-18T16:09:11+00:00" + "time": "2022-06-09T12:39:36+00:00" }, { "name": "phpstan/phpstan-deprecation-rules", @@ -10582,21 +10577,21 @@ }, { "name": "phpstan/phpstan-mockery", - "version": "1.0.0", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-mockery.git", - "reference": "1767581e025d830d9288702761ad3cc7b72ecca4" + "reference": "245b17ccd00f04be3c6b9fc6645f63793b37b2ea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-mockery/zipball/1767581e025d830d9288702761ad3cc7b72ecca4", - "reference": "1767581e025d830d9288702761ad3cc7b72ecca4", + "url": "https://api.github.com/repos/phpstan/phpstan-mockery/zipball/245b17ccd00f04be3c6b9fc6645f63793b37b2ea", + "reference": "245b17ccd00f04be3c6b9fc6645f63793b37b2ea", "shasum": "" }, "require": { - "php": "^7.1 || ^8.0", - "phpstan/phpstan": "^1.0" + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.5.0" }, "require-dev": { "mockery/mockery": "^1.2.4", @@ -10608,9 +10603,6 @@ }, "type": "phpstan-extension", "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - }, "phpstan": { "includes": [ "extension.neon" @@ -10629,9 +10621,9 @@ "description": "PHPStan Mockery extension", "support": { "issues": "https://github.com/phpstan/phpstan-mockery/issues", - "source": "https://github.com/phpstan/phpstan-mockery/tree/1.0.0" + "source": "https://github.com/phpstan/phpstan-mockery/tree/1.1.0" }, - "time": "2021-09-20T16:03:58+00:00" + "time": "2022-05-09T13:12:35+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/config/snmptraps.php b/config/snmptraps.php index de99e78091..9625e4f5f0 100755 --- a/config/snmptraps.php +++ b/config/snmptraps.php @@ -127,7 +127,8 @@ return [ 'OSPF-TRAP-MIB::ospfIfStateChange' => \LibreNMS\Snmptrap\Handlers\OspfIfStateChange::class, 'OSPF-TRAP-MIB::ospfNbrStateChange' => \LibreNMS\Snmptrap\Handlers\OspfNbrStateChange::class, 'OSPF-TRAP-MIB::ospfTxRetransmit' => \LibreNMS\Snmptrap\Handlers\OspfTxRetransmit::class, - 'UPS-MIB::upsTraps.0.1' => \LibreNMS\Snmptrap\Handlers\UpsTrapsOnBattery::class, + 'UPS-MIB::upsTrapOnBattery' => \LibreNMS\Snmptrap\Handlers\UpsTrapOnBattery::class, + 'UPS-MIB::upsTraps.0.1' => \LibreNMS\Snmptrap\Handlers\UpsTrapOnBattery::class, // apparently bad/old UPS-MIB 'VEEAM-MIB::onBackupJobCompleted' => \LibreNMS\Snmptrap\Handlers\VeeamBackupJobCompleted::class, 'VEEAM-MIB::onVmBackupCompleted' => \LibreNMS\Snmptrap\Handlers\VeeamVmBackupCompleted::class, 'VEEAM-MIB::onLinuxFLRMountStarted' => \LibreNMS\Snmptrap\Handlers\VeeamLinuxFLRMountStarted::class, @@ -145,6 +146,5 @@ return [ 'VEEAM-MIB::onSobrOffloadFinished' => \LibreNMS\Snmptrap\Handlers\VeeamSobrOffloadFinished::class, 'VEEAM-MIB::onCdpRpoReport' => \LibreNMS\Snmptrap\Handlers\VeeamCdpRpoReport::class, 'HP-ICF-FAULT-FINDER-MIB::hpicfFaultFinderTrap' => \LibreNMS\Snmptrap\Handlers\HpFault::class, - 'UPS-MIB::upsTrapOnBattery' => \LibreNMS\Snmptrap\Handlers\UpsTrapOnBattery::class, ], ]; diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 691b19f778..6620bfc1a8 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -2545,11 +2545,6 @@ parameters: count: 1 path: LibreNMS/Exceptions/AuthenticationException.php - - - message: "#^Parameter \\#2 \\$code of class LibreNMS\\\\Exceptions\\\\DatabaseConnectException constructor expects int, string given\\.$#" - count: 1 - path: LibreNMS/Exceptions/DatabaseConnectException.php - - message: "#^Method LibreNMS\\\\Exceptions\\\\DatabaseInconsistentException\\:\\:__construct\\(\\) has parameter \\$code with no type specified\\.$#" count: 1 @@ -3930,11 +3925,6 @@ parameters: count: 1 path: LibreNMS/OS/Ceraos.php - - - message: "#^Variable \\$multi_get_array in empty\\(\\) is never defined\\.$#" - count: 2 - path: LibreNMS/OS/Ceraos.php - - message: "#^Variable \\$multi_get_array on left side of \\?\\? is never defined\\.$#" count: 2 @@ -4990,16 +4980,6 @@ parameters: count: 1 path: LibreNMS/Snmptrap/Handlers/AdvaNetThresholdCrossingAlert.php - - - message: "#^Parameter \\#5 \\$reference of static method App\\\\Facades\\\\LogManager\\:\\:event\\(\\) expects int\\|null, string given\\.$#" - count: 1 - path: LibreNMS/Snmptrap/Handlers/BgpBackwardTransition.php - - - - message: "#^Parameter \\#5 \\$reference of static method App\\\\Facades\\\\LogManager\\:\\:event\\(\\) expects int\\|null, string given\\.$#" - count: 1 - path: LibreNMS/Snmptrap/Handlers/BgpEstablished.php - - message: "#^Method LibreNMS\\\\Snmptrap\\\\Handlers\\\\EquipStatusTrap\\:\\:getSeverity\\(\\) has no return type specified\\.$#" count: 1 @@ -5370,36 +5350,6 @@ parameters: count: 1 path: LibreNMS/Util/DynamicConfigItem.php - - - message: "#^Method LibreNMS\\\\Util\\\\DynamicConfigItem\\:\\:offsetExists\\(\\) has parameter \\$offset with no type specified\\.$#" - count: 1 - path: LibreNMS/Util/DynamicConfigItem.php - - - - message: "#^Method LibreNMS\\\\Util\\\\DynamicConfigItem\\:\\:offsetGet\\(\\) has no return type specified\\.$#" - count: 1 - path: LibreNMS/Util/DynamicConfigItem.php - - - - message: "#^Method LibreNMS\\\\Util\\\\DynamicConfigItem\\:\\:offsetGet\\(\\) has parameter \\$offset with no type specified\\.$#" - count: 1 - path: LibreNMS/Util/DynamicConfigItem.php - - - - message: "#^Method LibreNMS\\\\Util\\\\DynamicConfigItem\\:\\:offsetSet\\(\\) has parameter \\$offset with no type specified\\.$#" - count: 1 - path: LibreNMS/Util/DynamicConfigItem.php - - - - message: "#^Method LibreNMS\\\\Util\\\\DynamicConfigItem\\:\\:offsetSet\\(\\) has parameter \\$value with no type specified\\.$#" - count: 1 - path: LibreNMS/Util/DynamicConfigItem.php - - - - message: "#^Method LibreNMS\\\\Util\\\\DynamicConfigItem\\:\\:offsetUnset\\(\\) has parameter \\$offset with no type specified\\.$#" - count: 1 - path: LibreNMS/Util/DynamicConfigItem.php - - message: "#^Method LibreNMS\\\\Util\\\\DynamicConfigItem\\:\\:only\\(\\) has no return type specified\\.$#" count: 1 @@ -6340,6 +6290,16 @@ parameters: count: 1 path: LibreNMS/Util/Snmpsim.php + - + message: "#^Unreachable statement \\- code above always terminates\\.$#" + count: 1 + path: LibreNMS/Util/Snmpsim.php + + - + message: "#^Anonymous function should return non\\-empty\\-string but returns string\\.$#" + count: 1 + path: LibreNMS/Util/StringHelpers.php + - message: "#^Method LibreNMS\\\\Util\\\\StringHelpers\\:\\:niceCase\\(\\) has no return type specified\\.$#" count: 1 @@ -8120,21 +8080,46 @@ parameters: count: 1 path: app/Jobs/PingCheck.php + - + message: "#^Property App\\\\Jobs\\\\PingCheck\\:\\:\\$deferred is never written, only read\\.$#" + count: 1 + path: app/Jobs/PingCheck.php + - message: "#^Property App\\\\Jobs\\\\PingCheck\\:\\:\\$devices \\(Illuminate\\\\Database\\\\Eloquent\\\\Collection\\) in isset\\(\\) is not nullable\\.$#" count: 1 path: app/Jobs/PingCheck.php + - + message: "#^Property App\\\\Jobs\\\\PingCheck\\:\\:\\$devices is never written, only read\\.$#" + count: 1 + path: app/Jobs/PingCheck.php + + - + message: "#^Property App\\\\Jobs\\\\PingCheck\\:\\:\\$groups is never read, only written\\.$#" + count: 1 + path: app/Jobs/PingCheck.php + - message: "#^Property App\\\\Jobs\\\\PingCheck\\:\\:\\$rrd_tags has no type specified\\.$#" count: 1 path: app/Jobs/PingCheck.php + - + message: "#^Property App\\\\Jobs\\\\PingCheck\\:\\:\\$tiered is never written, only read\\.$#" + count: 1 + path: app/Jobs/PingCheck.php + - message: "#^Property App\\\\Jobs\\\\PingCheck\\:\\:\\$wait has no type specified\\.$#" count: 1 path: app/Jobs/PingCheck.php + - + message: "#^Unreachable statement \\- code above always terminates\\.$#" + count: 1 + path: app/Jobs/PingCheck.php + - message: "#^Ternary operator condition is always true\\.$#" count: 2 @@ -9360,6 +9345,16 @@ parameters: count: 1 path: app/Providers/AppServiceProvider.php + - + message: "#^Result of && is always false\\.$#" + count: 1 + path: app/Providers/CliServiceProvider.php + + - + message: "#^Right side of && is always false\\.$#" + count: 1 + path: app/Providers/CliServiceProvider.php + - message: "#^Method App\\\\Providers\\\\DatastoreServiceProvider\\:\\:registerInflux\\(\\) has no return type specified\\.$#" count: 1