Skip to main content
Beginner

NQE Foreach and Where Statements

  • December 19, 2023
  • 0 replies
  • 151 views
  • Translate

Mike
Community Manager
  • Community Manager
  • 1 reply

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.

Did this topic help you find an answer to your question?

0 replies

Be the first to reply!

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings