Skip to content

Commit

Permalink
Merge branch 'librenms:master' into worknoc
Browse files Browse the repository at this point in the history
  • Loading branch information
ottorei authored Jul 24, 2024
2 parents 1867d81 + 55f603c commit 0faf50b
Show file tree
Hide file tree
Showing 427 changed files with 710,062 additions and 39,192 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
name: Pip install
run: |
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade --user snmpsim pylint python-memcached mysqlclient
python3 -m pip install --upgrade --user pylint python-memcached mysqlclient
-
name: Composer validate
run: |
Expand Down Expand Up @@ -128,6 +128,10 @@ jobs:
name: Composer install
run: |
composer install --prefer-dist --no-interaction --no-progress
-
name: Snmpsim setup
run: |
php lnms dev:simulate --setup-venv
-
name: Artisan dusk:chrome-driver
if: matrix.skip-web-check != '1'
Expand Down Expand Up @@ -168,7 +172,7 @@ jobs:
name: Start SNMP
if: matrix.skip-unit-check != '1'
run: |
~/.local/bin/snmpsimd.py --data-dir=tests/snmpsim --agent-udpv4-endpoint=127.1.6.2:1162 --logging-method=file:/tmp/snmpsimd.log &
.python_venvs/snmpsim/bin/snmpsim-command-responder-lite --data-dir=tests/snmpsim --agent-udpv4-endpoint=127.1.6.2:1162 --log-level=error --logging-method=file:/tmp/snmpsimd.log &
-
name: lnms dev:check ci
run: |
Expand Down
25 changes: 20 additions & 5 deletions LibreNMS/Data/Source/NetSnmpQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class NetSnmpQuery implements SnmpQueryInterface
*/
private array $mibDirs = [];
private string $context = '';
private array|string $options = [self::DEFAULT_FLAGS];
private array|string $options = [self::DEFAULT_FLAGS, '-Pu'];
private Device $device;
private bool $abort = false;
private bool $cache = false;
Expand Down Expand Up @@ -312,7 +312,9 @@ public function translate(string $oid): string

// user did not specify numeric, output full text
if (! in_array('-On', $this->options)) {
$this->options[] = '-OS';
if (! in_array('-Os', $this->options)) {
$this->options[] = '-OS'; // show full oid, unless hideMib is set
}
} elseif (Oid::isNumeric($oid)) {
return Str::start($oid, '.'); // numeric to numeric optimization
}
Expand Down Expand Up @@ -407,8 +409,21 @@ private function execMultiple(string $command, array $oids): SnmpResponse
private function exec(string $command, array $oids): SnmpResponse
{
// use runtime(array) cache if requested. The 'null' driver will simply return the value without caching
$driver = $this->cache ? 'array' : 'null';
$key = $this->cache ? $this->getCacheKey($command, $oids) : '';
$driver = 'null';
$key = '';

if ($this->cache) {
$driver = 'array';
$key = $this->getCacheKey($command, $oids);

if (Debug::isEnabled()) {
if (Cache::driver($driver)->has($key)) {
Log::debug("Cache hit for $command " . implode(',', $oids));
} else {
Log::debug("Cache miss for $command " . implode(',', $oids) . ', grabbing fresh data.');
}
}
}

return Cache::driver($driver)->rememberForever($key, function () use ($command, $oids) {
$measure = Measurement::start($command);
Expand Down Expand Up @@ -546,6 +561,6 @@ private function getCacheKey(string $type, array $oids): string
$oids = implode(',', $oids);
$options = implode(',', $this->options);

return "$type|{$this->device->hostname}|$this->context|$oids|$options";
return "$type|{$this->device->hostname}|{$this->device->community}|$this->context|$oids|$options";
}
}
30 changes: 13 additions & 17 deletions LibreNMS/Data/Source/SnmpResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,23 +216,19 @@ public function mapTable(callable $callback): Collection
return new Collection;
}

return collect($this->values())
->map(function ($value, $oid) {
$parts = $this->getOidParts($oid);
$key = array_shift($parts);

return [
'_index' => implode('][', $parts),
$key => $value,
];
})
->groupBy('_index')
->map(function ($values, $index) use ($callback) {
$values = array_merge(...$values);
unset($values['_index']);

return call_user_func($callback, $values, ...explode('][', (string) $index));
});
$data = [];
foreach ($this->values() as $key => $value) {
$parts = $this->getOidParts($key);
$oid = array_shift($parts);
$data[implode('][', $parts)][$oid] = $value;
}

$return = new Collection;
foreach ($data as $index => $values) {
$return->push(call_user_func($callback, $values, ...explode('][', (string) $index)));
}

return $return;
}

