<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Management zone to identify orphan entities in Open Q&amp;A</title>
    <link>https://community.dynatrace.com/t5/Open-Q-A/Management-Zone-to-identify-orphan-entities/m-p/285919#M37551</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I would say creating those management zones base on tagging rules.&lt;/P&gt;&lt;P&gt;Then, you can define that logic base on tags:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;If tag is present, MZ A.&lt;/LI&gt;&lt;LI&gt;If tag is not present, MZ B.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Best regards&lt;/P&gt;</description>
    <pubDate>Sat, 13 Sep 2025 12:38:49 GMT</pubDate>
    <dc:creator>AntonPineiro</dc:creator>
    <dc:date>2025-09-13T12:38:49Z</dc:date>
    <item>
      <title>Management Zone to identify orphan entities</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/Management-Zone-to-identify-orphan-entities/m-p/285908#M37549</link>
      <description>&lt;P&gt;Is it possible to create a management zone that identifies all entities not included in any existing management zone? I’d like this zone to capture entities across multiple types—such as &lt;STRONG&gt;Applications&lt;/STRONG&gt;, &lt;STRONG&gt;Hosts&lt;/STRONG&gt;, &lt;STRONG&gt;Synthetic Tests&lt;/STRONG&gt;, &lt;STRONG&gt;HTTP Checks&lt;/STRONG&gt;, and &lt;STRONG&gt;Custom Devices&lt;/STRONG&gt;—so we can easily review any uncovered resources.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 29 Dec 2025 11:29:33 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/Management-Zone-to-identify-orphan-entities/m-p/285908#M37549</guid>
      <dc:creator>tmathew</dc:creator>
      <dc:date>2025-12-29T11:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: Management zone to identify orphan entities</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/Management-Zone-to-identify-orphan-entities/m-p/285919#M37551</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I would say creating those management zones base on tagging rules.&lt;/P&gt;&lt;P&gt;Then, you can define that logic base on tags:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;If tag is present, MZ A.&lt;/LI&gt;&lt;LI&gt;If tag is not present, MZ B.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Best regards&lt;/P&gt;</description>
      <pubDate>Sat, 13 Sep 2025 12:38:49 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/Management-Zone-to-identify-orphan-entities/m-p/285919#M37551</guid>
      <dc:creator>AntonPineiro</dc:creator>
      <dc:date>2025-09-13T12:38:49Z</dc:date>
    </item>
    <item>
      <title>Re: Management zone to identify orphan entities</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/Management-Zone-to-identify-orphan-entities/m-p/285927#M37552</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;unfortunately, there is no such option from the GUI.&lt;BR /&gt;The only thing I can suggest is retrieving this data via the API.&lt;BR /&gt;First, list all entities by type, then for each entityID check if it has an assigned MZ.&lt;BR /&gt;Below, I’m pasting a script that will list this for you.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#!/usr/bin/env python3

import os, csv, json, time, re, argparse
import requests
from concurrent.futures import ThreadPoolExecutor, as_completed
# =========================
# CONFIGURATION (CHANGE HERE)
# =========================
DT_BASE_URL = "https://dynatrace/e/tenantid"  # WITHOUT /api/v2 at the end
DT_API_TOKEN = "dt0c01. API TOKEN"  # token with "Monitored entities – read" permission (API v2)

# Types you want to check
TYPES = ["APPLICATION", "HOST", "SYNTHETIC_TEST", "HTTP_CHECK", "CUSTOM_DEVICE"]

# Files
OUT_CSV = "unassigned_entities.csv"
OUT_JSON = "unassigned_entities.json"

# Technical parameters
PAGE_SIZE   = 500
TIMEOUT_SEC = 30
MAX_WORKERS = 8  
# =========================


def _normalize_base_url(u: str) -&amp;gt; str:
    if not u:
        raise RuntimeError("DT_BASE_URL not set")
    u = re.sub(r"/api/v2/?$", "", u.strip())  
    return u.rstrip("/")


