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

How to retrieve a key value of metadata item in properties of an entity (openshift container)?

henridb
Guide

Hello all,

 

Retrieving the properties via API for a container instance delivers:

{
  "entityId": "CONTAINER_GROUP_INSTANCE-08E89EB939BF5F49",
  "type": "CONTAINER_GROUP_INSTANCE",
  "displayName": "pega-web-55959b478c-dx8qw",
  "properties": {
    "metadata": [
      {
        "key": "KUBERNETES_NAMESPACE",
        "value": "pega-cm02-dev01"
      },
      {
        "key": "KUBERNETES_FULL_POD_NAME",
        "value": "pega-web-55959b478c-dx8qw"
      },
      {
        "key": "KUBERNETES_BASE_POD_NAME",
        "value": "pega-web-*"
      }
    ]
  }
}

Now I need to check for a text in the KUBERNETES_NAMESPACE value from the metadata in properties to do some auto tagging. What is the syntax for that?

This is as far as we got now: type(CONTAINER_GROUP_INSTANCE),...

 

Regards,

Henri

 

5 REPLIES 5

christoph_wilts
Dynatrace Enthusiast
Dynatrace Enthusiast

Hi Henri,

If you like to filter for metadata from the properties section in the auto-tagging rules, you can use the following entity selector: 

type(CONTAINER_GROUP_INSTANCE), metadata(KUBERNETES_NAMESPACE:<VALUE>) 

You can exchange the <VALUE> with the namespace you want to filter for. I have attached an example for the kube-system namespace:

Screenshot 2022-09-06 at 15.51.34.png

 

Thanks Christoph,

It even works with multiple value pairs:

type(CONTAINER_GROUP_INSTANCE), metadata(KUBERNETES_NAMESPACE:<VALUE>,KUBERNETES_NAMESPACE:<VALUE2>) 

Hi Christoph,
Any clue about which is the syntax if I want all entities where a metadata field has any value instead of a specific value? I'm looking for something like type(CONTAINER_GROUP_INSTANCE), metadata(CLOUD_FOUNDRY_APP_NAME) which works for the majority of key:value fields but does not work for metadata.
In this case, I'm using the /api/v2/entities API

Thanks,
Alaor

Alaor, 

seems this one is EQUALS comparison only, no contains.

Regards,

Henri

Yes Henri is right - it only allows EQUALS at the moment.

The filter is following the Entity Attribute selector: https://www.dynatrace.com/support/help/shortlink/api-entities-v2-selector#attribute

Featured Posts