Skip to content

Commit

Permalink
Merge branch 'master' into junostra
Browse files Browse the repository at this point in the history
  • Loading branch information
PipoCanaja authored Jan 3, 2025
2 parents 80f8e8e + 738496e commit 22fc8a0
Show file tree
Hide file tree
Showing 57 changed files with 28,992 additions and 10,913 deletions.
59 changes: 59 additions & 0 deletions LibreNMS/Snmptrap/Handlers/AxisAlarmCleared.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* AxisAlarmCleared.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 2024 Transitiv Technologies Ltd. <info@transitiv.co.uk>
* @author Adam Sweet <adam.sweet@transitiv.co.uk>
*/

namespace LibreNMS\Snmptrap\Handlers;

use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;

class AxisAlarmCleared 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)
{
$AlarmString = $trap->getOidData($trap->findOid('AXIS-VIDEO-MIB::alarmID'));
// Handle data type errors in translated trap
$AlarmID = preg_match('/^(?P<error>.+?)?(\:\s)?(?P<value>\d+)$/m', $AlarmString, $matches);
if (! empty($matches['value'])) {
$AlarmID = $matches['value'];
} else {
$AlarmID = $trap->getOidData($trap->findOid('AXIS-VIDEO-MIB::alarmID'));
}

$AlarmName = $trap->getOidData($trap->findOid('AXIS-VIDEO-MIB::alarmName'));
$Message = $trap->getOidData($trap->findOid('AXIS-VIDEO-MIB::alarmText'));

$trap->log("Axis Alarm Cleared Trap: Alarm ID $AlarmID for $AlarmName with text \"$Message\" has cleared", Severity::Ok);
}
}
59 changes: 59 additions & 0 deletions LibreNMS/Snmptrap/Handlers/AxisAlarmNew.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* AxisAlarmNew.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 2024 Transitiv Technologies Ltd. <info@transitiv.co.uk>
* @author Adam Sweet <adam.sweet@transitiv.co.uk>
*/

namespace LibreNMS\Snmptrap\Handlers;

use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;

class AxisAlarmNew 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)
{
$AlarmString = $trap->getOidData($trap->findOid('AXIS-VIDEO-MIB::alarmID'));
// Handle data type errors in translated trap
$AlarmID = preg_match('/^(?P<error>.+?)?(\:\s)?(?P<value>\d+)$/m', $AlarmString, $matches);
if (! empty($matches['value'])) {
$AlarmID = $matches['value'];
} else {
$AlarmID = $trap->getOidData($trap->findOid('AXIS-VIDEO-MIB::alarmID'));
}

$AlarmName = $trap->getOidData($trap->findOid('AXIS-VIDEO-MIB::alarmName'));
$Message = $trap->getOidData($trap->findOid('AXIS-VIDEO-MIB::alarmText'));

$trap->log("Axis Alarm Trap: Alarm ID $AlarmID: $AlarmName: $Message", Severity::Warning);
}
}
59 changes: 59 additions & 0 deletions LibreNMS/Snmptrap/Handlers/AxisAlarmSingle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* AxisAlarmSingle.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 2024 Transitiv Technologies Ltd. <info@transitiv.co.uk>
* @author Adam Sweet <adam.sweet@transitiv.co.uk>
*/

namespace LibreNMS\Snmptrap\Handlers;

use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;

