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

Get host ID using API

gary1024
Frequent Guest

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

7 REPLIES 7

pahofmann
DynaMight Guru
DynaMight Guru

You can use the Monitored Entities Endpoint in the Environment v2 API to get the Host IDs

Dynatrace Certified Master - Dynatrace Partner - 360Performance.net

dannemca
DynaMight Guru
DynaMight Guru

The Hosts API will also do the job.

Site Reliability Engineer @ Kyndryl

gary1024
Frequent Guest

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.

theharithsa
Dynatrace Champion
Dynatrace Champion

Hi @gary1024 

 

You can do this using OneAgent on a host API, 

  • First you need to use, /oneagents API to get the host id (Environment API)
  • Second, you need to use /hosts/{id}/monitoring API to update the monitoringEnabled parameter. (Configuration API)
    • {
        "monitoringEnabled": true,
        "monitoringMode": "FULL_STACK"
      }
Love more, hate less; Technology for all, together we grow.

Fin_Ubels
Dynatrace Champion
Dynatrace Champion

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


gary1024
Frequent Guest

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"

 
 
 

vzd68890
Newcomer_

It is so complicated to find so simple information . It is not user friendly .

Featured Posts