# Host List without Management Zone

**URL:** <https://community.dynatrace.com/t/host-list-without-management-zone/43771>\
**Category:** Open Q&A\
**Tags:** management-zones, entity-selector\
**Created:** [January 23, 2024, 9:27am UTC](https://community.dynatrace.com/t/host-list-without-management-zone/43771 "2024-01-23T09:27:14Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![gbaudart](https://avatars.discourse-cdn.com/v4/letter/g/e47c2d/32.png) [@gbaudart](https://community.dynatrace.com/u/gbaudart)\
**Post date:** [January 23, 2024, 9:27am UTC](https://community.dynatrace.com/t/host-list-without-management-zone/43771/1 "2024-01-23T09:27:14Z")

</div>

Hi Community,

I’d like to output a list of Hosts that are not in a ManagementZone.  
The EntitySelector does not allow us to do this.

Do you have an idea?

---

<div class="post-metadata">

**Author:** ![AntonPineiro](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/antonpineiro/32/49_2.png) [@AntonPineiro](https://community.dynatrace.com/u/AntonPineiro)\
**Post date:** [January 23, 2024, 9:44am UTC](https://community.dynatrace.com/t/host-list-without-management-zone/43771/2 "2024-01-23T09:44:14Z")

</div>

Hi,

I would say using entities API:

1. Call [entities API](https://docs.dynatrace.com/docs/shortlink/api-entities-v2-get-all-entities-list) to get a full host list.
2. Call [entity API](https://docs.dynatrace.com/docs/shortlink/api-entities-v2-get-entity) per host ID in before query.

Second one is providing much more information than mz, but you can see if that host has a MZ or not:

 ![AntonPineiro_0-1706003113199.png](https://global.discourse-cdn.com/dynatrace/original/3X/e/7/e74d261ead0004b44807628946b7469b6efa016f.png)

Best regards

---

<div class="post-metadata">

**Author:** ![gbaudart](https://avatars.discourse-cdn.com/v4/letter/g/e47c2d/32.png) [@gbaudart](https://community.dynatrace.com/u/gbaudart)\
**Post date:** [January 24, 2024, 3:54pm UTC](https://community.dynatrace.com/t/host-list-without-management-zone/43771/3 "2024-01-24T15:54:22Z")

</div>

Isn’t there an easier way to get the information?

---

<div class="post-metadata">

**Author:** ![PraWij](https://avatars.discourse-cdn.com/v4/letter/p/67e7ee/32.png) [@PraWij](https://community.dynatrace.com/u/PraWij)\
**Post date:** [January 24, 2024, 4:29pm UTC](https://community.dynatrace.com/t/host-list-without-management-zone/43771/4 "2024-01-24T16:29:36Z")

</div>

This may help, part of a dashboard - not my code, from a DT SME.

```markup
import { monitoredEntitiesClient } from '@dynatrace-sdk/client-classic-environment-v2';

export default async function() {
  // Check if that tile should be activated based on selected indicators and scope
  if($Indicators[0] === "All" || $Indicators.includes("hostGroupCoverage")) {
    let scope;
    if($Scope[0] === "Tenant") {
      scope = 'Tenant';
    } else {
      let mzList = "";
      for(let i=0; i<$Scope.length; i++) {
        mzList += i === 0 ? `"${$Scope[i]}"` : `,"${$Scope[i]}"`;
      }
      scope = mzList;
    }
    // Define entity selector based on the selected scope
    let entitySelector;
    if(scope === "Tenant") {
      entitySelector = 'type("HOST"),isMonitoringCandidate(false)';
    } else {
      entitySelector = `type("HOST"),isMonitoringCandidate(false),mzName(${scope})`;
    }
    let config = { from: `now-1d`, entitySelector: entitySelector};
    // Get all monitored hosts
    const monitoredHosts = await monitoredEntitiesClient.getEntities(config);
    // Define entity selector based on the selected scope
    if(scope === "Tenant") {
      entitySelector = 'type("HOST"),isMonitoringCandidate(false),fromRelationships.isInstanceOf(type("HOST_GROUP"))';
    } else {
      entitySelector = `type("HOST"),isMonitoringCandidate(false),fromRelationships.isInstanceOf(type("HOST_GROUP")),mzName(${scope})`;
    }
    config = { from: `now-1d`, entitySelector: entitySelector};
    // Get all monitored hosts that are assigned with a host group
    const hostsWithHostGroup = await monitoredEntitiesClient.getEntities(config);
    // Compute host group coverage
    const hostGroupCoverage = parseInt(hostsWithHostGroup.totalCount/monitoredHosts.totalCount*100);
    // Compute local score based on the host group coverage
    const score = hostGroupCoverage === 100 ? 1 : (hostGroupCoverage >= 80 ? 0.5 : 0);
    let result;
    switch(true) {
      case score === 1:
        result = `✅ ${hostGroupCoverage}%`;
        break;
      case score === 0.5:
        result = `💡 ${hostGroupCoverage}%`;
        break;
      case score === 0:
        result = `⚠️ ${hostGroupCoverage}%`;
        break;
    }
    // Return the emojied result
    return result;
  } else {
    return "N/A";
  }
}

```

---

<div class="post-metadata">

**Author:** ![AntonPineiro](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/antonpineiro/32/49_2.png) [@AntonPineiro](https://community.dynatrace.com/u/AntonPineiro)\
**Post date:** [January 24, 2024, 5:13pm UTC](https://community.dynatrace.com/t/host-list-without-management-zone/43771/5 "2024-01-24T17:13:51Z")

</div>

Hi,

Maybe easier can be using Grail, if it is enabled in your tenant. I think you know more Grail than mine but something as that:

```markup
fetch dt.entity.host 
| expand managementZones
| filter managementZones == ""

```

Best regards

---

<div class="post-metadata">

**Author:** ![gbaudart](https://avatars.discourse-cdn.com/v4/letter/g/e47c2d/32.png) [@gbaudart](https://community.dynatrace.com/u/gbaudart)\
**Post date:** [January 24, 2024, 7:51pm UTC](https://community.dynatrace.com/t/host-list-without-management-zone/43771/6 "2024-01-24T19:51:55Z")

</div>

hi&nbsp;[@PraWij](https://community.dynatrace.com/user/64361),

Thanks for this code.

OK, but what are the $Indicators and $Scope variables?

---

<div class="post-metadata">

**Author:** ![gbaudart](https://avatars.discourse-cdn.com/v4/letter/g/e47c2d/32.png) [@gbaudart](https://community.dynatrace.com/u/gbaudart)\
**Post date:** [January 24, 2024, 7:52pm UTC](https://community.dynatrace.com/t/host-list-without-management-zone/43771/7 "2024-01-24T19:52:31Z")

</div>

[@AntonPineiro](https://community.dynatrace.com/user/58682)&nbsp;  
This doesn’t work. I’ll try with the sdk

---

<div class="post-metadata">

**Author:** ![PraWij](https://avatars.discourse-cdn.com/v4/letter/p/67e7ee/32.png) [@PraWij](https://community.dynatrace.com/u/PraWij)\
**Post date:** [January 25, 2024, 5:19pm UTC](https://community.dynatrace.com/t/host-list-without-management-zone/43771/8 "2024-01-25T17:19:50Z")

</div>

![PraWij_0-1706203177210.png](https://global.discourse-cdn.com/dynatrace/original/3X/0/1/01d9e3806a1bdddb2bcabc23c563ec9e501cdf62.png)

In the full dashboard, scope also includes the mgmt zones.

Indicators example:

 ![PraWij_1-1706203301677.png](https://global.discourse-cdn.com/dynatrace/original/2X/6/6b9f2aaf93c68158fb2ccd927761a09e7c51bbe3.png)

---

<div class="post-metadata">

**Author:** ![AntonPineiro](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/antonpineiro/32/49_2.png) [@AntonPineiro](https://community.dynatrace.com/u/AntonPineiro)\
**Post date:** [January 27, 2024, 5:42pm UTC](https://community.dynatrace.com/t/host-list-without-management-zone/43771/9 "2024-01-27T17:42:40Z")

</div>

Hi,

You can try this one, looks like is working:

```markup
fetch dt.entity.host
| fieldsAdd managementZones
| filter isNull(managementZones)

```

 ![AntonPineiro_0-1706377351198.png](https://global.discourse-cdn.com/dynatrace/original/3X/d/5/d5638ae977169130231796f50a4cff479ce74879.png)

Best regards

---

<div class="post-metadata">

**Author:** ![MarwanC](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/marwanc/32/34480_2.png) [@MarwanC](https://community.dynatrace.com/u/MarwanC)\
**Post date:** [January 29, 2024, 12:11pm UTC](https://community.dynatrace.com/t/host-list-without-management-zone/43771/10 "2024-01-29T12:11:35Z")

</div>

This looks interesting,

```auto
fetch dt.entity.host
| fieldsAdd managementZones
| filter isNull(managementZones)

```

What do I need to add to search by a particular management zone?&nbsp; contains or equal? need the DQL.

---

<div class="post-metadata">

**Author:** ![AntonPineiro](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/antonpineiro/32/49_2.png) [@AntonPineiro](https://community.dynatrace.com/u/AntonPineiro)\
**Post date:** [January 29, 2024, 1:23pm UTC](https://community.dynatrace.com/t/host-list-without-management-zone/43771/11 "2024-01-29T13:23:20Z")

</div>

Hi,

Maybe more than one option but looks like this:

```markup
fetch dt.entity.host
| fieldsAdd managementZones
| filter matchesValue(managementZones, "XXXXXX")

```

Best regards

---

<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:** [January 30, 2024, 6:05am UTC](https://community.dynatrace.com/t/host-list-without-management-zone/43771/12 "2024-01-30T06:05:41Z")

</div>

[@AntonPineiro](https://community.dynatrace.com/user/58682)&nbsp;This works for me. Thanks a lot.

Tijust

---

<div class="post-metadata">

**Author:** ![AntonPineiro](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/antonpineiro/32/49_2.png) [@AntonPineiro](https://community.dynatrace.com/u/AntonPineiro)\
**Post date:** [January 30, 2024, 11:01am UTC](https://community.dynatrace.com/t/host-list-without-management-zone/43771/13 "2024-01-30T11:01:39Z")

</div>

You are welcome!
