Add ISIS discovery and polling for iosxe devices (#13880)
* Add ISIS discovery and polling for iosxe devices * remove ModuleModelObserver * add php stan exclusions as they are already present for the base module * change port_id to cached lookup * Create model object instead of using arrays and set properties directly * remove unneeded space... * remove null from non nullable field * revert to extending from ciscowlc rather than os * remove OS module * remove phpstan exclusions and fix errors * add spacing... * add spacing.... * add spacing * again... * Add tests * Update Iosxe.php * Update IsisAdjacency.php * Create 2022_04_08_085504_isis_adjacencies_table_add_index.php * Update db_schema.yaml * Update iosxe_asr920.json * Update Iosxe.php * Update Iosxe.php * Update junos_mx5t_isis.json Co-authored-by: Tony Murray <murraytony@gmail.com>
This commit is contained in:
parent
4910761c25
commit
5672d10a79
|
@ -3,6 +3,7 @@
|
|||
* Iosxe.php
|
||||
*
|
||||
* Cisco IOS-XE Wireless LAN Controller
|
||||
* Cisco IOS-XE ISIS Neighbors
|
||||
*
|
||||
* 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
|
||||
|
@ -25,16 +26,26 @@
|
|||
|
||||
namespace LibreNMS\OS;
|
||||
|
||||
use App\Models\IsisAdjacency;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use LibreNMS\DB\SyncsModels;
|
||||
use LibreNMS\Interfaces\Discovery\IsIsDiscovery;
|
||||
use LibreNMS\Interfaces\Discovery\Sensors\WirelessCellDiscovery;
|
||||
use LibreNMS\Interfaces\Discovery\Sensors\WirelessChannelDiscovery;
|
||||
use LibreNMS\Interfaces\Discovery\Sensors\WirelessRsrpDiscovery;
|
||||
use LibreNMS\Interfaces\Discovery\Sensors\WirelessRsrqDiscovery;
|
||||
use LibreNMS\Interfaces\Discovery\Sensors\WirelessRssiDiscovery;
|
||||
use LibreNMS\Interfaces\Discovery\Sensors\WirelessSnrDiscovery;
|
||||
use LibreNMS\Interfaces\Polling\IsIsPolling;
|
||||
use LibreNMS\Interfaces\Polling\OSPolling;
|
||||
use LibreNMS\OS\Traits\CiscoCellular;
|
||||
use LibreNMS\Util\IP;
|
||||
use SnmpQuery;
|
||||
|
||||
class Iosxe extends Ciscowlc implements
|
||||
IsIsDiscovery,
|
||||
IsIsPolling,
|
||||
OSPolling,
|
||||
WirelessCellDiscovery,
|
||||
WirelessChannelDiscovery,
|
||||
|
@ -43,10 +54,101 @@ class Iosxe extends Ciscowlc implements
|
|||
WirelessRsrpDiscovery,
|
||||
WirelessSnrDiscovery
|
||||
{
|
||||
use SyncsModels;
|
||||
use CiscoCellular;
|
||||
|
||||
public function pollOS(): void
|
||||
{
|
||||
// Don't poll Ciscowlc FIXME remove when wireless-controller module exists
|
||||
}
|
||||
|
||||
/**
|
||||
* Array of shortened ISIS codes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $isis_codes = [
|
||||
'l1IntermediateSystem' => 'L1',
|
||||
'l2IntermediateSystem' => 'L2',
|
||||
'l1L2IntermediateSystem' => 'L1L2',
|
||||
];
|
||||
|
||||
public function discoverIsIs(): Collection
|
||||
{
|
||||
// Check if the device has any ISIS enabled interfaces
|
||||
$circuits = SnmpQuery::enumStrings()->walk('CISCO-IETF-ISIS-MIB::ciiCirc');
|
||||
$adjacencies = new Collection;
|
||||
|
||||
if ($circuits->isValid()) {
|
||||
$circuits = $circuits->table(1);
|
||||
$adjacencies_data = SnmpQuery::enumStrings()->walk('CISCO-IETF-ISIS-MIB::ciiISAdj')->table(2);
|
||||
|
||||
foreach ($adjacencies_data as $circuit_index => $adjacency_list) {
|
||||
foreach ($adjacency_list as $adjacency_index => $adjacency_data) {
|
||||
if (empty($circuits[$circuit_index]['CISCO-IETF-ISIS-MIB::ciiCircIfIndex'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (($circuits[$circuit_index]['CISCO-IETF-ISIS-MIB::ciiCircPassiveCircuit'] ?? 'true') == 'true') {
|
||||
continue; // Do not poll passive interfaces and bad data
|
||||
}
|
||||
|
||||
$adjacencies->push(new IsisAdjacency([
|
||||
'device_id' => $this->getDeviceId(),
|
||||
'index' => "[$circuit_index][$adjacency_index]",
|
||||
'ifIndex' => $circuits[$circuit_index]['CISCO-IETF-ISIS-MIB::ciiCircIfIndex'],
|
||||
'port_id' => $this->ifIndexToId($circuits[$circuit_index]['CISCO-IETF-ISIS-MIB::ciiCircIfIndex']),
|
||||
'isisCircAdminState' => $circuits[$circuit_index]['CISCO-IETF-ISIS-MIB::ciiCircAdminState'] ?? 'down',
|
||||
'isisISAdjState' => $adjacency_data['CISCO-IETF-ISIS-MIB::ciiISAdjState'] ?? 'down',
|
||||
'isisISAdjNeighSysType' => Arr::get($this->isis_codes, $adjacency_data['CISCO-IETF-ISIS-MIB::ciiISAdjNeighSysType'] ?? '', 'unknown'),
|
||||
'isisISAdjNeighSysID' => $this->formatIsIsId($adjacency_data['CISCO-IETF-ISIS-MIB::ciiISAdjNeighSysID'] ?? ''),
|
||||
'isisISAdjNeighPriority' => $adjacency_data['CISCO-IETF-ISIS-MIB::ciiISAdjNeighPriority'] ?? '',
|
||||
'isisISAdjLastUpTime' => $this->parseAdjacencyTime($adjacency_data['CISCO-IETF-ISIS-MIB::ciiISAdjLastUpTime'] ?? 0),
|
||||
'isisISAdjAreaAddress' => implode(',', array_map([$this, 'formatIsIsId'], $adjacency_data['CISCO-IETF-ISIS-MIB::ciiISAdjAreaAddress'] ?? [])),
|
||||
'isisISAdjIPAddrType' => implode(',', $adjacency_data['CISCO-IETF-ISIS-MIB::ciiISAdjIPAddrType'] ?? []),
|
||||
'isisISAdjIPAddrAddress' => implode(',', array_map(function ($ip) {
|
||||
return (string) IP::fromHexstring($ip, true);
|
||||
}, $adjacency_data['CISCO-IETF-ISIS-MIB::ciiISAdjIPAddrAddress'] ?? [])),
|
||||
]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $adjacencies;
|
||||
}
|
||||
|
||||
public function pollIsIs($adjacencies): Collection
|
||||
{
|
||||
$states = SnmpQuery::enumStrings()->walk('CISCO-IETF-ISIS-MIB::ciiISAdjState')->values();
|
||||
$up_count = array_count_values($states)['up'] ?? 0;
|
||||
|
||||
if ($up_count !== $adjacencies->count()) {
|
||||
echo 'New Adjacencies, running discovery';
|
||||
|
||||
return $this->fillNew($adjacencies, $this->discoverIsIs());
|
||||
}
|
||||
|
||||
$uptime = SnmpQuery::walk('CISCO-IETF-ISIS-MIB::ciiISAdjLastUpTime')->values();
|
||||
|
||||
return $adjacencies->each(function (IsisAdjacency $adjacency) use ($states, $uptime) {
|
||||
$adjacency->isisISAdjState = $states['CISCO-IETF-ISIS-MIB::ciiISAdjState' . $adjacency->index] ?? $adjacency->isisISAdjState;
|
||||
$adjacency->isisISAdjLastUpTime = $this->parseAdjacencyTime($uptime['CISCO-IETF-ISIS-MIB::ciiISAdjLastUpTime' . $adjacency->index] ?? 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts SNMP time to int in seconds
|
||||
*
|
||||
* @param string|int $uptime
|
||||
* @return int
|
||||
*/
|
||||
protected function parseAdjacencyTime($uptime): int
|
||||
{
|
||||
return (int) round(max($uptime, 1) / 100);
|
||||
}
|
||||
|
||||
protected function formatIsIsId(string $raw): string
|
||||
{
|
||||
return str_replace(' ', '.', trim($raw));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ class IsisAdjacency extends PortRelatedModel implements Keyable
|
|||
|
||||
protected $fillable = [
|
||||
'device_id',
|
||||
'index',
|
||||
'port_id',
|
||||
'ifIndex',
|
||||
'isisCircAdminState',
|
||||
|
@ -59,6 +60,6 @@ class IsisAdjacency extends PortRelatedModel implements Keyable
|
|||
|
||||
public function getCompositeKey()
|
||||
{
|
||||
return $this->ifIndex;
|
||||
return $this->ifIndex . $this->index;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class IsisAdjacenciesTableAddIndex extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('isis_adjacencies', function (Blueprint $table) {
|
||||
$table->string('index', 16)->nullable()->after('device_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropColumns('isis_adjacencies', 'index');
|
||||
}
|
||||
}
|
|
@ -809,6 +809,7 @@ isis_adjacencies:
|
|||
Columns:
|
||||
- { Field: id, Type: 'int unsigned', 'Null': false, Extra: auto_increment }
|
||||
- { Field: device_id, Type: int, 'Null': false, Extra: '' }
|
||||
- { Field: index, Type: varchar(16), 'Null': true, Extra: '' }
|
||||
- { Field: port_id, Type: int, 'Null': true, Extra: '' }
|
||||
- { Field: ifIndex, Type: int, 'Null': false, Extra: '' }
|
||||
- { Field: isisISAdjState, Type: varchar(13), 'Null': false, Extra: '' }
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -13001,6 +13001,7 @@
|
|||
"discovery": {
|
||||
"isis_adjacencies": [
|
||||
{
|
||||
"index": null,
|
||||
"ifIndex": 559,
|
||||
"isisISAdjState": "up",
|
||||
"isisISAdjNeighSysType": "L2",
|
||||
|
@ -13013,6 +13014,7 @@
|
|||
"isisCircAdminState": "on"
|
||||
},
|
||||
{
|
||||
"index": null,
|
||||
"ifIndex": 572,
|
||||
"isisISAdjState": "up",
|
||||
"isisISAdjNeighSysType": "L2",
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue