# Tagging services running on hosts with specific tag

**URL:** <https://community.dynatrace.com/t/tagging-services-running-on-hosts-with-specific-tag/43813>\
**Category:** Cloud platforms\
**Tags:** aws, management-zones, tagging\
**Created:** [January 24, 2024, 7:18pm UTC](https://community.dynatrace.com/t/tagging-services-running-on-hosts-with-specific-tag/43813 "2024-01-24T19:18:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ccb-cloud](https://avatars.discourse-cdn.com/v4/letter/c/258eb7/32.png) [@ccb-cloud](https://community.dynatrace.com/u/ccb-cloud)\
**Post date:** [January 24, 2024, 7:18pm UTC](https://community.dynatrace.com/t/tagging-services-running-on-hosts-with-specific-tag/43813/1 "2024-01-24T19:18:42Z")

</div>

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:

```markup
{
    "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:

```markup
{
    "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

```markup
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.&nbsp;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

```python
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](https://global.discourse-cdn.com/dynatrace/original/2X/2/2a4fe6dc35f2fdcebe0e4ba04dac845c334e8669.png)

 ![ccbcloud_1-1706123554020.png](https://global.discourse-cdn.com/dynatrace/original/2X/2/2a4fe6dc35f2fdcebe0e4ba04dac845c334e8669.png)

---

<div class="post-metadata">

**Author:** ![Eric\_Yu](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/eric_yu/32/20360_2.png) [@Eric\_Yu](https://community.dynatrace.com/u/Eric_Yu)\
**Post date:** [January 26, 2024, 3:55pm UTC](https://community.dynatrace.com/t/tagging-services-running-on-hosts-with-specific-tag/43813/2 "2024-01-26T15:55:43Z")

</div>

The fromRelationship property you are looking for should be “runsOnHost”

 ![Eric_Yu_0-1706284422343.png](https://global.discourse-cdn.com/dynatrace/original/2X/e/ef3376c0e5453ddc1b124f6d8e30a1fea270d7bd.png)

For your example, something like this should work:

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

```

---

<div class="post-metadata">

**Author:** ![sujit\_k\_singh](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@sujit\_k\_singh](https://community.dynatrace.com/u/sujit_k_singh)\
**Post date:** [March 18, 2024, 2:41am UTC](https://community.dynatrace.com/t/tagging-services-running-on-hosts-with-specific-tag/43813/3 "2024-03-18T02:41:09Z")

</div>

[@Eric\_Yu](https://community.dynatrace.com/user/54474)&nbsp;Where i can see these properties as this will help us lot if&nbsp; we can get details like this?

---

<div class="post-metadata">

**Author:** ![paulo\_calaxa](https://avatars.discourse-cdn.com/v4/letter/p/9e8a1a/32.png) [@paulo\_calaxa](https://community.dynatrace.com/u/paulo_calaxa)\
**Post date:** [March 18, 2024, 11:20am UTC](https://community.dynatrace.com/t/tagging-services-running-on-hosts-with-specific-tag/43813/4 "2024-03-18T11:20:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Eric\_Yu](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/eric_yu/32/20360_2.png) [@Eric\_Yu](https://community.dynatrace.com/u/Eric_Yu)\
**Post date:** [March 18, 2024, 10:50pm UTC](https://community.dynatrace.com/t/tagging-services-running-on-hosts-with-specific-tag/43813/5 "2024-03-18T22:50:55Z")

</div>

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:

> **[Monitored entities API - GET entity type](https://docs.dynatrace.com/docs/dynatrace-api/environment-api/entity-v2/get-entity-type)**
>
> View the details of a monitored entity type via Dynatrace API.

 ![Eric_Yu_0-1710802179955.png](https://global.discourse-cdn.com/dynatrace/original/2X/0/03754d1e71276940f6c0adfda42d618e3473c72b.png)

You can get also get a full list of entities in your environment if you’re curious:

> **[Monitored entities API - GET all entity types](https://docs.dynatrace.com/docs/dynatrace-api/environment-api/entity-v2/get-all-entity-types)**
>
> View all types of monitored entities in your environment via Dynatrace API.

---

<div class="post-metadata">

**Author:** ![sujit\_k\_singh](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@sujit\_k\_singh](https://community.dynatrace.com/u/sujit_k_singh)\
**Post date:** [March 29, 2024, 7:00am UTC](https://community.dynatrace.com/t/tagging-services-running-on-hosts-with-specific-tag/43813/6 "2024-03-29T07:00:16Z")

</div>

[@Eric\_Yu](https://community.dynatrace.com/user/54474)&nbsp;[@paulo\_calaxa](https://community.dynatrace.com/user/7432)&nbsp;Thanks for for your help, both solution works perfectly.

---

<div class="post-metadata">

**Author:** ![Aurel](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/aurel/32/34246_2.png) [@Aurel](https://community.dynatrace.com/u/Aurel)\
**Post date:** [July 31, 2024, 12:23pm UTC](https://community.dynatrace.com/t/tagging-services-running-on-hosts-with-specific-tag/43813/7 "2024-07-31T12:23:03Z")

</div>

Thank you so much for this tips!&nbsp;I have been looking for a solution for almost two weeks
