cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

API to pull all host group ID's

lee_rovner
Contributor

I am trying to pull in ALL my hostgroup ID's from the DT API.

It used to work using 

https:// xxxxxlive.dynatrace.com/api/v1/entity/infrastructure/hosts?tag=ds%3Aprod&showMonitoringCandidates=false&includeDetails=true

now, I am getting blank hostGroups
5 REPLIES 5

axel_ayala
Dynatrace Advisor
Dynatrace Advisor

You can try using the Monitored Entities API, using the entity type HOST_GROUP should give you what you are looking for:

/api/v2/entities?entitySelector=type%28%22host_group%22%29

 

Hi Axel,

There appears to be a bug in this API, when issuing a nextPageKey parameter is throws an exception

{
  "error": {
    "code": 400,
    "message": "Constraints violated.",
    "constraintViolations": [
      {
        "path": "entitySelector",
        "message": "must not be used in combination with nextPageKey query parameter.",
        "parameterLocation": "QUERY",
        "location": null
      },
      {
        "path": "pageSize",
        "message": "must not be used in combination with nextPageKey query parameter.",
        "parameterLocation": "QUERY",
        "location": null
      }
    ]
  }
}

You must remove ALL parameters before using the nextPageKey or you will get the errors you show here. 

This is very useful information and I was able to get the list of host groups using the API.  The only question I have is how do I associate these host_groups to the hosts themselves?  I don't see a shared host Id/host group id, or at least know how to properly format the URL to pull both information together to allow me to view what host groups are associated to a given host.

I dont think the Host group monitored API information gives you that, unfortunately you would need a second call for hosts, and that info is part of the available properties:

/api/v2/entities?entitySelector=type("host")&fields=properties.hostgroupname

 

Featured Posts