# DQL query to fetch hosts via ostype

**URL:** <https://community.dynatrace.com/t/dql-query-to-fetch-hosts-via-ostype/47457>\
**Category:** DQL\
**Tags:** dql\
**Created:** [September 3, 2024, 3:35pm UTC](https://community.dynatrace.com/t/dql-query-to-fetch-hosts-via-ostype/47457 "2024-09-03T15:35:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![huzoor](https://avatars.discourse-cdn.com/v4/letter/h/67e7ee/32.png) [@huzoor](https://community.dynatrace.com/u/huzoor)\
**Post date:** [September 3, 2024, 3:35pm UTC](https://community.dynatrace.com/t/dql-query-to-fetch-hosts-via-ostype/47457/1 "2024-09-03T15:35:48Z")

</div>

Hi,

I am new to DQL query stuff, can anyone tell me the query to use to fetch the hostgroups which have hosts running on ostype like linux and windows and also along with monitoringmode they are configured on ?

---

<div class="post-metadata">

**Author:** ![Robert\_Conatser](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@Robert\_Conatser](https://community.dynatrace.com/u/Robert_Conatser)\
**Post date:** [September 3, 2024, 7:29pm UTC](https://community.dynatrace.com/t/dql-query-to-fetch-hosts-via-ostype/47457/2 "2024-09-03T19:29:40Z")

</div>

See if this gets close to what you are asking for.

fetch dt.entity.host  
| fieldsAdd hostGroupName, Host=entity.name, entity.type, osType, state, monitoringMode  
| filter entity.type == “HOST” and state == “RUNNING”  
| fieldsRemove entity.type, state  
| sort hostGroupName, Host

---

<div class="post-metadata">

**Author:** ![huzoor](https://avatars.discourse-cdn.com/v4/letter/h/67e7ee/32.png) [@huzoor](https://community.dynatrace.com/u/huzoor)\
**Post date:** [September 3, 2024, 7:47pm UTC](https://community.dynatrace.com/t/dql-query-to-fetch-hosts-via-ostype/47457/3 "2024-09-03T19:47:11Z")

</div>

thank you so much, can you let me know how to filterout ec2 instances?&nbsp; and also how to avoid names that has “db” in them

---

<div class="post-metadata">

**Author:** ![Robert\_Conatser](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@Robert\_Conatser](https://community.dynatrace.com/u/Robert_Conatser)\
**Post date:** [September 3, 2024, 8:00pm UTC](https://community.dynatrace.com/t/dql-query-to-fetch-hosts-via-ostype/47457/4 "2024-09-03T20:00:13Z")

</div>

fetch dt.entity.host  
| fieldsAdd hostGroupName, Host=entity.name, entity.type, osType, state, monitoringMode, **cloudType**  
| filter entity.type == “HOST” and state == “RUNNING” **and cloudType != “EC2” and NOT contains(Host,“db”)**  
| fieldsRemove entity.type, state  
| sort hostGroupName, Host

---

<div class="post-metadata">

**Author:** ![huzoor](https://avatars.discourse-cdn.com/v4/letter/h/67e7ee/32.png) [@huzoor](https://community.dynatrace.com/u/huzoor)\
**Post date:** [September 3, 2024, 8:05pm UTC](https://community.dynatrace.com/t/dql-query-to-fetch-hosts-via-ostype/47457/5 "2024-09-03T20:05:26Z")

</div>

I did try the above one before as well, its not fetching any records.. without the cloudtype boolean.. it does fetch all EC2 instance but when we include that it is not.

---

<div class="post-metadata">

**Author:** ![Robert\_Conatser](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@Robert\_Conatser](https://community.dynatrace.com/u/Robert_Conatser)\
**Post date:** [September 3, 2024, 8:16pm UTC](https://community.dynatrace.com/t/dql-query-to-fetch-hosts-via-ostype/47457/6 "2024-09-03T20:16:56Z")

</div>

Try this one.&nbsp; It seem that it was filtering out the ones with null. (not sure way).

fetch dt.entity.host  
| fieldsAdd hostGroupName, Host=entity.name, entity.type, osType, state, monitoringMode, cloudType  
| filter entity.type == “HOST” and state == “RUNNING” and (cloudType != “EC2” or isNull(cloudType)) and NOT contains(Host,“db”)  
| fieldsRemove entity.type, state  
| sort cloudType, hostGroupName, Host

---

<div class="post-metadata">

**Author:** ![huzoor](https://avatars.discourse-cdn.com/v4/letter/h/67e7ee/32.png) [@huzoor](https://community.dynatrace.com/u/huzoor)\
**Post date:** [September 3, 2024, 8:19pm UTC](https://community.dynatrace.com/t/dql-query-to-fetch-hosts-via-ostype/47457/7 "2024-09-03T20:19:15Z")

</div>

you are awesome, thank you so much ..&nbsp; if you can guide me for knowledge guide on how to fetch all these details would be helpful.

---

<div class="post-metadata">

**Author:** ![Robert\_Conatser](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@Robert\_Conatser](https://community.dynatrace.com/u/Robert_Conatser)\
**Post date:** [September 3, 2024, 8:29pm UTC](https://community.dynatrace.com/t/dql-query-to-fetch-hosts-via-ostype/47457/8 "2024-09-03T20:29:43Z")

</div>

Better solution (too many “Not”, “and” and “or” 😂)

fetch dt.entity.host  
| fieldsAdd hostGroupName, Host=entity.name, entity.type, osType, state, monitoringMode, cloudType  
| filter entity.type == “HOST” and state == “RUNNING”  
| filterOut cloudType == “EC2” or contains(Host,“db”)  
| fieldsRemove entity.type, state  
| sort hostGroupName, Host
