Skip to main content
Question

NQE Query for F5 NTP Server details from config, Please help us to collect this data.

  • Oct 29, 2024 12:35 PM UTC
  • 4 replies
  • 209 views
  • Translate All

Forum|alt.badge.img+2

NQE Query for F5 NTP Server details from config, Please help us to collect this data.

4 replies

StewS64
Employee
  • Employee
  • Oct 29, 2024 3:24 PM UTC

Hi Rohit,

Firstly, what version are you running?

 

Regardless of your version, the collection of NTP configuration will require a custom command. 

For later versions, it looks like the the command for listing the currently defined NTP servers is list /sys ntp servers

However, I prefer the output of ntpq -np which verifies the status of the NTP.

Could you please run both of these commands and show the outputs?

This will help us create the NQE for you.

 

Stewart

Translate

Christopher
Employee
Forum|alt.badge.img+3
  • Employee
  • Oct 29, 2024 4:37 PM UTC

To look at the configured NTP servers, you could use the custom command list sys ntp

and an NQE query like this:

pattern = ```
sys ntp
servers {server1:string} {server2:string}
```;

getServers(device) =
foreach command in device.outputs.commands
where command.commandText == "list sys ntp"
let filtered_response = replace(command.response, "{", "")
let filtered_response = replace(filtered_response, "}", "")
let blocks = parseConfigBlocks(OS.F5, filtered_response)
foreach match in blockMatches(blocks, pattern)
select {server1: match.data.server1, server2: match.data.server2
};

foreach device in network.devices
where device.platform.os == OS.F5
select {
device: device.name,
os: device.platform.os,
server1: max(getServers(device)).server1,
server2: max(getServers(device)).server2

}

 

Translate

Forum|alt.badge.img+2

Now we are collecting the data via Custom command , we are using same query to get the information ,we are getting below error.

 

error - Address the following issues:

  • Line 21, character 14: Cannot select field 'server1' from null value. Consider either replacing '.' with '?.' to return null or using isPresent() to check whether the value is present before selecting a field from the value.
Translate

Christopher
Employee
Forum|alt.badge.img+3
  • Employee
  • Nov 26, 2024 6:08 PM UTC

You can change the code to be 

server1: max(getServers(device))?.server1,
server2: max(getServers(device))?.server2

Adding the “?” allows us to display a result with a null value.

Translate