Skip to content

Commit

Permalink
Fix VRP polling
Browse files Browse the repository at this point in the history
Was using deprecated database functions.
Use current methods
  • Loading branch information
murrant committed Oct 10, 2023
1 parent c87c6e8 commit bfaa907
Showing 1 changed file with 24 additions and 56 deletions.
80 changes: 24 additions & 56 deletions LibreNMS/OS/Vrp.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@

namespace LibreNMS\OS;

use App\Models\AccessPoint;
use App\Models\Device;
use App\Models\Mempool;
use App\Models\PortsNac;
use App\Models\Sla;
use App\Observers\ModuleModelObserver;
use Carbon\Carbon;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use LibreNMS\DB\SyncsModels;
use LibreNMS\Device\Processor;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\Interfaces\Data\DataStorageInterface;
Expand All @@ -59,6 +62,8 @@ class Vrp extends OS implements
SlaPolling,
OSDiscovery
{
use SyncsModels;

public function discoverMempools()
{
$mempools = new Collection();
Expand Down Expand Up @@ -165,7 +170,7 @@ public function pollOS(DataStorageInterface $datastore): void
$tags = compact('rrd_def');
$datastore->put($this->getDeviceArray(), 'vrp', $tags, $fields);

$ap_db = dbFetchRows('SELECT * FROM `access_points` WHERE `device_id` = ?', [$this->getDeviceArray()['device_id']]);
$aps = new Collection;

foreach ($radioTable as $ap_id => $ap) {
foreach ($ap as $r_id => $radio) {
Expand Down Expand Up @@ -226,63 +231,26 @@ public function pollOS(DataStorageInterface $datastore): void
$tags = compact('name', 'radionum', 'rrd_name', 'rrd_def');
$datastore->put($this->getDeviceArray(), 'arubaap', $tags, $fields);

$foundid = 0;

for ($z = 0; $z < count($ap_db); $z++) {
if ($ap_db[$z]['name'] == $name && $ap_db[$z]['radio_number'] == $radionum) {
$foundid = $ap_db[$z]['accesspoint_id'];
$ap_db[$z]['seen'] = 1;
continue;
}
}

if ($foundid == 0) {
$ap_id = dbInsert(
[
'device_id' => $this->getDeviceArray()['device_id'],
'name' => $name,
'radio_number' => $radionum,
'type' => $type,
'mac_addr' => $mac,
'channel' => $channel,
'txpow' => $txpow,
'radioutil' => $radioutil,
'numasoclients' => $numasoclients,
'nummonclients' => $nummonclients,
'numactbssid' => $numactbssid,
'nummonbssid' => $nummonbssid,
'interference' => $interference,
],
'access_points'
);
} else {
dbUpdate(
[
'mac_addr' => $mac,
'type' => $type,
'deleted' => 0,
'channel' => $channel,
'txpow' => $txpow,
'radioutil' => $radioutil,
'numasoclients' => $numasoclients,
'nummonclients' => $nummonclients,
'numactbssid' => $numactbssid,
'nummonbssid' => $nummonbssid,
'interference' => $interference,
],
'access_points',
'`accesspoint_id` = ?',
[$foundid]
);
}
}//end foreach 1
}//end foreach 2

for ($z = 0; $z < count($ap_db); $z++) {
if (! isset($ap_db[$z]['seen']) && $ap_db[$z]['deleted'] == 0) {
dbUpdate(['deleted' => 1], 'access_points', '`accesspoint_id` = ?', [$ap_db[$z]['accesspoint_id']]);
$aps->push(new AccessPoint([
'device_id' => $this->getDeviceId(),
'name' => $name,
'radio_number' => $radionum,
'type' => $type,
'mac_addr' => $mac,
'channel' => $channel,
'txpow' => $txpow,
'radioutil' => $radioutil,
'numasoclients' => $numasoclients,
'nummonclients' => $nummonclients,
'numactbssid' => $numactbssid,
'nummonbssid' => $nummonbssid,
'interference' => $interference,
]));
}
}

ModuleModelObserver::observe(AccessPoint::class);
$this->syncModels($this->getDevice(), 'accessPoints', $aps);
}
}

Expand Down

0 comments on commit bfaa907

Please sign in to comment.