Skip to main content

Team,

 

i am using below query to get the virtual server name and dst ip from below query , but somehow i am getting 0 result , can anyone please help .

 

-=--------------------

 

pattern01 = ```

Ltm::Virtual Server: {VirtualServer: string}

    |   Availability   : {Availability: string}          

    |   State          : {State: string}            

    |   IP Address     : {Destination: ipv4Address}

    |   Reason         : {Reason: string}

```;

 

foreach device in network.devices

where device.platform.vendor == Vendor.F5

where device.snapshotInfo.result == DeviceSnapshotResult.completed

foreach command in device.outputs.commands

where command.commandType == CommandType.F5_VIRTUAL_SERVER_STATE

let text = command.response

let text = replaceMatches(text, "\n", "\n    ")

let text = replaceMatches(text, "    Ltm::Virtual Server: ", "Ltm::VirtualServer: ")

let parsedCommand = parseConfigBlocks(OS.F5, text)

foreach match in blockMatches(parsedCommand, pattern01)

select {

  device: device.name,

 VirtualServer: match.data.VirtualServer

 

  }

 

@Rohit_809 Kumar It means there is something about your pattern01 that is not matching the actual output.  As a test comment out the last “foreach” and the “VirtualServer” and add “text”.  Look at what the “text” actually looks like.  

Also,  it is good to put the query into a “code block” that way it does not get changed by the Gainsight text editor.

pattern01 =
```
Ltm::Virtual Server: {VirtualServer:string}
| Availability : {Availability:string}
| State : {State:string}
| IP Address : {Destination:ipv4Address}
| Reason : {Reason:string}
```;

foreach device in network.devices
where device.platform.vendor == Vendor.F5
where device.snapshotInfo.result == DeviceSnapshotResult.completed
foreach command in device.outputs.commands
where command.commandType == CommandType.F5_VIRTUAL_SERVER_STATE
let text = command.response
let text = replaceMatches(text, "\n", "\n ")
let text = replaceMatches(text, " Ltm::Virtual Server: ", "Ltm::VirtualServer: ")
let parsedCommand = parseConfigBlocks(OS.F5, text)
//foreach match in blockMatches(parsedCommand, pattern01)
select {
device: device.name,
//VirtualServer: match.data.VirtualServer,
text
}

There may be a version difference.  When I look at this output in one of my customer’s snapshots, the output of the F5_VIRTUAL_SERVER_STATE does not have the | output in front of the Availability, State, IP Address, and Reason.  In fact in the one I see it doesn’t have “IP Address” it has “Destination”. Another thing I notice is the output I have is that the word “Status” is the line above Availability, and it is further to the left.  Also “VirtualServer” had no space in my output. Which means my pattern01 looks like this for my output:

pattern01 =
```
Ltm::VirtualServer: {VirtualServer:string}
Status
Availability {Availability:string}
State {State:string}
Reason {Reason:string}
Destination {Destination:string}
```;

Another test that works is to put that “foreach” behind a “let”, while you are trying to fix this.

pattern01 =
```
Ltm::VirtualServer: {VirtualServer:string}
Status
Availability {Availability:string}
State {State:string}
Reason {Reason:string}
Destination {Destination:string}
```;

foreach device in network.devices
where device.platform.vendor == Vendor.F5
where device.snapshotInfo.result == DeviceSnapshotResult.completed
foreach command in device.outputs.commands
where command.commandType == CommandType.F5_VIRTUAL_SERVER_STATE
let text = command.response
let text = replaceMatches(text, "\n", "\n ")
let text = replaceMatches(text, " Ltm::Virtual Server: ", "Ltm::VirtualServer: ")
let parsedCommand = parseConfigBlocks(OS.F5, text)
let match = (foreach match in blockMatches(parsedCommand, pattern01) select match)
select {
device: device.name,
match,
//VirtualServer: match.data.VirtualServer,
text
}

Notice that I put “let match =” in front of the “foreach”.  Because it is a “let” it does not work as a filter.  The “foreach” actually works like a filter, because only things that match the foreach statement get to pass further along in the query.  The “let” says that it is okay whether you match or don’t match.  This is helpful for troubleshooting.  Once you get the pattern01 working correctly then I would remove the “let match =” and go back to what you had before.


this pattern and version of NQE working as i want , but somehow the whole output i can see in test coloum, but i want some specifc details like virtual server name , dst ip and avaliability .


