Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
amarnathsps
Participant

Filter or fetch single object from show-gateways-and-servers API

Hi,

Is there a solution to filter or fetch single object from show-gateways-and-servers API based on name field or any other similar API?

Our API version is 1.6.1, basically looking for object details + policy details, which can be fetched from show-gateways-and-servers. But I was not able to find a option to filter only one object instead of all objects.

Please help, Thanks in advance.

0 Kudos
6 Replies
_Val_
Admin
Admin

There is "show simple-gateway" command 

0 Kudos
amarnathsps
Participant

We are using 1.6.1 API version and there is no filter option available for this "show-simple-gateway" API, I guess. We need to search using "name" field, the name works only if it is a perfect match.

For example: "Device123_._._Domain" will not be fetched if we are passing "Device123" in name field of "show-simple-gateway" API request. We get this below error,

{
"code" : "generic_err_object_not_found",
"message" : "Requested object [Device123] not found"
}

Also looking for policy details as in show-gateways-and-servers API which seems to be not available in "show-simple-gateway"

0 Kudos
_Val_
Admin
Admin

"show simple-gateway", same for simple-cluster, etc.

Screenshot 2021-07-21 at 13.15.49.png

0 Kudos
Bob_Zimmerman
Authority
Authority

That works if you have the device's exact name, or exact UUID. It doesn't work if you know the device by only part of its name.

I would solve this problem like so:

 

mgmt_cli --format json -r true show gateways-and-servers limit 500 details-level full \
| jq -c '.objects[]|.' \
| egrep "<filter goes here>" \
| xargs -L 1 jq .

 

'details-level full' gives us more information about the object like the comment, which might be useful for filtering. 'limit 500' is as high as that option goes, so the command would need to be repeated with an offset if there are more than 500 gateway-and-server objects.

The `jq -c '.objects[]|.'` splits up the items in the 'objects' list in the original JSON, then prints the whole object in compact form (one full object per line).

You can then filter in any way you want. I've used egrep here, but there are other options. Since the whole object is one line, you just have to return lines which match the desired filter. Easy.

Finally, since the grep may return many lines but jq wants to get a single array or object, I use xargs to carve grep's output and feed it one object at a time to jq for pretty print. You can use a longer jq expression here instead of the . if you only want certain fields of the objects.

0 Kudos
amarnathsps
Participant

Could you please help me with the web services (web_api) equivalent, as cURL or Python sample. Since we are using only web services API and do not access mgmt_cli tool.  

0 Kudos
PhoneBoy
Admin
Admin

mgmt_cli just calls the API the same way you’d call it using the REST API.
The magic is happening in other CLI tools:

  • jq parses/transforms the JSON output.
  • egrep is used to pull out the line you care about.
  • xargs plus jq is turning the output back to a pretty JSON output.

Ultimately, you will have the parse the results of the API programmatically to get the precise result you’re after.

0 Kudos

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events