07 Apr 2022 10:10 AM - last edited on 21 Aug 2024 08:55 AM by Michal_Gebacki
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"
09 Mar 2023 01:02 AM
It is so complicated to find so simple information . It is not user friendly .