@Rohit_809 Kumar My apologies.  I was trying to say that the “text” column and he “match” column were temporary columns.  They are there for the troubleshooting.  If you are only seeing data in the “text” column, but not in the “match” column, then it means you “pattern01” is not working yet.

You need to keep adjusting you “pattern01” until you receive output in the “match” column.  Once you see output in the “match” column.  Then you are ready to take the final step and remove the “let match” and go back to that being just a “foreach” statement.  Then you can put the data you want into other columns.

This is what the query looks like when you are troubleshooting.

pattern01 =
```
Ltm::VirtualServer: {VirtualServer:string}
Status
Availability : {Availability:string}
State : {State:string}
Reason : {Reason:(string*)}
Destination : {Destination:string}
```;

foreach device in network.devices
where device.platform.vendor == Vendor.F5
where device.snapshotInfo.result == DeviceSnapshotResult.completed
foreach command in device.outputs.commands
where command.commandType == CommandType.F5_VIRTUAL_SERVER_STATE
let text = command.response
let text = replaceMatches(text, "\n", "\n ")
let text = replaceMatches(text, " Ltm::Virtual Server: ", "Ltm::VirtualServer: ")
let parsedCommand = parseConfigBlocks(OS.F5, text)
let match = (foreach match in blockMatches(parsedCommand, pattern01) select match) // this line is temporary for troubleshooting
// foreach match in blockMatches(parsedCommand, pattern01) // commented out for troubleshooting
select {
device: device.name,
match, // temporary for troubleshooting
text, // temporary for troubleshooting
/* Uncomment the following lines after you get the match working
* And after you comment out the "let match" line in the body of the query
VirtualServer: match.data.VirtualServer,
Availability: match.data.Availability,
State: match.data.State,
Reason: join(" ", match.data.Reason),
"IP Address": match.data.Destination
*/
}

This is what it would look like when you think your “pattern01” is correct.

pattern01 =
```
Ltm::VirtualServer: {VirtualServer:string}
Status
Availability : {Availability:string}
State : {State:string}
Reason : {Reason:(string*)}
Destination : {Destination:string}
```;

foreach device in network.devices
where device.platform.vendor == Vendor.F5
where device.snapshotInfo.result == DeviceSnapshotResult.completed
foreach command in device.outputs.commands
where command.commandType == CommandType.F5_VIRTUAL_SERVER_STATE
let text = command.response
let text = replaceMatches(text, "\n", "\n ")
let text = replaceMatches(text, " Ltm::Virtual Server: ", "Ltm::VirtualServer: ")
let parsedCommand = parseConfigBlocks(OS.F5, text)
// let match = (foreach match in blockMatches(parsedCommand, pattern01) select match) // this line is temporary for troubleshooting
foreach match in blockMatches(parsedCommand, pattern01) // commented out for troubleshooting
select {
device: device.name,
// match, // temporary for troubleshooting
// text, // temporary for troubleshooting
/* Uncomment the following lines after you get the match working
* And after you comment out the "let match" line in the body of the query */
VirtualServer: match.data.VirtualServer,
Availability: match.data.Availability,
State: match.data.State,
Reason: join(" ", match.data.Reason),
"IP Address": match.data.Destination
/* */
}

Then this would hopefully be the final product after you take out the lines you used for troubleshooting.

pattern01 =
```
Ltm::VirtualServer: {VirtualServer:string}
Status
Availability : {Availability:string}
State : {State:string}
Reason : {Reason:(string*)}
Destination : {Destination:string}
```;

foreach device in network.devices
where device.platform.vendor == Vendor.F5
where device.snapshotInfo.result == DeviceSnapshotResult.completed
foreach command in device.outputs.commands
where command.commandType == CommandType.F5_VIRTUAL_SERVER_STATE
let text = command.response
let text = replaceMatches(text, "\n", "\n ")
let text = replaceMatches(text, " Ltm::Virtual Server: ", "Ltm::VirtualServer: ")
let parsedCommand = parseConfigBlocks(OS.F5, text)
foreach match in blockMatches(parsedCommand, pattern01)
select {
device: device.name,
VirtualServer: match.data.VirtualServer,
Availability: match.data.Availability,
State: match.data.State,
Reason: join(" ", match.data.Reason),
"IP Address": match.data.Destination
}

I hope this helps.


Reply