class AxisAlarmSingle 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)
{
$AlarmString = $trap->getOidData($trap->findOid('AXIS-VIDEO-MIB::alarmID'));
// Handle data type errors in translated trap
$AlarmID = preg_match('/^(?P<error>.+?)?(\:\s)?(?P<value>\d+)$/m', $AlarmString, $matches);
if (! empty($matches['value'])) {
$AlarmID = $matches['value'];
} else {
$AlarmID = $trap->getOidData($trap->findOid('AXIS-VIDEO-MIB::alarmID'));
}

$AlarmName = $trap->getOidData($trap->findOid('AXIS-VIDEO-MIB::alarmName'));
$Message = $trap->getOidData($trap->findOid('AXIS-VIDEO-MIB::alarmText'));

$trap->log("Axis Alarm Trap: Alarm ID $AlarmID: $AlarmName: $Message", Severity::Warning);
}
}
2 changes: 2 additions & 0 deletions LibreNMS/Util/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ public static function get($vars): GraphImage
require base_path('/includes/html/graphs/customoid/customoid.inc.php');
} elseif (is_file(base_path("/includes/html/graphs/$type/$subtype.inc.php"))) {
require base_path("/includes/html/graphs/$type/$subtype.inc.php");
} elseif (is_file(base_path("/includes/html/graphs/$type/generic.inc.php"))) {
require base_path("/includes/html/graphs/$type/generic.inc.php");
} else {
throw new RrdGraphException("{$type}_$subtype template missing", "{$type}_$subtype missing", $width, $height);
}
Expand Down
12 changes: 9 additions & 3 deletions LibreNMS/Validations/WebServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,28 @@ public function validate(Validator $validator): void
{
if (! app()->runningInConsole()) {
$url = $this->removeStandardPorts(request()->url());
$expected = $this->removeStandardPorts(Str::finish(Config::get('base_url'), '/') . 'validate/results');
$base_url = Config::get('base_url');
$expected = $this->removeStandardPorts(Str::finish($base_url, '/') . 'validate/results');
$correct_base = str_replace('/validate/results', '', $url);

if ($url !== $expected) {
preg_match($this->host_regex, $url, $actual_host_match);
preg_match($this->host_regex, $expected, $expected_host_match);
$actual_host = $actual_host_match[1] ?? '';
$expected_host = $expected_host_match[1] ?? "parse failure ($expected)";
if ($actual_host != $expected_host) {

if ($base_url == '/' && ! str_contains($actual_host, '/') || ! Str::startsWith($base_url, 'http')) {
$validator->warn('base_url could be more specific', "lnms config:set base_url $correct_base");
} elseif ($actual_host != $expected_host) {
$nginx = Str::startsWith(request()->server->get('SERVER_SOFTWARE'), 'nginx');
$server_name = $nginx ? 'server_name' : 'ServerName';
$fix = $nginx ? "server_name $actual_host;" : "ServerName $actual_host";
$validator->fail("$server_name is set incorrectly for your webserver, update your webserver config. $actual_host $expected_host", $fix);
} else {
$correct_base = str_replace('validate/results', '', $url);
$validator->fail('base_url is not set correctly', "lnms config:set base_url $correct_base");
}
} elseif (preg_replace('#/$#', '', \config('app.url')) !== $correct_base) {
$validator->fail("APP_URL is not set correctly. It should be set to $correct_base");
}

if (request()->secure() && ! \config('session.secure')) {
Expand Down
12 changes: 9 additions & 3 deletions app/Jobs/PollDevice.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Events\DevicePolled;
use App\Events\PollingDevice;
use App\Facades\LibrenmsConfig;
use App\Models\Eventlog;
use App\Polling\Measure\Measurement;
use App\Polling\Measure\MeasurementManager;
Expand Down Expand Up @@ -229,11 +230,16 @@ private function recordPerformance(Measurement $measurement): void

private function getModules(): array
{
if (! empty($this->module_overrides)) {
return $this->module_overrides;
$default_modules = LibrenmsConfig::get('poller_modules', []);

if (empty($this->module_overrides)) {
return $default_modules;
}

return \LibreNMS\Config::get('poller_modules', []);
// ensure order of modules
$ordered_modules = array_fill_keys(array_keys(array_intersect_key($default_modules, $this->module_overrides)), true);

return $ordered_modules;
}

private function isModuleManuallyEnabled(string $module): ?bool
Expand Down
21 changes: 21 additions & 0 deletions app/Logging/LogFileFormatter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Logging;

class LogFileFormatter extends \Monolog\Formatter\LineFormatter
{
public function __construct()
{
parent::__construct(
"[%datetime%][%level_name%] %message% %context% %extra%\n",
'Y-m-d\TH:i:s',
true,
true
);
}

public function format(\Monolog\LogRecord $record): string
{
return parent::format($record);
}
}
4 changes: 2 additions & 2 deletions config/logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@
'single' => [
'driver' => 'single',
'path' => env('APP_LOG', base_path('logs/librenms.log')),
'formatter' => \App\Logging\NoColorFormatter::class,
'level' => env('LOG_LEVEL', 'error'),
'formatter' => \App\Logging\LogFileFormatter::class,
'level' => env('LOG_LEVEL', 'warning'),
'replace_placeholders' => true,
],

Expand Down
3 changes: 3 additions & 0 deletions config/snmptraps.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
'ALCATEL-IND1-LBD-MIB::alaLbdStateChangeToShutdown' => LibreNMS\Snmptrap\Handlers\Aos6LbdStateChangeToShutdown::class,
'ALCATEL-IND1-LBD-MIB::alaLbdStateChangeForAutoRecovery' => LibreNMS\Snmptrap\Handlers\Aos6LbdStateChangeForAutoRecovery::class,
'ALCATEL-IND1-AAA-MIB::aaaHicServerTrap' => LibreNMS\Snmptrap\Handlers\Aos6HicServerTrap::class,
'AXIS-VIDEO-MIB::alarmCleared' => LibreNMS\Snmptrap\Handlers\AxisAlarmCleared::class,
'AXIS-VIDEO-MIB::alarmNew' => LibreNMS\Snmptrap\Handlers\AxisAlarmNew::class,
'AXIS-VIDEO-MIB::alarmSingle' => LibreNMS\Snmptrap\Handlers\AxisAlarmSingle::class,
'BGP4-MIB::bgpBackwardTransition' => LibreNMS\Snmptrap\Handlers\BgpBackwardTransition::class,
'BGP4-MIB::bgpEstablished' => LibreNMS\Snmptrap\Handlers\BgpEstablished::class,
'BGP4-V2-MIB-JUNIPER::jnxBgpM2BackwardTransition' => LibreNMS\Snmptrap\Handlers\JnxBgpM2BackwardTransition::class,
Expand Down
2 changes: 1 addition & 1 deletion doc/Extensions/Dispatcher-Service.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Optional Settings
lnms config:set service_poller_frequency 300
lnms config:set service_services_frequency 300
lnms config:set service_discovery_frequency 21600
lnms config:set schedule_type.alert dispatcher
lnms config:set schedule_type.alerting dispatcher
lnms config:set schedule_type.billing dispatcher
lnms config:set service_billing_frequency 300
lnms config:set service_billing_calculate_frequency 60
Expand Down
48 changes: 48 additions & 0 deletions html/images/logos/seh.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions html/images/os/seh.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 22fc8a0

Please sign in to comment.