Rewrite ISIS Adjacency discovery/polling (#13155)

* Rewrite ISIS Adjacency discovery/polling
hopefully much faster now, do most work in discovery and just check up/down in poller.

* unused variable

* Implement option for OS override

* fix an incorrect typehint

* test data

* work around stupid migration name

* update schema

* better handling for the on-demand discovery

* more detailed phpdoc

* fix when adjacency is not found

* don't clear out data when adjacency goes away

* Adjust nullable fields

* fixes

* fix class name

* correct migration

* fix bug causing adjacency data to always be blank

* port popups for port links

* isisISAdjState does not need to be nullable

* remove extra space

* default off

* If port is missing return $text

* update schema

* Cleanup old components

* correc copy paste error
This commit is contained in:
Tony Murray
2021-08-23 21:19:55 -05:00
committed by GitHub
parent 456c5d2fae
commit 8e409ba051
13 changed files with 358 additions and 186 deletions

View File

@@ -24,18 +24,20 @@
namespace LibreNMS\DB;
use Illuminate\Support\Collection;
trait SyncsModels
{
/**
* Sync several models for a device's relationship
* Model must implement \LibreNMS\Interfaces\Models\Keyable interface
*
* @param \App\Models\Device $device
* @param string $relationship
* @param \Illuminate\Support\Collection $models
* @param \App\Models\Device $device
* @param string $relationship
* @param \Illuminate\Support\Collection $models \LibreNMS\Interfaces\Models\Keyable
* @return \Illuminate\Support\Collection
*/
protected function syncModels($device, $relationship, $models)
protected function syncModels($device, $relationship, $models): Collection
{
$models = $models->keyBy->getCompositeKey();
$existing = $device->$relationship->keyBy->getCompositeKey();
@@ -56,4 +58,26 @@ trait SyncsModels
return $existing->merge($new);
}
/**
* Combine a list of existing and potentially new models
* If the model exists fill any new data from the new models
*
* @param \Illuminate\Support\Collection $existing \LibreNMS\Interfaces\Models\Keyable
* @param \Illuminate\Support\Collection $discovered \LibreNMS\Interfaces\Models\Keyable
* @return \Illuminate\Support\Collection
*/
protected function fillNew(Collection $existing, Collection $discovered): Collection
{
$all = $existing->keyBy->getCompositeKey();
foreach ($discovered as $new) {
if ($found = $all->get($new->getCompositeKey())) {
$found->fill($new->getAttributes());
} else {
$all->put($new->getCompositeKey(), $new);
}
}
return $all;
}
}