<?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: Oneagent updateStatus using DQL in Open Q&amp;A</title>
    <link>https://community.dynatrace.com/t5/Open-Q-A/OneAgent-updateStatus-using-DQL/m-p/287258#M37717</link>
    <description>&lt;P&gt;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/58568"&gt;@SrikanthSamraj&lt;/a&gt;&amp;nbsp;Not sure this field is exposed via DQL, your best bet would be API&lt;/P&gt;</description>
    <pubDate>Thu, 02 Oct 2025 23:44:31 GMT</pubDate>
    <dc:creator>p_devulapalli</dc:creator>
    <dc:date>2025-10-02T23:44:31Z</dc:date>
    <item>
      <title>OneAgent updateStatus using DQL</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/OneAgent-updateStatus-using-DQL/m-p/287242#M37716</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Is it possible to retrieve UpdateStatus field of an oneagent using DQL? I know that we can avail this using /api/v1/oneagents.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Oct 2025 10:34:30 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/OneAgent-updateStatus-using-DQL/m-p/287242#M37716</guid>
      <dc:creator>SrikanthSamraj</dc:creator>
      <dc:date>2025-10-31T10:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: Oneagent updateStatus using DQL</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/OneAgent-updateStatus-using-DQL/m-p/287258#M37717</link>
      <description>&lt;P&gt;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/58568"&gt;@SrikanthSamraj&lt;/a&gt;&amp;nbsp;Not sure this field is exposed via DQL, your best bet would be API&lt;/P&gt;</description>
      <pubDate>Thu, 02 Oct 2025 23:44:31 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/OneAgent-updateStatus-using-DQL/m-p/287258#M37717</guid>
      <dc:creator>p_devulapalli</dc:creator>
      <dc:date>2025-10-02T23:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: Oneagent updateStatus using DQL</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/OneAgent-updateStatus-using-DQL/m-p/287298#M37718</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/58568"&gt;@SrikanthSamraj&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;I don't think there's an automated way to use DQL for get OneAgent and ActiveGate for obtain&amp;nbsp;&lt;SPAN&gt;UpdateStatus .&lt;/SPAN&gt;&amp;nbsp;&lt;BR /&gt;But I think it could be possible if you capture both logs and input them into Dynatrace, with that way you can do explore information with DQL.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I hope it's helpful &lt;span class="lia-unicode-emoji" title=":flexed_biceps:"&gt;💪&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Oct 2025 17:51:40 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/OneAgent-updateStatus-using-DQL/m-p/287298#M37718</guid>
      <dc:creator>PierreGutierrez</dc:creator>
      <dc:date>2025-10-03T17:51:40Z</dc:date>
    </item>
    <item>
      <title>Re: Oneagent updateStatus using DQL</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/OneAgent-updateStatus-using-DQL/m-p/287302#M37719</link>
      <description>&lt;P&gt;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/58568"&gt;@SrikanthSamraj&lt;/a&gt;I also think that the only way is via ingest logs and then parse them as &lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/45543"&gt;@PierreGutierrez&lt;/a&gt; suggested, but I'm wondering what is your use case? Why DQL and not the API?&lt;/P&gt;</description>
      <pubDate>Fri, 03 Oct 2025 18:42:45 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/OneAgent-updateStatus-using-DQL/m-p/287302#M37719</guid>
      <dc:creator>deni</dc:creator>
      <dc:date>2025-10-03T18:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: Oneagent updateStatus using DQL</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/OneAgent-updateStatus-using-DQL/m-p/287612#M37763</link>
      <description>&lt;P&gt;Hi, u can use this script and send result as metrics/logs/event to dynatrace:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Dynatrace OneAgents UpdateStatus exporter
