Forum Discussion

robson_78577's avatar
robson_78577
Icon for Nimbostratus rankNimbostratus
Jun 14, 2017

How to Get FailOver Status via iControl REST?

Hi Guys,

I´m playing with some REST calls, and I would like to get a specific information from a GET request. In the example:

GET , I got the following response:

{
    "kind": "tm:cm:failover-status:failover-statusstats",
    "selfLink": "[https://localhost/mgmt/tm/cm/failover-status?ver=12.1.2"](https://localhost/mgmt/tm/cm/failover-status?ver=12.1.2);,
    "entries": {
        "[https://localhost/mgmt/tm/cm/failover-status/0"](https://localhost/mgmt/tm/cm/failover-status/0);: {
            "nestedStats": {
                "entries": {
                    "color": {
                        "description": "green"
                    },
                    "[https://localhost/mgmt/tm/cm/failoverStatus/0/details"](https://localhost/mgmt/tm/cm/failoverStatus/0/details);: {
                        "nestedStats": {
                            "entries": {
                                "[https://localhost/mgmt/tm/cm/failoverStatus/0/details/0"](https://localhost/mgmt/tm/cm/failoverStatus/0/details/0);: {
                                    "nestedStats": {
                                        "entries": {
                                            "details": {
                                                "description": "active for /Common/traffic-group-1"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "status": {
                        "description": "ACTIVE"
                    },
                    "summary": {
                        "description": "1/1 active"
                    }
                }
            }
        }
    }
}

Is it possible to use query parameters to get a specific response? In the example above, I would only like to receive the appliance status (description": "ACTIVE"). I was trying to work with $filter and $select parameter but no success.

Plus, if someone could give me one example of each parameter, it would be great.

4 Replies

  • you can use this uri : /mgmt/tm/cm/failover-status?$select=status

    but you will still have a nested response.

    {
        "entries": {
            "https://localhost/mgmt/tm/cm/failover-status/0": {
                "nestedStats": {
                    "entries": {
                        "status": {
                            "description": "ACTIVE"
                        }
                    }
                }
            }
        }
    }
    
  • To answer your follow-up question:

    This is just how the rest API works. You have to do some client side manipulation to get the actual data.

    Here's an example in Powershell:

    $Response = (Invoke-WebRequest -Method "GET" -Headers $headers -Uri "https://mydevice.j.local/mgmt/tm/cm/failover-status?`$select=status").content | ConvertFrom-Json
    $content.entries.'https://localhost/mgmt/tm/cm/failover-status/0'.nestedStats.entries.status.description
    

    /Patrik

    • Chimy's avatar
      Chimy
      Icon for Nimbostratus rankNimbostratus

      Hello Patric_Jonsson

      I use your example in powershell but and error appear

      I tried to fix, but there are something that is missed.

      Could you re-check the code?

      I think that point of view to perform the task to know if the device is active/standby is pretty cool 🙂

       


      PS C:\Windows\system32> $Response = (Invoke-WebRequest -Method "GET" -Headers $headers -Uri "https://$f5/mgmt/tm/cm/failover-status?`$select=status").content | ConvertFrom-Json $content.entries.'https://localhost/mgmt/tm/cm/failover-status/0'.nestedStats.entries.status.description

      ConvertFrom-Json : Cannot bind argument to parameter 'InputObject' because it is null.
      At line:1 char:154
      + ... rtFrom-Json $content.entries.'https://localhost/mgmt/tm/cm/failover-s ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidData: (:) [ConvertFrom-Json], ParameterBindingValidationException
      + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ConvertFromJsonCommand