24 Jan 2024 07:18 PM
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))
type(SERVICE),fromRelationships.runsOn(type(HOST).tags(Environment))
but no success at all. Could someone guide me on how to achieve this?
Solved! Go to Solution.
26 Jan 2024 03:55 PM
The fromRelationship property you are looking for should be "runsOnHost"
For your example, something like this should work:
type(SERVICE),fromRelationship.runsOnHost(type(HOST),tag(Environment))
18 Mar 2024 02:41 AM
@Eric_Yu Where i can see these properties as this will help us lot if we can get details like this?
18 Mar 2024 11:20 AM
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
18 Mar 2024 10:50 PM
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
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
29 Mar 2024 07:00 AM
@Eric_Yu @paulo_calaxa Thanks for for your help, both solution works perfectly.
31 Jul 2024 01:23 PM
Thank you so much for this tips! I have been looking for a solution for almost two weeks