"""

import argparse
import csv
import json
import sys
from datetime import datetime, timezone
from typing import Dict, Iterable, List, Optional
import requests

# =========================
# CONFIGURATION (CHANGE HERE)
# =========================
DT_BASE_URL = "https://dynatrace/e/tenant"
DT_API_TOKEN = "dt0c01.xxxxxxxxxxxx" 

# =========================
# MAIN SCRIPT
# =========================

def parse_args():
    p = argparse.ArgumentParser(description="Export Dynatrace OneAgents update status.")
    p.add_argument("--base-url", default=DT_BASE_URL,
                   help=f"Base URL of your Dynatrace environment (default: {DT_BASE_URL})")
    p.add_argument("--api-token", default=DT_API_TOKEN,
                   help="Dynatrace API token (default: value from CONFIGURATION)")
    p.add_argument("--output", default="oneagents.csv",
                   help="Output file path (ends with .csv or .json). Default: oneagents.csv")
    p.add_argument("--page-size", type=int, default=500,
                   help="Page size for the API call. Default: 500")
    p.add_argument("--verify", default="true",
                   help="TLS verification: 'true' (default), 'false', or path to CA bundle.")
    p.add_argument("--timeout", type=int, default=30, help="HTTP timeout seconds. Default: 30")
    return p.parse_args()

def make_session(token: str, verify_opt: str, timeout: int) -&amp;gt; requests.Session:
    s = requests.Session()
    s.headers.update({
        "Authorization": f"Api-Token {token}",
        "Accept": "application/json",
    })
    if verify_opt.lower() == "false":
        s.verify = False
    elif verify_opt.lower() == "true":
        s.verify = True
    else:
        s.verify = verify_opt  # path to CA bundle
    s.timeout = timeout
    return s

def fetch_oneagents(base_url: str,
                    session: requests.Session,
                    page_size: int = 500
                   ) -&amp;gt; Iterable[Dict]:
    """
    Generator yielding OneAgent records from /api/v1/oneagents across all pages.
    """
    endpoint = f"{base_url.rstrip('/')}/api/v1/oneagents"
    params = {"pageSize": page_size}

    next_key = None
    while True:
        q = params.copy()
        if next_key:
            q["nextPageKey"] = next_key
        resp = session.get(endpoint, params=q)
        resp.raise_for_status()
        data = resp.json() or {}

        items = []
        for key in ("oneagents", "agents", "items"):
            if isinstance(data.get(key), list):
                items = data[key]
                break
        if not items and isinstance(data, list):
            items = data

        for it in items:
            yield it

        next_key = data.get("nextPageKey")
        if not next_key:
            break

def normalize_record(raw: Dict) -&amp;gt; Dict:
    def to_iso(ts):
        if ts in (None, 0, "0"):
            return None
        try:
            return datetime.fromtimestamp(int(ts)/1000, tz=timezone.utc).isoformat()
        except Exception:
            return str(ts)

    return {
        "hostId": raw.get("hostId") or raw.get("entityId") or raw.get("host", {}).get("id"),
        "hostName": raw.get("hostName") or raw.get("displayName") or raw.get("host", {}).get("displayName"),
        "ipAddresses": ",".join(raw.get("ipAddresses", []) or raw.get("networkAddresses", []) or []),
        "osType": raw.get("osType"),
        "oneAgentVersion": (raw.get("agentVersion") or raw.get("oneAgentVersion")
                            or raw.get("version") or raw.get("agent", {}).get("version")),
        "updateStatus": raw.get("updateStatus"),
        "needsReboot": raw.get("needsReboot"),
        "availabilityState": raw.get("availabilityState"),
        "managementZoneIds": ",".join(raw.get("managementZoneIds", []) or []),
        "hostGroupId": raw.get("hostGroupId"),
        "autoUpdate": raw.get("autoUpdate") or raw.get("autoUpdateSettings", {}).get("enabled"),
        "lastSeen": to_iso(raw.get("lastSeenTimestamp") or raw.get("lastSeen")),
        "agentType": raw.get("agentType") or raw.get("installerType"),
        "environment": raw.get("environment"),
    }

def write_csv(path: str, rows: List[Dict]):
    headers = sorted({k for r in rows for k in r.keys()}) if rows else []
    with open(path, "w", newline="", encoding="utf-8") as f:
        if headers:
            w = csv.DictWriter(f, fieldnames=headers)
            w.writeheader()
            w.writerows(rows)

def write_json(path: str, rows: List[Dict]):
    with open(path, "w", encoding="utf-8") as f:
        json.dump(rows, f, ensure_ascii=False, indent=2)

def main():
    args = parse_args()
    session = make_session(args.api_token, args.verify, args.timeout)

    try:
        raw_items = list(fetch_oneagents(
            base_url=args.base_url,
            session=session,
            page_size=args.page_size
        ))
    except requests.HTTPError as e:
        print(f"[ERROR] HTTP {e.response.status_code}: {e.response.text}", file=sys.stderr)
        sys.exit(1)
    except requests.RequestException as e:
        print(f"[ERROR] Request failed: {e}", file=sys.stderr)
        sys.exit(2)

    rows = [normalize_record(x) for x in raw_items]

    if args.output.lower().endswith(".json"):
        write_json(args.output, rows)
    else:
        write_csv(args.output, rows)

    print(f"[OK] Exported {len(rows)} OneAgent records -&amp;gt; {args.output}")

if __name__ == "__main__":
    main()&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 10 Oct 2025 10:19:29 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/OneAgent-updateStatus-using-DQL/m-p/287612#M37763</guid>
      <dc:creator>t_pawlak</dc:creator>
      <dc:date>2025-10-10T10:19:29Z</dc:date>
    </item>
  </channel>
</rss>

