I provided a query for doing this some time ago. However, it was written for running where the Data Model did not have as many BGP elements as the current Data Model. Now that there are more BGP elements in the data model it makes this query much simpler. Which also means it runs faster.
The inspiration for this query was a customer that run BGP between pretty much all devices. This is why it is only based on BGP peers.
/**
* @intent Input the device under maintenance. get the list of BGP peers and outbound interfaces
* @description This is a Parameterized Query. You input the devicename string.
* it will look for the BGP peers of that devices, plus determine the interfaces that connect the
* devices together. This way you can mute the alarms for the BGP peers and links before a maintenance window.
*/
import "@fwd/L3/Interface Utilities"; //getL3Interfaces(device: Device)
getPeerInfo(neighbor, sourceRouterId) =
max(foreach device in network.devices
where device.name == neighbor.peerDeviceName
let l3IfaceList = getL3Interfaces(device)
foreach networkInstance in device.networkInstances
foreach protocol in networkInstance.protocols
where isPresent(protocol.bgp)
let bgp = protocol.bgp
foreach neighbor in bgp.neighbors
where neighbor.peerRouterId == sourceRouterId
let outIface = max(foreach l3Iface in l3IfaceList
foreach address in l3Iface.ipv4.addresses
where neighbor.neighborAddress in
ipSubnet(address.ip, address.prefixLength)
select l3Iface)
select outIface);
@query
findPeers(deviceUnderMaintenance: String) =
foreach device in network.devices
where toLowerCase(device.name) == toLowerCase(deviceUnderMaintenance)
let l3IfaceList = getL3Interfaces(device)
foreach networkInstance in device.networkInstances
foreach protocol in networkInstance.protocols
where isPresent(protocol.bgp)
let bgp = protocol.bgp
foreach neighbor in bgp.neighbors
let peerInfo = getPeerInfo(neighbor, bgp.routerId)
let outIface = max(foreach l3Iface in l3IfaceList
foreach address in l3Iface.ipv4.addresses
where neighbor.neighborAddress in
ipSubnet(address.ip, address.prefixLength)
select l3Iface)
select {
deviceUnderMaintenance: deviceUnderMaintenance,
networkInstanceName: networkInstance.name,
neighborNeighborAddress: neighbor.neighborAddress,
"outbound Interface": outIface.name,
peerDeviceName: neighbor.peerDeviceName,
peerVrf: neighbor.peerVrf,
peerRouterId: neighbor.peerRouterId,
"peer outbound Interface": peerInfo.name,
sessionState: neighbor.sessionState,
enabled: neighbor.enabled,
description: neighbor.description,
peerAS: neighbor.peerAS,
localAS: bgp.asNumber,
peerType: neighbor.peerType
};