def _headers():
    return {
        "Authorization": f"Api-Token {DT_API_TOKEN}",
        "accept": "application/json; charset=utf-8",
    }


def list_entity_ids(base_url: str, entity_type: str):
    """Step 1: Returns a list of entityIds for a given type"""
    ids = []
    next_key = None
    url = f"{base_url}/api/v2/entities"

    while True:
        if next_key:
            params = {"nextPageKey": next_key}
        else:

            params = {"entitySelector": f'type("{entity_type}")', "pageSize": str(PAGE_SIZE)}

        r = requests.get(url, headers=_headers(), params=params, timeout=TIMEOUT_SEC)
        if r.status_code == 429:
            time.sleep(1.0)
            continue
        r.raise_for_status()

        data = r.json()
        for e in data.get("entities", []):
            eid = e.get("entityId")
            if eid:
                ids.append(eid)

        next_key = data.get("nextPageKey")
        if not next_key:
            break

    return ids


def get_entity_details(base_url: str, entity_id: str):
    url = f"{base_url}/api/v2/entities/{entity_id}"
    params = {"fields": "+managementZones,+tags,+firstSeenTms,+lastSeenTms"}  # &amp;lt;= FIX

    for attempt in range(5): 
        r = requests.get(url, headers=_headers(), params=params, timeout=TIMEOUT_SEC)
        if r.status_code == 429:
            time.sleep(0.5 * (attempt + 1))
            continue
        if not r.ok:
            return {
                "entityId": entity_id,
                "type": "",
                "displayName": "",
                "firstSeenTms": None,
                "lastSeenTms": None,
                "managementZonesCount": None,
                "error": f"{r.status_code} {r.text[:1000]}",
            }

        data = r.json()
        mz = data.get("managementZones") or []
        return {
            "entityId": data.get("entityId", entity_id),
            "type": data.get("type", ""),
            "displayName": data.get("displayName", ""),
            "firstSeenTms": data.get("firstSeenTms"),
            "lastSeenTms": data.get("lastSeenTms"),
            "managementZonesCount": len(mz),
        }

    return {
        "entityId": entity_id,
        "type": "",
        "displayName": "",
        "firstSeenTms": None,
        "lastSeenTms": None,
        "managementZonesCount": None,
        "error": "Too many 429s",
    }

def main():
    base_url = _normalize_base_url(DT_BASE_URL)
    if not DT_API_TOKEN or DT_API_TOKEN.startswith("dt0c01.xxxxx"):
        raise RuntimeError("Set the correct DT_API_TOKEN in the script header")

    all_ids = []
    per_type_counts = {}

    # Krok 1 — listing ID
    for t in TYPES:
        print(f"[INFO] Step1: listing the ID for the type: {t}")
        ids = list_entity_ids(base_url, t)
        per_type_counts[t] = len(ids)
        all_ids.extend(ids)
        print(f"[OK] {t}: {len(ids)} entity")

    # Krok 2 — szczegóły
    print(f"[INFO] Step2: fetching details of {len(all_ids)} entities in parallel ({MAX_WORKERS} threads)")
    details = []
    unassigned = []

    with ThreadPoolExecutor(max_workers=MAX_WORKERS) as ex:
        futures = {ex.submit(get_entity_details, base_url, eid): eid for eid in all_ids}
        for f in as_completed(futures):
            rec = f.result()
            details.append(rec)

            if rec.get("error"):
                print(f"[WARN] {rec['entityId']}: {rec['error']}")
                continue

            if rec.get("managementZonesCount", 0) == 0:
                unassigned.append(rec)

    # Save
    fields = ["entityId", "type", "displayName", "firstSeenTms", "lastSeenTms", "managementZonesCount"]
    with open(OUT_CSV, "w", newline="", encoding="utf-8") as f:
        w = csv.DictWriter(f, fieldnames=fields)
        w.writeheader()
        for r in unassigned:
            w.writerow(r)

    with open(OUT_JSON, "w", encoding="utf-8") as f:
        json.dump(unassigned, f, ensure_ascii=False, indent=2)

    # Summary
    print("\n=== SUMMARY ===")
    for t, c in per_type_counts.items():
        print(f"{t}: {c} (all)")
    print(f"without MZ: {len(unassigned)}")
    print(f"Pliki: {OUT_CSV}  |  {OUT_JSON}")


if __name__ == "__main__":
    main()&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 13 Sep 2025 15:47:19 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/Management-Zone-to-identify-orphan-entities/m-p/285927#M37552</guid>
      <dc:creator>t_pawlak</dc:creator>
      <dc:date>2025-09-13T15:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: Management zone to identify orphan entities</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/Management-Zone-to-identify-orphan-entities/m-p/285970#M37555</link>
      <description>&lt;P&gt;I would say this would definitely work. Tagging resources is imo the most important step for ordering entities and metrics. So you would simply base your management zones upon tags.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Let's say you have created a Management Zone based upon an Application tag:MyApplication.&lt;BR /&gt;You can than &lt;STRONG&gt;&lt;U&gt;negate&lt;/U&gt; &lt;/STRONG&gt;the management zone like this for hosts:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;&lt;EM&gt;type("HOST"), not(tag("MyApplication"))&lt;/EM&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could&amp;nbsp; also just create a notebook / dashboard&amp;nbsp; where you write an DQL statement that pulls these metrics and combine it with other usefull stuff like updates failed, hosts not in host groups / network zones etc.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Sep 2025 08:32:04 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/Management-Zone-to-identify-orphan-entities/m-p/285970#M37555</guid>
      <dc:creator>michiel_otten</dc:creator>
      <dc:date>2025-09-15T08:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: Management zone to identify orphan entities</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/Management-Zone-to-identify-orphan-entities/m-p/286229#M37598</link>
      <description>&lt;P&gt;Thank you all for the ideas and solutions. I truly appreciate your time and effort in helping me work toward resolving the problem.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Sep 2025 20:24:56 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/Management-Zone-to-identify-orphan-entities/m-p/286229#M37598</guid>
      <dc:creator>tmathew</dc:creator>
      <dc:date>2025-09-16T20:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: Management zone to identify orphan entities</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/Management-Zone-to-identify-orphan-entities/m-p/286402#M37620</link>
      <description>&lt;P&gt;Hi tomaxp,&lt;/P&gt;&lt;P&gt;Thanks again for the code. I tried running it and ran in to the below error :&lt;/P&gt;&lt;P&gt;Appreciate if you could have a look and give suggestions to fix it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;C:\Users\thomas.mathew&amp;gt;Python FindOrphanMZ.py&lt;/P&gt;&lt;P&gt;[INFO] Step1: listing the ID for the type: APPLICATION&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "C:\Users\thomas.mathew\FindOrphanMZ.py", line 168, in &amp;lt;module&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; main()&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "C:\Users\thomas.mathew\FindOrphanMZ.py", line 125, in main&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; ids = list_entity_ids(base_url, t)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "C:\Users\thomas.mathew\FindOrphanMZ.py", line 58, in list_entity_ids&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; r.raise_for_status()&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "C:\Users\thomas.mathew\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\requests\models.py", line 1026, in raise_for_status&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; raise HTTPError(http_error_msg, response=self)&lt;/P&gt;&lt;P&gt;requests.exceptions.HTTPError: 404 Client Error: Not Found for url: &lt;A href="https://{environmentid}.apps.dynatrace.com%2Fapi%2Fv2%2Fentities%3FentitySelector%3Dtype*28*22APPLICATION*22*29%26pageSize%3D500__%3BJSUlJQ!!HUqgN_M!p__IREVNErZwLKUMrBx8sHTBSoEJFnkupFORKA5i6rDHRn54FcD91dhSclano82gGAEJwik3CSfQkct9tQWqHM81EA%24&amp;amp;data=05%7C02%7Cthomas.mathew%40orasi.com%7Ca5dea7e62569445f235808ddf6e46bb6%7Cd3f61ad4cd4244ba9987f609cd2d8c85%7C0%7C0%7C638938183122466832%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&amp;amp;sdata=1QJQ1JidMT7Hq5ggjZcaNQ54wtsRNeKAaUD5csAhzWY%3D&amp;amp;reserved=0" target="_blank"&gt;https://{environmentid}.apps.dynatrace.com/api/v2/entities?entitySelector=type%28%22APPLICATION%22%29&amp;amp;pageSize=500&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;C:\Users\thomas.mathew&amp;gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Sep 2025 19:00:46 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/Management-Zone-to-identify-orphan-entities/m-p/286402#M37620</guid>
      <dc:creator>tmathew</dc:creator>
      <dc:date>2025-09-18T19:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: Management zone to identify orphan entities</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/Management-Zone-to-identify-orphan-entities/m-p/286422#M37622</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/66749"&gt;@tmathew&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Thanks for trying it out! The 404 comes from calling the wrong host for API v2. In Dynatrace &lt;STRONG&gt;SaaS&lt;/STRONG&gt;, API v2 lives at *.live.dynatrace.com (not *.apps.dynatrace.com). In &lt;STRONG&gt;Managed&lt;/STRONG&gt;, it’s your cluster URL with /e/&amp;lt;environmentId&amp;gt;.&lt;/P&gt;&lt;P&gt;I’ve just tested it against apps.dynatrace.com and it worked. On some “Latest Dynatrace” tenants, certain endpoints of the classic Environment API v2 are also exposed via *.apps.dynatrace.com (typically as a proxy to the classic APIs).&lt;/P&gt;&lt;P&gt;Please try switching&lt;BR /&gt;https://{environmentid}.live.dynatrace.com&lt;BR /&gt;and test again.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Sep 2025 08:30:28 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/Management-Zone-to-identify-orphan-entities/m-p/286422#M37622</guid>
      <dc:creator>t_pawlak</dc:creator>
      <dc:date>2025-09-19T08:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: Management zone to identify orphan entities</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/Management-Zone-to-identify-orphan-entities/m-p/286554#M37639</link>
      <description>&lt;P&gt;Hi tomaxp,&lt;BR /&gt;&lt;BR /&gt;Excellent — thank you so much! It worked perfectly.&lt;/P&gt;&lt;P&gt;I was also wondering if there’s a way to convert this into a dashboard — specifically, one that would list all entities that are not assigned to any Management Zone.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Sep 2025 00:03:00 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/Management-Zone-to-identify-orphan-entities/m-p/286554#M37639</guid>
      <dc:creator>tmathew</dc:creator>
      <dc:date>2025-09-23T00:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: Management zone to identify orphan entities</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/Management-Zone-to-identify-orphan-entities/m-p/286562#M37640</link>
      <description>&lt;P&gt;You can upload the script's output to Dynatrace as a metric. If you run it once a day, it shouldn't use much license space.&lt;BR /&gt;&lt;A href="https://docs.dynatrace.com/docs/discover-dynatrace/references/dynatrace-api/environment-api/metric-v2/post-ingest-metrics" target="_blank"&gt;https://docs.dynatrace.com/docs/discover-dynatrace/references/dynatrace-api/environment-api/metric-v2/post-ingest-metrics&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Sep 2025 06:54:29 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/Management-Zone-to-identify-orphan-entities/m-p/286562#M37640</guid>
      <dc:creator>t_pawlak</dc:creator>
      <dc:date>2025-09-23T06:54:29Z</dc:date>
    </item>
    <item>
      <title>Re: Management zone to identify orphan entities</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/Management-Zone-to-identify-orphan-entities/m-p/290608#M38118</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;SPAN&gt;t_pawlak. Appreciate your help.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Dec 2025 17:04:33 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/Management-Zone-to-identify-orphan-entities/m-p/290608#M38118</guid>
      <dc:creator>tmathew</dc:creator>
      <dc:date>2025-12-01T17:04:33Z</dc:date>
    </item>
  </channel>
</rss>

