Solved

WAN Interfaces Inventory from NQE query

  • 25 June 2024
  • 7 replies
  • 64 views

Userlevel 1
Badge

Hi Team,

I want to add only admin status up interfaces condition, CDP LLDP neighbor info in below query, please help me on this.

Extra question- 1. any method to shirk the results to only getting WAN interfaces any idea on this.
2. want to add one more column to fetch circuit id details from Interface or Interface description.

NQE Query-
 

pattern_interfaces = ["*WAN *"];

testPatterns(s, p) = 
max (foreach pattern in p
select matches(toLowerCase(s), toLowerCase(pattern)));

foreach device in network.devices
foreach interface in device.interfaces
let platform = device.platform
let ethernet = interface.ethernet
where isPresent(interface.description)
where testPatterns(interface.description, pattern_interfaces)
select {
  test: testPatterns(interface.description, pattern_interfaces),
  deviceName: device.name,
  Location: device.locationName,
  Tags: device.tagNames,
  Vendor: platform.vendor,
  Model: platform.model,
  interfaceName: interface.name,
  negotiatedSpeed: ethernet.negotiatedPortSpeed,
  negotiatedMode: ethernet.negotiatedDuplexMode,
  description: interface.description,
  operStatus: interface.operStatus,
  adminStatus: interface.adminStatus
}

icon

Best answer by GaryB 25 June 2024, 22:01

View original

7 replies

Userlevel 4
Badge

 

Hello @Nand 


When you want to filter on something you use the `where` clause with a boolean outcome e.g. True False. 

Below we evaluate interface.adminStatus == AdminStatus.UP which is an enumeration of interface status.

You can lookup CDP in the data model, you can get an example query to help you see how to retrieve data and add it to the select statement.

 

pattern_interfaces = ["*WAN *"];

testPatterns(s, p) =
max (foreach pattern in p
select matches(toLowerCase(s), toLowerCase(pattern)));

foreach device in network.devices
foreach interface in device.interfaces
let platform = device.platform
let ethernet = interface.ethernet
let cdp = interface.cdp
where interface.adminStatus == AdminStatus.UP
where isPresent(interface.description)
where testPatterns(interface.description, pattern_interfaces)
select {
deviceName: device.name,
Location: device.locationName,
Tags: device.tagNames,
Vendor: platform.vendor,
Model: platform.model,
Neighbors: cdp.neighbors,
interfaceName: interface.name,
negotiatedSpeed: ethernet.negotiatedPortSpeed,
negotiatedMode: ethernet.negotiatedDuplexMode,
description: interface.description,
operStatus: interface.operStatus,
adminStatus: interface.adminStatus
}


Hope that helps.​​​​​​

-g

Userlevel 1
Badge

Thanks @GaryB ,

Any documentation or video link or any course suggest to know more about NQE Query.


Can you also help me out for this-

want to add one more column to fetch circuit id details from Interface or Interface description.

Example- like this.

                       Interface Description                                         Circuit id

WAN - Verizon MPLS VPN:Graw; Site-Circuit: E3003336 | E3003336

Userlevel 3
Badge

@Nand and Inside Forward Enterprised there is an NQE Tutorial.  It is directly under the NQE Library down the left hand menu.  That is a self paced course.  Also at the top of the NQE community page are some “pinned” comments.  There is a set of videos by Mike Lossman that are vey handy.

Userlevel 1
Badge

@Nand and Inside Forward Enterprised there is an NQE Tutorial.  It is directly under the NQE Library down the left hand menu.  That is a self paced course.  Also at the top of the NQE community page are some “pinned” comments.  There is a set of videos by Mike Lossman that are vey handy.

Thanks Henrie

Userlevel 2

Hi @Nand - 

Here are links to the community resources @Tyson Henrie recommended for learning NQE . You can always find them at the top of the NQE space.

 

@Mike ‘s NQE tutorials that cover the fundamentals:

 

And @devecis and @Andreas’s video on writing better queries is a great watch to learn how our NQE experts write queries that are easy to maintain, scale, and troubleshoot. 

 

Dave

Userlevel 4
Badge

@Nand 

 

Here is how you can parse the CircuitID from interface.description

 

interface_description =
"WAN - Verizon MPLS VPN:Graw; Site-Circuit: E3003336 | E3003336";

getCircuitId(intDescr) =
max(foreach x in [0]
let fix = replace(replace(intDescr, " ", "_"), "_|_", " ")
let match = patternMatch(fix, `{descr:string} {circuitId:string}`)
select {
intfDescr: replace(match.descr, "_", " "), circuitId: match.circuitId
});

foreach x in [0]
let match = getCircuitId(interface_description)
select { intfDesc: match.intfDescr, circuitId: match.circuitId }

 

Userlevel 1
Badge

Thank you so much @GaryB  for the resolution. I have upcoming concern related to this data. I have raised another question for this.

Reply