/**
Expand Down
32 changes: 25 additions & 7 deletions LibreNMS/Data/Store/InfluxDBv2.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

namespace LibreNMS\Data\Store;

use App\Facades\DeviceCache;
use App\Polling\Measure\Measurement;
use InfluxDB2\Client;
use InfluxDB2\Model\WritePrecision;
Expand Down Expand Up @@ -62,6 +63,21 @@ public static function isEnabled()
*/
public function put($device, $measurement, $tags, $fields)
{
$device_data = DeviceCache::get($device['device_id']);
$excluded_groups = Config::get('influxdbv2.groups-exclude');

if (! empty($excluded_groups)) {
$device_groups = $device_data->groups;
foreach ($device_groups as $group) {
// The group name will always be parsed as lowercase, even when uppercase in the GUI.
if (in_array(strtoupper($group->name), array_map('strtoupper', $excluded_groups))) {
Log::warning('Skipped parsing to InfluxDBv2, device is in group: ' . $group->name);

return;
}
}
}

$stat = Measurement::start('write');
$tmp_fields = [];
$tmp_tags['hostname'] = $device['hostname'];
Expand All @@ -87,11 +103,13 @@ public function put($device, $measurement, $tags, $fields)
return;
}

Log::debug('InfluxDB data: ', [
'measurement' => $measurement,
'tags' => $tmp_tags,
'fields' => $tmp_fields,
]);
if (Config::get('influxdbv2.debug') === true) {
Log::debug('InfluxDB data: ', [
'measurement' => $measurement,
'tags' => $tmp_tags,
'fields' => $tmp_fields,
]);
}

// Get a WriteApi instance from the client
$client = self::createFromConfig();
Expand Down Expand Up @@ -133,15 +151,15 @@ public static function createFromConfig()
$organization = Config::get('influxdbv2.organization', '');
$allow_redirects = Config::get('influxdbv2.allow_redirects', true);
$token = Config::get('influxdbv2.token', '');

$debug = Config::get('influxdbv2.debug', false);
$client = new Client([
'url' => $transport . '://' . $host . ':' . $port,
'token' => $token,
'bucket' => $bucket,
'org' => $organization,
'precision' => WritePrecision::S,
'allow_redirects' => $allow_redirects,
'debug' => true,
'debug' => $debug,
]);

return $client;
Expand Down
6 changes: 6 additions & 0 deletions LibreNMS/Data/Store/Prometheus.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public function __construct()

$this->client = Http::client()->baseUrl($this->base_uri);

$user = Config::get('prometheus.user', '');
$passwd = Config::get('prometheus.password', '');
if ($user && $passwd) {
$this->client = $this->client->withBasicAuth($user, $passwd);
}

$this->prefix = Config::get('prometheus.prefix', '');
if ($this->prefix) {
$this->prefix = "$this->prefix" . '_';
Expand Down
2 changes: 1 addition & 1 deletion LibreNMS/Device/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public static function processYaml(OS $os)
return [];
}

return YamlDiscovery::discover($os, get_class(), $discovery);
return YamlDiscovery::discover($os, get_called_class(), $discovery);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion LibreNMS/Device/Sensor.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private function fetch()
'WHERE `device_id`=? AND `sensor_class`=? AND `sensor_type`=? AND `sensor_index`=?',
[$this->device_id, $this->type, $this->subtype, $this->index]
);
$this->sensor_id = $sensor['sensor_id'];
$this->sensor_id = $sensor['sensor_id'] ?? null;

return $sensor;
}
Expand Down
70 changes: 70 additions & 0 deletions LibreNMS/OS/ArubaosCx.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/*
* ArubaosCx.php
*
* NAC polling including 802.1x and device-profile entries.
*
* 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/>.
*
* @package LibreNMS
* @link https://www.librenms.org
*/

namespace LibreNMS\OS;

use App\Models\PortsNac;
use Illuminate\Support\Collection;
use LibreNMS\Interfaces\Polling\NacPolling;
use SnmpQuery;

class ArubaosCx extends \LibreNMS\OS implements NacPolling
{
public function pollNac()
{
$nac = new Collection();

$rowSet = [];
$ifIndex_map = $this->getDevice()->ports()->pluck('port_id', 'ifName');
$table = SnmpQuery::mibDir('arubaos-cx')->mibs(['ARUBAWIRED-PORT-ACCESS-MIB'])->hideMib()->enumStrings()->walk('arubaWiredPortAccessClientTable')->table(2);

foreach ($table as $ifIndex => $entry) {
foreach ($entry as $macKey => $macEntry) {
$rowSet[$macKey] = [
'domain' => '',
'ip_address' => '',
'host_mode' => '',
'authz_by' => '',
'username' => '',
'timeout' => '',
];
$rowSet[$macKey]['authc_status'] = $macEntry['arubaWiredPacAuthState'] ?? '';
$rowSet[$macKey]['mac_address'] = $macKey;
$rowSet[$macKey]['authz_by'] = $macEntry['arubaWiredPacOnboardedMethods'] ?? '';
$rowSet[$macKey]['authz_status'] = '';
$rowSet[$macKey]['username'] = $macEntry['arubaWiredPacUserName'] ?? '';
$rowSet[$macKey]['vlan'] = $macEntry['arubaWiredPacVlanId'] ?? null;
$rowSet[$macKey]['port_id'] = $ifIndex_map->get($ifIndex, 0);
$rowSet[$macKey]['auth_id'] = $ifIndex;
$rowSet[$macKey]['method'] = $macEntry['arubaWiredPacOnboardedMethods'] ?? '';
}
}

foreach ($rowSet as $row) {
var_dump($row);
$nac->put($row['mac_address'], new PortsNac($row));
}

return $nac;
}
}
2 changes: 1 addition & 1 deletion LibreNMS/OS/EltexMes23xx.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class EltexMes23xx extends OS
/**
* Specific HexToString for Eltex
*/
public function normData(string $par = ''): string
public static function normData(string $par = ''): string
{
$tmp = str_replace([':', ' '], '', trim(strtoupper($par)));
$ret = preg_match('/^[0-9A-F]+$/', $tmp) ? hex2str($tmp) : $par; //if string is pure hex, convert to ascii
Expand Down
92 changes: 92 additions & 0 deletions LibreNMS/OS/Fortiextender.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/*
* Fortiextender.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/>.
*
* @package LibreNMS
* @link https://www.librenms.org
* @copyright 2024 CTNET B.V.
* @author Rudy Broersma <[email protected]>
*/

namespace LibreNMS\OS;

use LibreNMS\Device\WirelessSensor;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessRsrpDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessRsrqDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessRssiDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessSinrDiscovery;
use LibreNMS\OS\Shared\Fortinet;

class Fortiextender extends Fortinet implements
WirelessSinrDiscovery,
WirelessRsrpDiscovery,
WirelessRsrqDiscovery,
WirelessRssiDiscovery
{
public function discoverWirelessSinr()
{
$sinr_group = snmpwalk_group($this->getDeviceArray(), 'fextInfoModemStatusSINR', 'FORTINET-FORTIEXTENDER-MIB', 1);
$oid = '.1.3.6.1.4.1.12356.121.21.3.1.1.28.';

$sinr = [];
foreach ($sinr_group as $key => $sinr_entry) {
$sinr[] = new WirelessSensor('sinr', $this->getDeviceId(), $oid . $key, 'fortiextender', $key, 'Modem ' . $key);
}

return $sinr;
}

public function discoverWirelessRsrp()
{
$rsrp_group = snmpwalk_group($this->getDeviceArray(), 'fextInfoModemStatusSINR', 'FORTINET-FORTIEXTENDER-MIB', 1);
$oid = '.1.3.6.1.4.1.12356.121.21.3.1.1.29.';

$rsrp = [];
foreach ($rsrp_group as $key => $rsrp_entry) {
$rsrp[] = new WirelessSensor('rsrp', $this->getDeviceId(), $oid . $key, 'fortiextender', $key, 'Modem ' . $key);
}

return $rsrp;
}

public function discoverWirelessRsrq()
{
$rsrq_group = snmpwalk_group($this->getDeviceArray(), 'fextInfoModemStatusRSRQ', 'FORTINET-FORTIEXTENDER-MIB', 1);
$oid = '.1.3.6.1.4.1.12356.121.21.3.1.1.30.';

$rsrq = [];
foreach ($rsrq_group as $key => $rsrq_entry) {
$rsrq[] = new WirelessSensor('rsrq', $this->getDeviceId(), $oid . $key, 'fortiextender', $key, 'Modem ' . $key);
}

return $rsrq;
}

public function discoverWirelessRssi()
{
$rsrq_group = snmpwalk_group($this->getDeviceArray(), 'fextInfoModemStatusRSSI', 'FORTINET-FORTIEXTENDER-MIB', 1);
$oid = '.1.3.6.1.4.1.12356.121.21.3.1.1.22.';

$rsrq = [];
foreach ($rsrq_group as $key => $rsrq_entry) {
$rsrq[] = new WirelessSensor('rssi', $this->getDeviceId(), $oid . $key, 'fortiextender', $key, 'Modem ' . $key);
}

return $rsrq;
}
}
Loading

0 comments on commit 0faf50b

Please sign in to comment.