From bfaa907b577835186332a5f3cdc9ddf8e30be10d Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Tue, 10 Oct 2023 17:01:21 -0500 Subject: [PATCH] Fix VRP polling Was using deprecated database functions. Use current methods --- LibreNMS/OS/Vrp.php | 80 ++++++++++++++------------------------------- 1 file changed, 24 insertions(+), 56 deletions(-) diff --git a/LibreNMS/OS/Vrp.php b/LibreNMS/OS/Vrp.php index d36c019fcd41..a8bd024796f5 100644 --- a/LibreNMS/OS/Vrp.php +++ b/LibreNMS/OS/Vrp.php @@ -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; @@ -59,6 +62,8 @@ class Vrp extends OS implements SlaPolling, OSDiscovery { + use SyncsModels; + public function discoverMempools() { $mempools = new Collection(); @@ -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) { @@ -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); } }