07 Apr 2022
10:10 AM
- last edited on
21 Mar 2025
07:43 AM
by
MaciejNeumann
Hi
I need help to find a way to get hostid using an API. I know hostid can be found on the URL like this:
https://my-domain/e/my-environment/#newhosts/hostdetails;id=HOST-B0363C0D000000000;gtf=-72h%20to%20now;gf=all
However, I need to have a way to query from the OneAgent host itself so that I can use it to trigger enable/disable API from there.
Gary
Solved! Go to Solution.
07 Apr 2022 10:23 AM
You can use the Monitored Entities Endpoint in the Environment v2 API to get the Host IDs
07 Apr 2022 01:07 PM
The Hosts API will also do the job.
08 Apr 2022 03:08 AM
Thanks for the reply. Sorry for not being specific.
A list of HOSTID and other parameters will not help.
My use case is that I need to configure my AWS instance to query the HOSTID of the instance in Dynatrace (by its Instance-ID or detected name) and store it in a variable to be use in the OneAgent enable/disable API.
08 Apr 2022 03:30 AM
Hi @gary1024
You can do this using OneAgent on a host API,
{ "monitoringEnabled": true, "monitoringMode": "FULL_STACK" }
08 Apr 2022 05:17 AM
Hey NKIANKEONG,
Instead of the APIs you could also use the oneagentctl tool to get the HostID of specific hosts. It's bundled with OneAgent when you install it so it will be on every host. So you could set up some system to remotely trigger it to run and then get the response from it.
https://www.dynatrace.com/support/help/shortlink/oneagentctl#host-id
08 Apr 2022 05:46 AM - edited 08 Apr 2022 05:50 AM
Thanks to everyone that contribute to this. Problem solved!
This is the solution:
environment-api/entity-v2/get-entities-list
And this simple API will get me the HOSTID I need:
https://{my-domain}/e/{my-environment}/api/v2/entities?Api-Token={my-token}&entitySelector=type(%22HOST%22),entityName(%22{my-detected-name}%22)
The result:
totalCount: 1
pageSize: 50
entities:
0:
entityId: "HOST-xxxxxxxxxxxxxxx"
displayName: "MicroServices - ip-xx-xxx-xx-xx.aws.men.maxis.com.my"
20 Mar 2025
12:07 PM
- last edited on
21 Mar 2025
07:44 AM
by
MaciejNeumann
Hi. I see that this thread is already closed, but in case someone is useful, it is a good idea to filter only for those hosts that are being monitored (we discard all ESXi discovered in vCenter) and by the way, not return only 50 results and can specify the number we want. This is the call to return the ID of each server, (necessary to use the API) only if it is in “FULL-STACK” and returning 100 results.
url = 'https://{environmentid}.live.dynatrace.com/api/v2/entities?entitySelector=type%28%22HOST%22%29,monitoringMode(%22FULL_STACK%22)&pageSize=100'
In our case we use it to enable or disable by API the monitoring of HOSTs through a python script.
Greetings.
09 Mar 2023 01:02 AM
It is so complicated to find so simple information . It is not user friendly .