Update IronWare sensors & bgp-peers discovery, allow skip_values to target a specific index appended to the OID (#10941)

* Migrate ironware sensor discovery from php to yaml.

* More sensors, add grouping.

* dynamic_discovery_get_value() becomes getValueFromData()

* Target a specific index with skip_values.

* Improve Brocade BGP session discovery/polling

This commit allows for the correct discovery of BGP sessions
with 32-bit ASNs, IPv6 neighbors using the BGP4V2-MIB which is
based on draft-ietf-idr-bgp4-mibv2-11 and also polls for IPv4
unicast received routes through the FOUNDRY-SN-BGP4-GROUP-MIB.

Copied most of the code from PR#8877 by @Mikeburke14, cleaned
up the code a little bit to match the normal LibreNMS style,
and fixed bgpPeers_cbgp discovery as well as polling for the
ipv4.unicast neighbors.

Note that older Brocade IronWare firmware versions are known
to have multiple defects relating to the BGP4V2-MIB which
might result in certain missing non-established neighbors.

Related vendor defect numbers:

- DEFECT000633962
-- Symptom: The OID bgp4V2PeerAdminStatus does not return the
            correct value
-- Reported: NI 05.7.00
-- Resolved: NI 05.8.00g

- DEFECT000583319
-- Symptom: SNMP polling on bgp4V2PeerTable (OID brcdIp.3.5.1.1.2)
            does not display all the BGP entries
-- Reported: NI 05.6.00
-- Resolved: NI 05.8.00e

- DEFECT000550309
-- Symptom: SNMP polling on bgp4V2PeerTable (OID brcdIp.3.5.1.1.2)
            does not display the full information
-- Reported: NI 05.7.00
-- Resolved: NI 05.8.00c

* Add ironware CER & ICX platform test data.

* Re-add ironware.json compatible with current master branch.
This commit is contained in:
Martijn Schmidt
2020-02-01 23:28:03 +01:00
committed by GitHub
parent 398d5fe2b7
commit a64bd45dbc
14 changed files with 29126 additions and 265 deletions

View File

@@ -86,7 +86,7 @@ class YamlDiscovery
$current_data[$name] = static::replaceValues($name, $index, $count, $data, $pre_cache);
} else {
// replace references to data
$current_data[$name] = dynamic_discovery_get_value($name, $index, $data, $pre_cache, $value);
$current_data[$name] = static::getValueFromData($name, $index, $data, $pre_cache, $value);
}
}
@@ -108,7 +108,7 @@ class YamlDiscovery
public static function replaceValues($name, $index, $count, $data, $pre_cache)
{
$value = dynamic_discovery_get_value($name, $index, $data, $pre_cache);
$value = static::getValueFromData($name, $index, $data, $pre_cache);
if (is_null($value)) {
// built in replacements
$search = [
@@ -130,7 +130,7 @@ class YamlDiscovery
// search discovery data for values
$value = preg_replace_callback('/{{ \$([a-zA-Z0-9.]+) }}/', function ($matches) use ($index, $data, $pre_cache) {
$replace = dynamic_discovery_get_value($matches[1], $index, $data, $pre_cache, null);
$replace = static::getValueFromData($matches[1], $index, $data, $pre_cache, null);
if (is_null($replace)) {
d_echo('Warning: No variable available to replace ' . $matches[1] . ".\n");
return ''; // remove the unavailable variable
@@ -147,7 +147,7 @@ class YamlDiscovery
* Helper function for dynamic discovery to search for data from pre_cached snmp data
*
* @param string $name The name of the field from the discovery data or just an oid
* @param int $index The index of the current sensor
* @param string $index The index of the current sensor
* @param array $discovery_data The discovery data for the current sensor
* @param array $pre_cache all pre-cached snmp data
* @param mixed $default The default value to return if data is not found
@@ -169,6 +169,8 @@ class YamlDiscovery
return $pre_cache[$name][$index][$name];
} elseif (isset($pre_cache[$index][$name])) {
return $pre_cache[$index][$name];
} elseif (isset($pre_cache[$name][$index])) {
return $pre_cache[$name][$index];
} elseif (count($pre_cache[$name]) === 1) {
return current($pre_cache[$name]);
}
@@ -252,6 +254,10 @@ class YamlDiscovery
// Dynamic skipping of data
$op = isset($skip_value['op']) ? $skip_value['op'] : '!=';
$tmp_value = static::getValueFromData($skip_value['oid'], $index, $yaml_item_data, $pre_cache);
if (str_contains($skip_value['oid'], '.')) {
list($skip_value['oid'], $targeted_index) = explode('.', $skip_value['oid'], 2);
$tmp_value = static::getValueFromData($skip_value['oid'], $targeted_index, $yaml_item_data, $pre_cache);
}
if (compare_var($tmp_value, $skip_value['value'], $op)) {
return true;
}

View File

@@ -136,7 +136,11 @@ case the oid is indexed multiple times) are also available: if
$index="1.20", then $subindex0="1" and $subindex1="20".
> `skip_values` can also compare items within the OID table against
> values. One example of this is:
> values. The index of the sensor is used to retrieve the value
> from the OID, unless a target index is appended to the OID.
> Comparisons behave on a logical OR basis when chained, so only
> one of them needs to be matched for that particular sensor
> to be skipped during discovery. An example of this is below:
```yaml
skip_values:
@@ -144,6 +148,10 @@ $index="1.20", then $subindex0="1" and $subindex1="20".
oid: sensUnit
op: '!='
value: 4
-
oid: sensConfig.0
op: '!='
value: 1
```
> ``` op ``` can be any of the following operators :

View File

@@ -0,0 +1,146 @@
mib: FOUNDRY-SN-AGENT-MIB:FOUNDRY-SN-SWITCH-GROUP-MIB:FOUNDRY-SN-STACKING-MIB
modules:
sensors:
pre-cache:
data:
- oid:
- ifDescr
dbm:
data:
-
oid: snIfOpticalMonitoringInfoTable
value: snIfOpticalMonitoringRxPower
num_oid: '.1.3.6.1.4.1.1991.1.1.3.3.6.1.3.{{ $index }}'
descr: '{{ $ifDescr }} Rx Power'
index: 'snIfOpticalMonitoringRxPower.{{ $index }}'
-
oid: snIfOpticalMonitoringInfoTable
value: snIfOpticalMonitoringTxPower
num_oid: '.1.3.6.1.4.1.1991.1.1.3.3.6.1.2.{{ $index }}'
descr: '{{ $ifDescr }} Tx Power'
index: 'snIfOpticalMonitoringTxPower.{{ $index }}'
current:
options:
divisor: 1000
data:
-
oid: snIfOpticalMonitoringInfoTable
value: snIfOpticalMonitoringTxBiasCurrent
num_oid: '.1.3.6.1.4.1.1991.1.1.3.3.6.1.4.{{ $index }}'
descr: '{{ $ifDescr }} Tx Bias Current'
index: 'snIfOpticalMonitoringTxBiasCurrent.{{ $index }}'
temperature:
data:
-
oid: snAgentTempTable
value: snAgentTempValue
divisor: 2
num_oid: '.1.3.6.1.4.1.1991.1.1.2.13.1.1.4.{{ $index }}'
descr: snAgentTempSensorDescr
index: '{{ $index }}'
group: 'Module Temperatures'
-
oid: snIfOpticalMonitoringInfoTable
value: snIfOpticalMonitoringTemperature
num_oid: '.1.3.6.1.4.1.1991.1.1.3.3.6.1.1.{{ $index }}'
descr: '{{ $ifDescr }} Tx Laser'
index: 'snIfOpticalMonitoringTemperature.{{ $index }}'
group: 'Transceiver Temperatures'
state:
data:
-
oid: snChasPwrSupplyTable
value: snChasPwrSupplyOperStatus
num_oid: '.1.3.6.1.4.1.1991.1.1.1.2.1.1.3.{{ $index }}'
descr: 'Power Supply {{ $index }}'
index: '{{ $index }}'
skip_values: 1
group: Power Supply Status
state_name: snChasPwrSupplyOperStatus
states:
- { value: 1, descr: other, graph: 0, generic: 3 }
- { value: 2, descr: normal, graph: 1, generic: 0 }
- { value: 3, descr: failure, graph: 0, generic: 2 }
-
oid: snChasFanTable
value: snChasFanOperStatus
num_oid: '.1.3.6.1.4.1.1991.1.1.1.3.1.1.3.{{ $index }}'
descr: '{{ $snChasFanDescription }}'
index: 'snChasFanOperStatus.{{ $index }}'
group: Fan Status
state_name: snChasFanOperStatus
states:
- { value: 1, descr: other, graph: 0, generic: 3 }
- { value: 2, descr: normal, graph: 1, generic: 0 }
- { value: 3, descr: failure, graph: 0, generic: 2 }
-
oid: snStackingGlobalConfigState
num_oid: '.1.3.6.1.4.1.1991.1.1.3.31.1.1.{{ $index }}'
descr: 'Global Stack Config State'
index: 'snStackingGlobalConfigState.{{ $index }}'
group: Stacking Status
state_name: snStackingGlobalConfigState
states:
- { value: 0, descr: none, graph: 0, generic: 3 }
- { value: 1, descr: enabled, graph: 1, generic: 0 }
- { value: 2, descr: disabled, graph: 0, generic: 0 }
-
oid: snStackingOperUnitTable
value: snStackingOperUnitState
num_oid: '.1.3.6.1.4.1.1991.1.1.3.31.2.2.1.5.{{ $index }}'
descr: 'Unit {{ $index }} Stack State'
index: 'snStackingOperUnitState.{{ $index }}'
skip_values:
-
oid: snStackingGlobalConfigState.0
op: '!='
value: 1
group: Stacking Status
state_name: snStackingOperUnitState
states:
- { value: 1, descr: local, graph: 0, generic: 0 }
- { value: 2, descr: remote, graph: 1, generic: 0 }
- { value: 3, descr: reserved, graph: 0, generic: 2 }
- { value: 4, descr: empty, graph: 0, generic: 2 }
-
oid: snStackingOperUnitTable
value: snStackingOperUnitStackPort1State
num_oid: '.1.3.6.1.4.1.1991.1.1.3.31.2.2.1.8.{{ $index }}'
descr: 'Unit {{ $index }} Stack-port 1 to Unit {{ $snStackingOperUnitNeighbor1 }}'
index: 'snStackingOperUnitStackPort1State.{{ $index }}'
skip_values:
-
oid: snStackingGlobalConfigState.0
op: '!='
value: 1
-
oid: snStackingOperUnitStackPort1
op: '='
value: 0
group: Stacking Status
state_name: snStackingOperUnitStackPortState
states:
- { value: 1, descr: other, graph: 0, generic: 3 }
- { value: 2, descr: up, graph: 1, generic: 0 }
- { value: 3, descr: down, graph: 0, generic: 2 }
-
oid: snStackingOperUnitTable
value: snStackingOperUnitStackPort2State
num_oid: '.1.3.6.1.4.1.1991.1.1.3.31.2.2.1.10.{{ $index }}'
descr: 'Unit {{ $index }} Stack-port 2 to Unit {{ $snStackingOperUnitNeighbor2 }}'
index: 'snStackingOperUnitStackPort2State.{{ $index }}'
skip_values:
-
oid: snStackingGlobalConfigState.0
op: '!='
value: 1
-
oid: snStackingOperUnitStackPort2
op: '='
value: 0
group: Stacking Status
state_name: snStackingOperUnitStackPortState
states:
- { value: 1, descr: other, graph: 0, generic: 3 }
- { value: 2, descr: up, graph: 1, generic: 0 }
- { value: 3, descr: down, graph: 0, generic: 2 }

View File

@@ -97,6 +97,9 @@ if (Config::get('enable_bgp')) {
} elseif ($device['os_group'] === 'cisco') {
$peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB');
$peer2 = !empty($peers_data);
} elseif ($device['os_group'] === 'brocade') {
$peers_data = snmp_walk($device, 'bgp4V2PeerRemoteAs', '-Oq', 'BGP4V2-MIB', 'brocade');
$peer2 = !empty($peers_data);
}
if (empty($peers_data)) {
@@ -128,7 +131,6 @@ if (Config::get('enable_bgp')) {
if ($peer2 === true) {
$af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', array(), 'CISCO-BGP4-MIB');
}
if (empty($af_data)) {
$af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', array(), 'CISCO-BGP4-MIB');
$peer2 = false;
@@ -148,6 +150,14 @@ if (Config::get('enable_bgp')) {
$af_list = build_cbgp_peers($device, $peer, $af_data, $peer2);
}
if ($device['os_group'] === 'brocade') {
// Brocade doesn't return MP-BGP SAFIs in the BGP4V2-MIB data, so it only displays the unicast SAFI
d_echo("Brocade:");
$afi = IP::parse($peer['ip'])->getFamily();
$af_list[$peer['ip']][$afi]['unicast'] = 1;
add_cbgp_peer($device, $peer, $afi, 'unicast');
}
if (!$bgp4_mib && $device['os'] == 'junos') {
$afis['ipv4'] = 'ipv4';
$afis['ipv6'] = 'ipv6';

View File

@@ -1080,7 +1080,7 @@ function discovery_process(&$valid, $device, $sensor_type, $pre_cache)
if (is_numeric($data[$limit])) {
$$limit = $data[$limit];
} else {
$$limit = dynamic_discovery_get_value($limit, $index, $data, $pre_cache, 'null');
$$limit = YamlDiscovery::getValueFromData($limit, $index, $data, $pre_cache, 'null');
if (is_numeric($$limit)) {
$$limit = ($$limit / $divisor) * $multiplier;
}
@@ -1118,43 +1118,6 @@ function discovery_process(&$valid, $device, $sensor_type, $pre_cache)
}
}
/**
* Helper function for dynamic discovery to search for data from pre_cached snmp data
*
* @param string $name The name of the field from the discovery data or just an oid
* @param int $index The index of the current sensor
* @param array $discovery_data The discovery data for the current sensor
* @param array $pre_cache all pre-cached snmp data
* @param mixed $default The default value to return if data is not found
* @return mixed
*/
function dynamic_discovery_get_value($name, $index, $discovery_data, $pre_cache, $default = null)
{
if (isset($discovery_data[$name])) {
$name = $discovery_data[$name];
}
if (isset($pre_cache[$discovery_data['oid']][$index][$name])) {
return $pre_cache[$discovery_data['oid']][$index][$name];
}
if (isset($pre_cache[$name])) {
if (is_array($pre_cache[$name])) {
if (isset($pre_cache[$name][$index][$name])) {
return $pre_cache[$name][$index][$name];
} elseif (isset($pre_cache[$index][$name])) {
return $pre_cache[$index][$name];
} elseif (count($pre_cache[$name]) === 1) {
return current($pre_cache[$name]);
}
} else {
return $pre_cache[$name];
}
}
return $default;
}
/**
* @param $types
* @param $device
@@ -1193,13 +1156,17 @@ function build_bgp_peers($device, $data, $peer2)
'BGP4-MIB::bgpPeerRemoteAs.',
'HUAWEI-BGP-VPN-MIB::hwBgpPeerRemoteAs.',
'.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.',
'BGP4V2-MIB::bgp4V2PeerRemoteAs.1.ipv4.',
'BGP4V2-MIB::bgp4V2PeerRemoteAs.1.ipv6.',
);
$peers = trim(str_replace($remove, '', $data));
$peerlist = array();
$ver = '';
foreach (explode("\n", $peers) as $peer) {
$local_ip = null;
if ($peer2 === true) {
$peerFull = $peer;
list($ver, $peer) = explode('.', $peer, 2);
}
list($peer_ip, $peer_as) = explode(' ', $peer);
@@ -1213,6 +1180,21 @@ function build_bgp_peers($device, $data, $peer2)
// ipv4
$peer_ip = implode('.', array_slice(explode('.', $peer_ip), -4));
}
} elseif ($device['os_group'] === 'brocade') {
$rawIP = $peer_ip;
$ver = '';
$octets = count(explode('.', $rawIP));
if ($octets > 11) {
// ipv6
$peer_ip = (string)IP::parse(snmp2ipv6($rawIP), true);
$parts = explode('.2.16.', $peerFull);
$ip_parts = str_split(str_replace(':', '', $parts[0]), 4);
$local_ip = implode(':', $ip_parts);
} else {
// ipv4
$peer_ip = implode('.', array_slice(explode('.', $rawIP), -4));
$local_ip = implode('.', array_slice(explode('.', $rawIP), 0, 4));
}
} else {
if (strstr($peer_ip, ':')) {
$peer_ip_snmp = preg_replace('/:/', ' ', $peer_ip);
@@ -1223,9 +1205,10 @@ function build_bgp_peers($device, $data, $peer2)
if ($peer && $peer_ip != '0.0.0.0') {
d_echo("Found peer $peer_ip (AS$peer_as)\n");
$peerlist[] = array(
'ip' => $peer_ip,
'as' => $peer_as,
'ver' => $ver,
'ip' => $peer_ip,
'as' => $peer_as,
'localip' => $local_ip ?: '0.0.0.0',
'ver' => $ver,
);
}
}
@@ -1284,7 +1267,7 @@ function add_bgp_peer($device, $peer)
'astext' => $peer['astext'],
'bgpPeerState' => 'idle',
'bgpPeerAdminStatus' => 'stop',
'bgpLocalAddr' => '0.0.0.0',
'bgpLocalAddr' => $peer['localip'] ?: '0.0.0.0',
'bgpPeerRemoteAddr' => '0.0.0.0',
'bgpPeerInUpdates' => 0,
'bgpPeerOutUpdates' => 0,

View File

@@ -1,70 +0,0 @@
<?php
/*
* LibreNMS Interface Power dBm module for Brocade IronWare
*
* © 2017 Chris A. Evans <thecityofguanyu@outlook.com>
*
* 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. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
echo 'Brocade IronWare Interface dBm ';
$multiplier = 1;
$divisor = 1000;
foreach ($pre_cache['ironware_optic_oids'] as $index => $entry) {
if ($entry['snIfOpticalMonitoringRxPower']) {
if (strpos($entry['snIfOpticalMonitoringRxPower'], 'N\/A') !== true) {
return_num($entry);
$oid = '.1.3.6.1.4.1.1991.1.1.3.3.6.1.3.' . $index;
$descr = dbFetchCell('SELECT `ifDescr` FROM `ports` WHERE `ifIndex`= ? AND `device_id` = ?', [$index, $device['device_id']]) . ' Rx Power';
discover_sensor(
$valid['sensor'],
'dbm',
$device,
$oid,
'snIfOpticalMonitoringRxPower.'.$index,
'ironware',
$descr,
null,
null,
null,
null,
null,
null,
$currentrx,
'snmp'
);
}
}
if ($entry['snIfOpticalMonitoringTxPower']) {
if (strpos($entry['snIfOpticalMonitoringTxPower'], 'N\/A') !== true) {
return_num($entry);
$oid = '.1.3.6.1.4.1.1991.1.1.3.3.6.1.2.' . $index;
$descr = dbFetchCell('SELECT `ifDescr` FROM `ports` WHERE `ifIndex`= ? AND `device_id` = ?', [$index, $device['device_id']]) . ' Tx Power';
discover_sensor(
$valid['sensor'],
'dbm',
$device,
$oid,
'snIfOpticalMonitoringTxPower.'.$index,
'ironware',
$descr,
null,
null,
null,
null,
null,
null,
$currenttx,
'snmp'
);
}
}
}

View File

@@ -1,16 +0,0 @@
<?php
/*
* LibreNMS Sensor pre-cache module for Brocade IronWare Interface dBm
*
* © 2017 Chris A. Evans <thecityofguanyu@outlook.com>
*
* 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. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
echo 'Caching Brocade IronWare Optics';
$pre_cache['ironware_optic_oids'] = snmpwalk_cache_multi_oid($device, 'snIfOpticalMonitoringInfoTable', [], 'FOUNDRY-SN-SWITCH-GROUP-MIB');

View File

@@ -1,37 +0,0 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2016 Søren Friis Rosiak <sorenrosiak@gmail.com>
* 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. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
$temp = snmpwalk_cache_multi_oid($device, 'snChasPwrSupplyTable', [], 'FOUNDRY-SN-AGENT-MIB');
$cur_oid = '.1.3.6.1.4.1.1991.1.1.1.2.1.1.3.';
if (is_array($temp)) {
//Create State Index
$state_name = 'snChasPwrSupplyOperStatus';
$states = [
['value' => 1, 'generic' => 3, 'graph' => 0, 'descr' => 'other'],
['value' => 2, 'generic' => 0, 'graph' => 0, 'descr' => 'normal'],
['value' => 3, 'generic' => 2, 'graph' => 0, 'descr' => 'failure'],
];
create_state_index($state_name, $states);
foreach ($temp as $index => $entry) {
//Discover Sensors
$descr = $temp[$index]['snChasPwrSupplyDescription'];
if (empty($descr)) {
$descr = "Power Supply " . $index;
}
discover_sensor($valid['sensor'], 'state', $device, $cur_oid.$index, $index, $state_name, $descr, 1, 1, null, null, null, null, $temp[$index]['snChasPwrSupplyOperStatus'], 'snmp', $index);
//Create Sensor To State Index
create_sensor_to_state_index($device, $state_name, $index);
}
}

View File

@@ -1,31 +0,0 @@
<?php
echo 'IronWare ';
$oids = snmp_walk($device, 'snAgentTempSensorDescr', '-Osqn', 'FOUNDRY-SN-AGENT-MIB:FOUNDRY-SN-ROOT-MIB');
$oids = trim($oids);
$oids = str_replace('.1.3.6.1.4.1.1991.1.1.2.13.1.1.3.', '', $oids);
foreach (explode("\n", $oids) as $data) {
$data = trim($data);
if ($data != '') {
list($oid) = explode(' ', $data);
$temperature_oid = ".1.3.6.1.4.1.1991.1.1.2.13.1.1.4.$oid";
$descr_oid = ".1.3.6.1.4.1.1991.1.1.2.13.1.1.3.$oid";
$descr = snmp_get($device, $descr_oid, '-Oqv', '');
$temperature = snmp_get($device, $temperature_oid, '-Oqv', '');
if (!strstr($descr, 'No') && !strstr($temperature, 'No') && $descr != '' && $temperature != '0') {
$descr = str_replace('"', '', $descr);
$descr = str_replace('temperature', '', $descr);
$descr = str_replace('temperature', '', $descr);
$descr = str_replace('sensor', 'Sensor', $descr);
$descr = str_replace('Line module', 'Slot', $descr);
$descr = str_replace('Switch Fabric module', 'Fabric', $descr);
$descr = str_replace('Active management module', 'Mgmt Module', $descr);
$descr = str_replace(' ', ' ', $descr);
$descr = trim($descr);
$current = ($temperature / 2);
discover_sensor($valid['sensor'], 'temperature', $device, $temperature_oid, $oid, 'ironware', $descr, '2', '1', null, null, null, null, $current);
}
}
}

View File

@@ -2528,17 +2528,6 @@ function get_device_oid_limit($device)
return $global_max > 0 ? $global_max : 10;
}
/**
* Strip out non-numeric characters
*/
function return_num($entry)
{
if (!is_numeric($entry)) {
preg_match('/-?\d*\.?\d+/', $entry, $num_response);
return $num_response[0];
}
}
/**
* If Distributed, create a lock, then purge the mysql table
*

View File

@@ -14,6 +14,8 @@ if (\LibreNMS\Config::get('enable_bgp')) {
$peer_data_check = snmpwalk_cache_oid($device, 'aristaBgp4V2PeerRemoteAs', array(), 'ARISTA-BGP4V2-MIB');
} elseif ($device['os'] === 'timos') {
$peer_data_check = snmpwalk_cache_multi_oid($device, 'tBgpInstanceRowStatus', [], 'TIMETRA-BGP-MIB', 'nokia');
} elseif ($device['os_group'] === 'brocade') {
$peer_data_check = snmpwalk_cache_oid($device, 'bgp4V2PeerRemoteAs', array(), 'BGP4V2-MIB', 'brocade', '-ObQ');
} else {
$peer_data_check = snmpwalk_cache_oid($device, 'cbgpPeer2RemoteAs', array(), 'CISCO-BGP4-MIB');
}
@@ -138,6 +140,25 @@ if (\LibreNMS\Config::get('enable_bgp')) {
'aristaBgp4V2PeerInUpdatesElapsedTime' => 'bgpPeerInUpdateElapsedTime',
'aristaBgp4V2PeerLocalAddr' => 'bgpLocalAddr',
);
} elseif ($device['os_group'] === 'brocade') {
if ($ip_type == 2) {
$ip_parts = str_split(str_replace(':', '', $peer['bgpLocalAddr']), 2);
array_walk($ip_parts, function (&$aPart) {
if ($aPart == '00') {
$aPart = '0';
}
$aPart = (int)$aPart;
});
$peer['bgpLocalAddr'] = implode('.', $ip_parts);
}
$peer_identifier = "1.$ip_type.$ip_len.{$peer['bgpLocalAddr']}.$ip_type.$ip_len.$bgp_peer_ident";
$mib = 'BGP4V2-MIB';
$oid_map = array(
'bgp4V2PeerState' => 'bgpPeerState',
'bgp4V2PeerAdminStatus' => 'bgpPeerAdminStatus',
'bgp4V2PeerFsmEstablishedTime' => 'bgpPeerFsmEstablishedTime',
'bgp4V2PeerInUpdatesElapsedTime' => 'bgpPeerInUpdateElapsedTime',
);
} else {
$peer_identifier = $ip_type . '.' . $ip_len . '.' . $bgp_peer_ident;
$mib = 'CISCO-BGP4-MIB';
@@ -261,7 +282,7 @@ if (\LibreNMS\Config::get('enable_bgp')) {
}
// --- Populate cbgp data ---
if ($device['os_group'] == 'vrp' || $device['os_group'] == 'cisco' || $device['os'] == 'junos' || $device['os_group'] === 'arista') {
if ($device['os_group'] == 'vrp' || $device['os_group'] == 'cisco' || $device['os'] == 'junos' || $device['os_group'] === 'arista' || $device['os_group'] === 'brocade') {
// Poll each AFI/SAFI for this peer (using CISCO-BGP4-MIB or BGP4-V2-JUNIPER MIB)
$peer_afis = dbFetchRows('SELECT * FROM bgpPeers_cbgp WHERE `device_id` = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['bgpPeerIdentifier']));
foreach ($peer_afis as $peer_afi) {
@@ -394,12 +415,21 @@ if (\LibreNMS\Config::get('enable_bgp')) {
if ($device['os_group'] === 'vrp') {
$vrpPrefixes = snmpwalk_cache_multi_oid($device, 'hwBgpPeerPrefixRcvCounter', $vrpPrefixes, 'HUAWEI-BGP-VPN-MIB', null, '-OQUs');
$vrpPrefixes = snmpwalk_cache_multi_oid($device, 'hwBgpPeerPrefixAdvCounter', $vrpPrefixes, 'HUAWEI-BGP-VPN-MIB', null, '-OQUs');
$key = '0.'.$afi.'.'.$safi.'.ipv4.'.$peer['bgpPeerIdentifier'];
$cbgpPeerAcceptedPrefixes = $vrpPrefixes[$key]['hwBgpPeerPrefixRcvCounter'];
$cbgpPeerAdvertisedPrefixes = $vrpPrefixes[$key]['hwBgpPeerPrefixAdvCounter'];
}
if ($device['os_group'] === 'brocade') {
if (empty($b_prefixes)) {
$b_prefixes = snmpwalk_cache_multi_oid($device, 'snBgp4NeighborSummaryTable', $b_prefixes, 'FOUNDRY-SN-BGP4-GROUP-MIB', null, '-OQUs');
}
$key = array_search($peer['bgpPeerIdentifier'], array_column($b_prefixes, 'snBgp4NeighborSummaryIp', 'snBgp4NeighborSummaryIndex'), true);
$cbgpPeerAcceptedPrefixes = $key ? $b_prefixes[$key]['snBgp4NeighborSummaryRouteReceived'] : null;
}
// Validate data
$cbgpPeerAcceptedPrefixes = set_numeric($cbgpPeerAcceptedPrefixes);
$cbgpPeerDeniedPrefixes = set_numeric($cbgpPeerDeniedPrefixes);

View File

@@ -25,6 +25,8 @@
namespace LibreNMS\Tests;
use LibreNMS\Device\YamlDiscovery;
class FunctionsTest extends TestCase
{
public function testMacCleanToReadable()
@@ -95,23 +97,23 @@ sdfsd <a href="ftp://192.168.1.1/help/me/now.php">ftp://192.168.1.1/help/me/now.
);
$data = array('value' => 'temp', 'oid' => 'firstdata');
$this->assertNull(dynamic_discovery_get_value('missing', 0, $data, $pre_cache));
$this->assertSame('yar', dynamic_discovery_get_value('default', 0, $data, $pre_cache, 'yar'));
$this->assertSame(2, dynamic_discovery_get_value('value', 1, $data, $pre_cache));
$this->assertNull(YamlDiscovery::getValueFromData('missing', 0, $data, $pre_cache));
$this->assertSame('yar', YamlDiscovery::getValueFromData('default', 0, $data, $pre_cache, 'yar'));
$this->assertSame(2, YamlDiscovery::getValueFromData('value', 1, $data, $pre_cache));
$data = array('oid' => 'high');
$this->assertSame(3, dynamic_discovery_get_value('high', 0, $data, $pre_cache));
$this->assertSame(3, YamlDiscovery::getValueFromData('high', 0, $data, $pre_cache));
$data = array('oid' => 'table');
$this->assertSame(5, dynamic_discovery_get_value('first', 0, $data, $pre_cache));
$this->assertSame(7, dynamic_discovery_get_value('first', 1, $data, $pre_cache));
$this->assertSame(6, dynamic_discovery_get_value('second', 0, $data, $pre_cache));
$this->assertSame(8, dynamic_discovery_get_value('second', 1, $data, $pre_cache));
$this->assertSame(5, YamlDiscovery::getValueFromData('first', 0, $data, $pre_cache));
$this->assertSame(7, YamlDiscovery::getValueFromData('first', 1, $data, $pre_cache));
$this->assertSame(6, YamlDiscovery::getValueFromData('second', 0, $data, $pre_cache));
$this->assertSame(8, YamlDiscovery::getValueFromData('second', 1, $data, $pre_cache));
$this->assertSame(9, dynamic_discovery_get_value('single', 0, $data, $pre_cache));
$this->assertSame(10, dynamic_discovery_get_value('oneoff', 3, $data, $pre_cache));
$this->assertSame('Pickle', dynamic_discovery_get_value('singletable', 11, $data, $pre_cache));
$this->assertSame('BBQ', dynamic_discovery_get_value('doubletable', 13, $data, $pre_cache));
$this->assertSame(9, YamlDiscovery::getValueFromData('single', 0, $data, $pre_cache));
$this->assertSame(10, YamlDiscovery::getValueFromData('oneoff', 3, $data, $pre_cache));
$this->assertSame('Pickle', YamlDiscovery::getValueFromData('singletable', 11, $data, $pre_cache));
$this->assertSame('BBQ', YamlDiscovery::getValueFromData('doubletable', 13, $data, $pre_cache));
}
public function testParseAtTime()

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff