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

Tagging services running on hosts with specific tag

ccb-cloud
Frequent Guest

I'm trying to separate data from different AWS accounts with Management Zones, so the best solution I found was to automatically tag all the hosts, processes and services that are in, let's say Account A. I already tagged all the Hosts and underlying processes with the tag Environment = stg. However I'm struggling when trying to tag all the Services that run on those EC2 instances. I've been exploring the API querying a single Service I got something as the following:

 

{
    "entityId": "SERVICE-ABCD123",
    "type": "SERVICE",
    "displayName": "MyService",
    "firstSeenTms": 1702652961186,
    "lastSeenTms": 1706119883592,
    "properties": {
      "serviceType": "WEB_SERVICE",
(...)
    },
    "tags": [],
    "managementZones": [],
    "icon": {
      "primaryIconType": "web-sphere"
    },
    "fromRelationships": {
      "calls": [
        {
          "id": "SERVICE-DCBA321",
          "type": "SERVICE"
        }
      ],
      "runsOnHost": [
        {
          "id": "HOST-XYZ123",
          "type": "HOST"
        }
      ]
(...)
    }
}

 

 And regarding the Host is something like this:

 

{
    "entityId": "HOST-XYZ123",
    "type": "HOST",
    "displayName": "MyHost.mydomain.org.me",
    "firstSeenTms": 1702564195134,
    "lastSeenTms": 1706119645611,
    "properties": {
      "bitness": "64",
      "installerTrackedDownload": false,
      "autoInjection": "ENABLED",
      "additionalSystemInfo": [
        {
          "value": "Amazon EC2",
          "key": "system.vendor"
        },
(...)
      ],
      "monitoringMode": "FULL_STACK",
      "osArchitecture": "X86",
      "osVersion": "Red Hat Enterprise Linux 8.9 (Ootpa) (kernel 4.18.0-513.9.1.el8_9.x86_64)",
      "installerPotentialProblem": false,
      "cloudType": "EC2",
      "macAddresses": [
        "12:37:37:2D:68:AB"
      ],
      "osType": "LINUX",
      "state": "RUNNING",
(...)
      "installerSupportAlert": false
    },
    "tags": [
      {
        "context": "CONTEXTLESS",
        "key": "Environment",
        "value": "stg",
        "stringRepresentation": "Environment:stg"
      }
    ],
    "managementZones": [],
}

 

(I ommited non-relevant info with (...))

Following my logic it should be something like 

 

type(SERVICE),fromRelationships.runsOn(type(HOST).tags(Environment=stg))

 

Since "tags" is at the same level as type in the json. I'm not completely sure about the "=" sign to show which values of that tag I'm interested in. However, the Entity Selector doesn't seem to understand what I'm trying to query since it doesn't understand the ".tags" part.
I've tried with 

 

type(SERVICE),fromRelationships.runsOn(type(HOST).tags(Environment))​

 

but no success at all. Could someone guide me on how to achieve this?

ccbcloud_1-1706123554020.png

 

ccbcloud_0-1706123529666.png

 

5 REPLIES 5

Eric_Yu
Dynatrace Advisor
Dynatrace Advisor

The fromRelationship property you are looking for should be "runsOnHost"

Eric_Yu_0-1706284422343.png
For your example, something like this should work:

type(SERVICE),fromRelationship.runsOnHost(type(HOST),tag(Environment))

 

Eric Yu

@Eric_Yu Where i can see these properties as this will help us lot if  we can get details like this?

Dynatrace Professional Certified

Hi.
Make a call to the Entity types endpoint
api/v2/entityTypes?type=SERVICE
and set type parameter to whatever you need: SERVICE, HOST, etc.

Best regards

Eric_Yu
Dynatrace Advisor
Dynatrace Advisor

Hi, glad you found it useful.

As Paulo mentioned, you can get a list of properties of any entity type by calling the GET entity type API:
https://docs.dynatrace.com/docs/dynatrace-api/environment-api/entity-v2/get-entity-type

Eric_Yu_0-1710802179955.png

You can get also get a full list of entities in your environment if you're curious:
https://docs.dynatrace.com/docs/shortlink/api-entities-v2-get-all-entity-types

Eric Yu

@Eric_Yu @paulo_calaxa Thanks for for your help, both solution works perfectly. 

Dynatrace Professional Certified

Featured Posts