# Get Host Name in Open Events

**URL:** <https://community.dynatrace.com/t/get-host-name-in-open-events/42888>\
**Category:** DQL\
**Tags:** dql\
**Created:** [November 28, 2023, 8:59pm UTC](https://community.dynatrace.com/t/get-host-name-in-open-events/42888 "2023-11-28T20:59:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![PickleRick](https://avatars.discourse-cdn.com/v4/letter/p/85f322/32.png) [@PickleRick](https://community.dynatrace.com/u/PickleRick)\
**Post date:** [November 28, 2023, 8:59pm UTC](https://community.dynatrace.com/t/get-host-name-in-open-events/42888/1 "2023-11-28T20:59:59Z")

</div>

Greetings!&nbsp; I’m attempting to DQL my way to a problems dashboard.&nbsp; Think of the classic Problems UI in DT, showing active problems and what’s affected.

So far my DQL is very basic:

```markup
fetch events
| filter event.kind == "DAVIS_PROBLEM"
| sort timestamp desc
| filter event.status != "CLOSED"

```

Unfortunately when I get my events back, host name isn’t part of the result set.&nbsp; I get things like affected\_entity\_ids, but I don’t get an actual host name.&nbsp; If I have low disk space or a service that isn’t responding, I’d like to see that.&nbsp; To be honest, without it the returned data to my proposed dashboard isn’t really helpful.

So… how can I get impacted service\database\server\website name?

---

<div class="post-metadata">

**Author:** ![kalelazic](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@kalelazic](https://community.dynatrace.com/u/kalelazic)\
**Post date:** [November 30, 2023, 8:12am UTC](https://community.dynatrace.com/t/get-host-name-in-open-events/42888/2 "2023-11-30T08:12:59Z")

</div>

Hi PickleRick!

This query should help:

```auto
fetch events, from:now()-6h
| filter event.kind == "DAVIS_PROBLEM"
| summarize {problem=takeMax(record(
  timestamp,
  resolved_problem_duration,
  event.end,dt.davis.is_duplicate,
  event.status,maintenance.is_under_maintenance,
  dt.davis.is_frequent_event,
  affected_entity_ids
  )) }, by:{display_id}
| fieldsFlatten problem
| filter problem.dt.davis.is_frequent_event == false and problem.dt.davis.is_duplicate == false and problem.maintenance.is_under_maintenance == false
| filter problem.event.status == "CLOSED"
| expand entityId = problem.affected_entity_ids
| fieldsAdd entityName = if(startsWith(entityId,"SERVICE-"), lookup([fetch dt.entity.service], sourceField:entityId, lookupField:id)[entity.name])
| fieldsAdd entityName = if(startsWith(entityId,"HOST-"), lookup([fetch dt.entity.host], sourceField:entityId, lookupField:id)[entity.name], else: entityName)
| fieldsAdd entityName = if(startsWith(entityId,"APPLICATION-"), lookup([fetch dt.entity.application], sourceField:entityId, lookupField:id)[entity.name], else: entityName)
| fieldsAdd entityName = if(startsWith(entityId,"PROCESS_GROUP_INSTANCE-"), lookup([fetch dt.entity.process_group_instance], sourceField:entityId, lookupField:id)[entity.name], else: entityName)
| fieldsAdd entityName = if(startsWith(entityId,"HTTP_CHECK-"), lookup([fetch dt.entity.http_check], sourceField:entityId, lookupField:id)[entity.name], else: entityName)
| fieldsAdd entityName = if(startsWith(entityId,"SYNTHETIC_TEST-"), lookup([fetch dt.entity.synthetic_test], sourceField:entityId, lookupField:id)[entity.name], else: entityName)
| fieldsAdd entityName = if(startsWith(entityId,"MOBILE_APPLICATION-"), lookup([fetch dt.entity.mobile_application], sourceField:entityId, lookupField:id)[entity.name], else: entityName)
| summarize affectedEntities = collectArray(entityName), by:{display_id}

```

Regards  
Kale

---

<div class="post-metadata">

**Author:** ![PickleRick](https://avatars.discourse-cdn.com/v4/letter/p/85f322/32.png) [@PickleRick](https://community.dynatrace.com/u/PickleRick)\
**Post date:** [November 30, 2023, 3:05pm UTC](https://community.dynatrace.com/t/get-host-name-in-open-events/42888/3 "2023-11-30T15:05:17Z")

</div>

Thanks Kale!&nbsp; This helps immensely!&nbsp; I have a lot to learn about DQL apparently.

Would you mind summarizing for me:

1. How does this work?&nbsp; As an example,

```auto
if(startsWith(entityId,"MOBILE_APPLICATION-"), lookup([fetch dt.entity.mobile_application]

```

How would I know to check dt.entity.mobile\_application?&nbsp; Trying to understand what documentation I could have researched that would have given me that information.

2. This gives me problem id and affected service\application\host - if I wanted to add another field, lets say problem summary (ex: Low Disk Space), how would I go about doing that?&nbsp; Not asking you to solve for me, asking for pointers so I can learn myself 🙂

Thanks again!

---

<div class="post-metadata">

**Author:** ![sinisa\_zubic](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/sinisa_zubic/32/32498_2.png) [@sinisa\_zubic](https://community.dynatrace.com/u/sinisa_zubic)\
**Post date:** [November 30, 2023, 3:57pm UTC](https://community.dynatrace.com/t/get-host-name-in-open-events/42888/4 "2023-11-30T15:57:32Z")

</div>

Hi [@PickleRick](https://community.dynatrace.com/user/69315)

Question 1:

We are currently planning to release a more extended documentation about entities (a dictionary). From there you should be able to see what kind of entities exists, their properties and their relationships. Currently you won’t be able to find that in documentation. But if you would have any problems raised in your environment which have mobile applications affected, then you would know.

Question 2:  
This query looks how it looks because it considers some the way davis events & problems are stored in grail. First you must know, davis problem records in grail are basically a changelog. So before you do any kind of further processing of a davis problem, you want to get the most recent state of a davis problem.  
Basically that part

```markup
fetch events, from:now()-6h
| filter event.kind == "DAVIS_PROBLEM"
| summarize {problem=takeMax(record(
  timestamp,
  resolved_problem_duration,
  event.end,dt.davis.is_duplicate,
  event.status,maintenance.is_under_maintenance,
  dt.davis.is_frequent_event,
  affected_entity_ids,
  event.name
  )) }, by:{display_id}

```

In the [record function](https://docs.dynatrace.com/docs/shortlink/general-functions#record) you list all fields which are to your interest. Because you are interested also in the problem summary, add the field event.name to that list.

After this step, every record consists of two fields, a field display\_id and a complex field problem, which we have created with the record function. We want to flatten this complex record out, so lets use the [fieldsFlatten](https://docs.dynatrace.com/docs/shortlink/structuring-commands#fieldsFlatten) command

```auto
| fieldsFlatten problem
| filter problem.dt.davis.is_frequent_event == false and problem.dt.davis.is_duplicate == false and problem.maintenance.is_under_maintenance == false
| filter problem.event.status == "CLOSED"

```

Since affected\_entity\_ids are stored in an array, we have to [expand](https://docs.dynatrace.com/docs/shortlink/structuring-commands#expand) it and find to every affected entity ID the entity name.

```auto
| expand entityId = problem.affected_entity_ids
| fieldsAdd entityName = if(startsWith(entityId,"SERVICE-"), lookup([fetch dt.entity.service], sourceField:entityId, lookupField:id)[entity.name])
| fieldsAdd entityName = if(startsWith(entityId,"HOST-"), lookup([fetch dt.entity.host], sourceField:entityId, lookupField:id)[entity.name], else: entityName)
| fieldsAdd entityName = if(startsWith(entityId,"APPLICATION-"), lookup([fetch dt.entity.application], sourceField:entityId, lookupField:id)[entity.name], else: entityName)
| fieldsAdd entityName = if(startsWith(entityId,"PROCESS_GROUP_INSTANCE-"), lookup([fetch dt.entity.process_group_instance], sourceField:entityId, lookupField:id)[entity.name], else: entityName)
| fieldsAdd entityName = if(startsWith(entityId,"HTTP_CHECK-"), lookup([fetch dt.entity.http_check], sourceField:entityId, lookupField:id)[entity.name], else: entityName)
| fieldsAdd entityName = if(startsWith(entityId,"SYNTHETIC_TEST-"), lookup([fetch dt.entity.synthetic_test], sourceField:entityId, lookupField:id)[entity.name], else: entityName)
| fieldsAdd entityName = if(startsWith(entityId,"MOBILE_APPLICATION-"), lookup([fetch dt.entity.mobile_application], sourceField:entityId, lookupField:id)[entity.name], else: entityName)

```

We have many duplicate problems now, so lets [summarize](https://docs.dynatrace.com/docs/shortlink/aggregation-commands#summarize) the problems and add the affected entities arrays in one array field. Also don’t forget your additional field event.name (summary).

```auto
| summarize affectedEntities = collectArray(entityName), by:{display_id, problem.event.name}

```

The team is currently working on improvements so that you won’t need to query the latest change of a davis problem.

Best,  
Sini

---

<div class="post-metadata">

**Author:** ![Keith\_Harding](https://avatars.discourse-cdn.com/v4/letter/k/8797f3/32.png) [@Keith\_Harding](https://community.dynatrace.com/u/Keith_Harding)\
**Post date:** [May 30, 2024, 5:46am UTC](https://community.dynatrace.com/t/get-host-name-in-open-events/42888/5 "2024-05-30T05:46:18Z")

</div>

Hi

In your answer to Q1 above you mention a data dictionary.&nbsp; Did that get created?&nbsp; Where is it?

I ask as I am trying to join from the problem to get the text description you see in the GUI but can’t find it anywhere.

thanks

---

<div class="post-metadata">

**Author:** ![jegron](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/jegron/32/12797_2.png) [@jegron](https://community.dynatrace.com/u/jegron)\
**Post date:** [January 15, 2025, 11:31am UTC](https://community.dynatrace.com/t/get-host-name-in-open-events/42888/6 "2025-01-15T11:31:24Z")

</div>

Hi&nbsp;[@sinisa\_zubic](https://community.dynatrace.com/user/38283)&nbsp;! I can see you added&nbsp;root\_cause\_entity\_name. Will you add&nbsp;affected\_entity\_name ?
