Skip to main content
Tutorial

NQE Foreach and Where Statements

  • 19 December 2023
  • 0 replies
  • 83 views

In today's video I will introduce the NQE foreach and where statements. We explore the data model and how to start off your NQE queries as well as go into when and why you would want to use a where statement.

Code examples used in video

Return all IPsec tunnels and create a report of the peer IP address, interface status and operational status

foreach device in network.devices
foreach interface in device.interfaces
where interface.interfaceType == IfaceType.IF_TUNNEL_IPSEC
select {
deviceName: device.name,
tunnelName: interface.name,
peerIP: interface.tunnel.dst,
adminStatus: interface.adminStatus,
operStatus: interface.operStatus
}

You could modify the above to violate if the administrative status is up but the operational status not up with the following NQE query:

foreach device in network.devices
foreach interface in device.interfaces
where interface.interfaceType == IfaceType.IF_TUNNEL_IPSEC
select {
deviceName: device.name,
tunnelName: interface.name,
peerIP: interface.tunnel.dst,
violation: interface.adminStatus == AdminStatus.UP &&
interface.operStatus != OperStatus.UP
}

Let us know in the comments below 👇🏻 what you found in your network using NQE that you couldn't get before.

Be the first to reply!

Reply