Forum Discussion

tatmotiv's avatar
tatmotiv
Icon for Cirrostratus rankCirrostratus
Jan 16, 2015

determine type of monitor for REST API call

Hi all.

I need to get the settings (timeout, send string, etc.) for a specific monitor that is bound to a pool and which can basically be of any type. When querying the pool through a REST call, I get for example the following reply:

 {
            "allowNat": "yes",
            "allowSnat": "yes",
            "fullPath": "/Partition-1/testPool2",
            "generation": 9744,
            "ignorePersistedWeight": "disabled",
            "ipTosToClient": "pass-through",
            "ipTosToServer": "pass-through",
            "kind": "tm:ltm:pool:poolstate",
            "linkQosToClient": "pass-through",
            "linkQosToServer": "pass-through",
            "loadBalancingMode": "round-robin",
            "membersReference": {
                "isSubcollection": true,
                "link": "https://localhost/mgmt/tm/ltm/pool/~Partition-1~testPool2/members?ver=11.6.0"
            },
            "minActiveMembers": 0,
            "minUpMembers": 0,
            "minUpMembersAction": "failover",
            "minUpMembersChecking": "disabled",
            "monitor": "/Partition-1/test2",
            "name": "testPool2",
            "partition": "Partition-1",
            "queueDepthLimit": 0,
            "queueOnConnectionLimit": "disabled",
            "queueTimeLimit": 0,
            "reselectTries": 0,
            "selfLink": "https://localhost/mgmt/tm/ltm/pool/~Partition-1~testPool2?ver=11.6.0",
            "serviceDownAction": "none",
            "slowRampTime": 10
        }

Now, I know the monitor name and its partition, but not its type. When trying to query the settings of this specific monitor, I need to provide its type as part of the query path, e.g.: /mgmt/tm/ltm/monitor/http/~Partition-1~test2

Since I do not know its type at that time, my idea was to subsequentially query the most common types of monitors (like http, https, tcp and so on), check the replies for the only one that has returned valid values and derive the monitor type from that. Unexpectedly, the BigIP will answer all of those queries with a valid reply, and will even return the settings, even if the "type" part of the URI is wrong.

For example, when querying an http monitor that is defined as

ltm monitor http test2 {
    adaptive disabled
    defaults-from /Common/http
    destination *:*
    interval 5
    ip-dscp 0
    partition Partition-1
    recv "200 OK"
    send "GET /\r\n"
    time-until-up 0
    timeout 16
}

through the iControl REST API, I get a valid reply even when using the path /mgmt/tm/ltm/monitor/tcp/~Partition-1~test2 ,although it is not a TCP monitor:

{
    "adaptive": "disabled",
    "adaptiveDivergenceType": "relative",
    "adaptiveDivergenceValue": 25,
    "adaptiveLimit": 200,
    "adaptiveSamplingTimespan": 300,
    "defaultsFrom": "/Common/http",
    "destination": "*:*",
    "fullPath": "/Partition-1/test2",
    "generation": 0,
    "interval": 5,
    "ipDscp": 0,
    "kind": "tm:ltm:monitor:tcp:tcpstate",
    "manualResume": "disabled",
    "name": "test2",
    "partition": "Partition-1",
    "recv": "200 OK",
    "reverse": "disabled",
    "selfLink": "https://localhost/mgmt/tm/ltm/monitor/tcp/~Partition-1~test2?ver=11.6.0",
    "send": "GET /\\r\\n",
    "timeUntilUp": 0,
    "timeout": 16,
    "transparent": "disabled",
    "upInterval": 0
}

I don't see any means of getting the type of monitor from those replies besides forcing all admins to include the type in the name, which is not a good solution. I cannot derive the type from the path, nor from the "kind" field, nor from the "defaultsFrom" setting, because that one does not necessarily contain the type (it does in the example above, though).

I suppose this to be a bug. Has anybody run into the same issue and would like to share his/her experience? Any suggestions on how to address that? Many thanks in advance!

7 Replies

  • Ouch. A right pain this one. Can you not query and iterate through all the possible monitor types using

    .../mgmt/tm/ltm/monitor/http
    .../mgmt/tm/ltm/monitor/tcp
    

    and so on? A bore I'm sure but reliable.

  • That's exactly what I was thinking and trying, but it does not work - see paragraph above starting with

     

    "Unexpectedly, the BigIP will answer all of those queries with a valid reply, and will even return the settings, even if the "type" part of the URI is wrong."

     

  • Yes, but if you just query as I stated (not being more specific), http monitors will only be returned using .../mgmt/tm/ltm/monitor/http and so on.

     

  • Ah, OK - I get it now. That's probably a solution, thanks for the hint! I'll see if it is feasible :-)

     

    Do you think the observed behaviour is a bug that will probably be fixed in future releases?

     

  • bonny_11145's avatar
    bonny_11145
    Historic F5 Account

    Hi there,

    Another possible way is to run two queries (I know it's less than efficient, but...):

    • The first is to specify as you did some monitor type. It seems to not make a difference so long as the type is valid. The change is that you add a select filter, so the query becomes:
       curl -s -k -u admin:admin -H "Content-Type: application/json" -X GET https://localhost/mgmt/tm/ltm/monitor/tcp/monitor_name?$select=defaultsFrom

    This query returns the parent monitor you used to create the monitor (assuming this is a custom monitor), which would, in most cases, be the monitor type name as well. For example when I run this, I get:

    {
        "defaultsFrom": "/Common/http"
        }

    • You can construct the proper query using the type obtained above.
  • Patrick_Chang_7's avatar
    Patrick_Chang_7
    Historic F5 Account

    curl -s -k -u admin:admin -H "Content-Type: application/json" -X GET https:///mgm/tm/ltm/monitor will return the list of monitor types. then cycle through each one: curl -s -k -u admin:admin -H "Content-Type: application/json" -X GET https:///mgm/tm/ltm/monitor/ and you will get the list of monitors of each type. Stop when you get the name that matches what you are looking for and then query for that specific one.

     

  • This one creates a little less data in the response and returns just the monitor names:

    curl -s -k -u admin:admin -H "Content-Type: application/json" -X GET https://localhost/mgmt/tm/ltm/monitor/http?\$select=name