cancel
Showing results for 
Search instead for 
Did you mean: 

How to use rest api to get the "Availability" attribute value of virtual server member without knowing its pool name

kartal
Altostratus
Altostratus

Hello,

How can I reach pool member availability property by using rest API calling with member IP?

I discover that if I call with pool name I can reach member availability but I want to access this value without using pool name since in the query phase I will not have pool name.

 

In current situation : I tried /mgmt/tm/ltm/node/~PROD~(member_ip) but this gives me pool availability

 

0691T00000C2Wj0QAF.png 

Desired : /mgmt/tm/ltm/pool/~PROD~(pool_name)/members/~PROD~(member_ip) gives me member availability property in session key, but I need pool_name.

 

 

0691T00000C2Wj1QAF.png 

Thanks.

1 ACCEPTED SOLUTION

Hello Kartal.

 

To get the state of one member only using their IP, you need to use 'jq'.

# curl -sku admin https://localhost/mgmt/tm/ltm/pool?expandSubcollections=true | jq '.items[] | select(.membersReference.items[].address == "10.100.40.112") | .membersReference.items[].state' "down"

In my case, I have one pool called P-WEB112_80 which has one member node with IP 10.100.40.112.

# tmsh list ltm pool P-WEB112_80 ltm pool P-WEB112_80 { members { N-WEB112:http { address 10.100.40.112 session monitor-enabled state down } } monitor gateway_icmp }

This solves what you are requesting, but take into account that if this member is applied to more than one pool, you will see in the output "up" "up" or "down" "down" without any information about the pool, so in this case, you could use something like this.

# curl -sku admin https://localhost/mgmt/tm/ltm/pool?expandSubcollections=true | jq '.items[] | select(.membersReference.items[].address == "10.100.40.111") | .name, .membersReference.items[].state' "P-REPO_8080" "up" "P-WEB111_80" "up"

If you need to collect any other field (like 'session'), you can extend the previous expression accordingly.

 

Regards,

Dario.

 

 

Regards,
Dario.

View solution in original post

8 REPLIES 8

Hi there

You believe you have to fetch all pools including subCollections and filter the result

 

Example:

curl -sku admin:admin https://bigip-01.domain.com/mgmt/tm/ltm/pool?expandSubcollections=true

Worth noting:

 

  • There are guides on filtering using $select but I've yet to encounter one that filters subcollections. You can have a look at this article or check out the documentation for OData which F5 used for this API implementation (both linked inline in this sentence). I am not sure if they have full support for OData though so keep that in mind.
  • The call to the REST API above is very heavy so if you might want to avoid it if doing it often or to a device with many pools without using some kind of caching proxy.

 

Kind regards,

Patrik

Hello Kartal.

 

To get the state of one member only using their IP, you need to use 'jq'.

# curl -sku admin https://localhost/mgmt/tm/ltm/pool?expandSubcollections=true | jq '.items[] | select(.membersReference.items[].address == "10.100.40.112") | .membersReference.items[].state' "down"

In my case, I have one pool called P-WEB112_80 which has one member node with IP 10.100.40.112.

# tmsh list ltm pool P-WEB112_80 ltm pool P-WEB112_80 { members { N-WEB112:http { address 10.100.40.112 session monitor-enabled state down } } monitor gateway_icmp }

This solves what you are requesting, but take into account that if this member is applied to more than one pool, you will see in the output "up" "up" or "down" "down" without any information about the pool, so in this case, you could use something like this.

# curl -sku admin https://localhost/mgmt/tm/ltm/pool?expandSubcollections=true | jq '.items[] | select(.membersReference.items[].address == "10.100.40.111") | .name, .membersReference.items[].state' "P-REPO_8080" "up" "P-WEB111_80" "up"

If you need to collect any other field (like 'session'), you can extend the previous expression accordingly.

 

Regards,

Dario.

 

 

Regards,
Dario.

Dear Dario, thank you for your detailed answer. I have one more small question: I am trying to reach F5 IP from outside and in the curl command I am taking curl: (35) schannel: SNI or certificate check failed: SEC_E_WRONG_PRINCIPAL (0x80090322) error. I also tried with -s but that time nothing returned. Can you give me an idea about it?

 

 

Use:

curl -k https://...

Regards,

Dario.

Regards,
Dario.

Thank you, I dont want to bore you with my questions but I got error about IP:

jq: error: Invalid numeric literal at EOF at line 1, column 12 (while parsing '10.192.40.112'). I tried as you typed "10.192.40.112" and also in [] but doesn't solved. Is my case not-quite-valid JSON?

Hello Kartal.

 

I don't know exactly what your error means. I've executed the above lines in my enviroment without issue.

 

I recommend you to run the command partially trying to figure out what specific part triggers the error.

## 1 curl -sku admin https://localhost/mgmt/tm/ltm/pool?expandSubcollections=true | jq   ## 2 curl -sku admin https://localhost/mgmt/tm/ltm/pool?expandSubcollections=true | jq '.items[]'   ## 3 curl -sku admin https://localhost/mgmt/tm/ltm/pool?expandSubcollections=true | jq '.items[] | select(.membersReference.items[].address == "10.100.40.111")'   ## 4 curl -sku admin https://localhost/mgmt/tm/ltm/pool?expandSubcollections=true | jq '.items[] | select(.membersReference.items[].address == "10.100.40.111") | .name, .membersReference.items[].state'

Other point, before moving to a remote device, try to execute this lines in the BIG-IP. That will give a clue if this error appears everywhere or just in one specific device.

 

Finally, besides the error, it's good to include which lines you are executing (pasting them here). This will give me more info about if this could be caused by a syntax error.

 

Hope this helps.

 

Regards,

Dario.

Regards,
Dario.

Dear Dario,

Thanks for your reply,

Step 1 and 2 works fine but at step 3 I got error:

 

curl -s -k -u user:password https://10.197.xx.xx/mgmt/tm/ltm/pool?expandSubcollections=true | .\jq '.items[] | select(.membersReference.items[].address == "10.192.xx.xx")'

 

jq: error: Invalid numeric literal at EOF at line 1, column 12 (while parsing '10.192.xx.xx') at <top-level>, line 1:

.items[] | select(.membersReference.items[].address == 10.192.xx.xx)

jq: 1 compile error

 

Currently, I am trying from a remote device.

 

Regards.

Hello Kartal

It seems a problem with your jq implementation.

Check these out.

https://stackoverflow.com/questions/44985737/invalid-numeric-literal-with-jq

https://unix.stackexchange.com/questions/599900/curl-jq-get-value-from-field-name

I recommend you to search for a solucion on google, because it's a client side error (not related with F5).

Regards,

Dario.

Regards,
Dario.