For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

Gouri's avatar
Gouri
Icon for Nimbostratus rankNimbostratus
Jun 29, 2016

Direct URIs for iControlREST calls

I am a newbie and was trying to get my feet wet with REST calls. As such, I am writing (rather attempting to write) a simple call which will get me the serial and the installed version from a LTM. I am using the path "/mgmt/tm/sys/hardware/?expandSubcollections=true". However the resulting json is huge with quite a few nesting & is quite overwhelming. Is there a shorter or direct URI I should be using ?

 

2 Replies

  • Try omitting the ?expandSubcollections=True. Cannot try it out at the moment, but I think the serial should be included in the json even without the subcollections. If not, find the subcollection that includes the serial and call that subcollection directly by using the selflink contained within.

     

  • If you are trying to get the serial number out of the JSON output you can simply walk through the nested JSON until you get to what you're looking for.

    Example for Serial Number path

    ["entries"]["https://localhost/mgmt/tm/sys/hardware/system-info"]["nestedStats"]["entries"]["https://localhost/mgmt/tm/sys/hardware/system-info/0"]["nestedStats"]["entries"]["bigipChassisSerialNum"]["description"]
    

    So in python 2.7 using requests it would look like this

    import json
    import requests
    from requests.packages.urllib3.exceptions import InsecureRequestWarning
    requests.packages.urllib3.disable_warnings(InsecureRequestWarning) Fixes certificate warning BS
    
    def GetSerial(URI):
        request = requests.session()
        request.auth = ('USERNAME' , 'PASSWORD')
        request.verify = False
        request.headers.update({'Content-Type':'application/json'})
        response = request.get(URI)
        data = response.json()
    
        parse the JSON output for the Serial Number
        print (data["entries"]["https://localhost/mgmt/tm/sys/hardware/system-info"]["nestedStats"]["entries"]["https://localhost/mgmt/tm/sys/hardware/system-info/0"]["nestedStats"]["entries"]["bigipChassisSerialNum"]["description"])
    
    
    uri = 'https://X.X.X.X/mgmt/tm/sys/hardware'
    GetSerial(uri)