Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dynatrace-api-tools

A collection of Python CLI utilities for interacting with the Dynatrace API — covering Grail DQL queries, EF2.0 extension health, OpenPipeline SDLC event ingestion, Management Zone coverage auditing, and Monaco configuration drift detection.

Built for use in real Dynatrace environments. All scripts use environment variables for credentials and are safe to commit to public repos.


Scripts

Script Description
dql_runner.py Execute parameterized DQL queries against the Grail API
extension_health_checker.py Audit EF2.0 extension versions and monitoring config state
openpipeline_event_pusher.py Push structured SDLC events (deploy, build, test) via BizEvents
mz_coverage_reporter.py Identify entities not covered by any Management Zone
monaco_auditor.py Detect drift between a Monaco project and the live environment

Setup

# Clone and install dependencies
git clone https://github.com/EntropicSage/dynatrace-api-tools.git
cd dynatrace-api-tools
pip install -r requirements.txt

# Configure credentials
cp .env.example .env
# Edit .env with your environment URL and API token

Required API Token Scopes

Script Required Scopes
dql_runner.py storage:logs:read, storage:metrics:read, storage:bizevents:read
extension_health_checker.py extensions.read
openpipeline_event_pusher.py bizevents.ingest
mz_coverage_reporter.py entities.read, settings.read
monaco_auditor.py settings.read

Usage

DQL Runner

Execute any DQL query interactively or from a file. Handles Grail's async poll pattern automatically.

# Run a query inline
python scripts/dql_runner.py --query "fetch logs | filter loglevel == \"ERROR\" | limit 20"

# Run from a .dql file, output as CSV
python scripts/dql_runner.py --file queries/slow_traces.dql --format csv --output results.csv

# Output as JSON
python scripts/dql_runner.py --query "fetch dt.entity.service | limit 10" --format json

Extension Health Checker

Audit all installed EF2.0 extensions — version state, environment activation, and monitoring config counts.

# Check all extensions
python scripts/extension_health_checker.py

# Filter to custom extensions only
python scripts/extension_health_checker.py --filter "custom:"

# Check a single extension
python scripts/extension_health_checker.py --extension com.dynatrace.extension.cisco-ucs-redfish

# Export as JSON
python scripts/extension_health_checker.py --format json --output ext_health.json

Example output:

┌──────────────────────────────────────┬───────────┬───────────┬─────────┬────────────┬─────────┬────────┐
│ Extension                            │ Installed │ Latest    │ Outdated│ Env Active │ Configs │ Active │
├──────────────────────────────────────┼───────────┼───────────┼─────────┼────────────┼─────────┼────────┤
│ custom:cisco-ucs-redfish             │ 1.2.1     │ 1.2.3     │ YES     │ yes        │ 4       │ 4      │
│ com.dynatrace.extension.snmp         │ 2.1.0     │ 2.1.0     │ no      │ yes        │ 12      │ 11     │
└──────────────────────────────────────┴───────────┴───────────┴─────────┴────────────┴─────────┴────────┘
  1 extension(s) running below latest version.

OpenPipeline Event Pusher

Push structured SDLC events into Dynatrace as BizEvents, compatible with OpenPipeline routing rules.

# Push a deployment event
python scripts/openpipeline_event_pusher.py deployment \
    --service payment-api \
    --version 2.3.1 \
    --stage production \
    --pipeline "azure-devops" \
    --triggered-by "CI/CD" \
    --status success

# Push a build event
python scripts/openpipeline_event_pusher.py build \
    --service payment-api \
    --version 2.3.1 \
    --status success

# Push test results
python scripts/openpipeline_event_pusher.py test \
    --service payment-api \
    --version 2.3.1 \
    --test-suite integration \
    --passed 142 \
    --failed 0

# Dry run (prints payload without sending)
python scripts/openpipeline_event_pusher.py deployment \
    --service my-svc --version 1.0.0 --dry-run

# Push a pre-built event JSON file
python scripts/openpipeline_event_pusher.py from-file event.json

Events follow CloudEvents 1.0 spec with sdlc.* type prefixes for clean OpenPipeline rule targeting.


Management Zone Coverage Reporter

Find entities that aren't included in any Management Zone — useful for governance audits.

# Check all supported entity types
python scripts/mz_coverage_reporter.py

# Check only services
python scripts/mz_coverage_reporter.py --entity-type SERVICE

# Export uncovered hosts to JSON
python scripts/mz_coverage_reporter.py --entity-type HOST --format json --output uncovered_hosts.json

Supported entity types: SERVICE, HOST, PROCESS_GROUP, APPLICATION, SYNTHETIC_TEST, CLOUD_APPLICATION, KUBERNETES_CLUSTER


Monaco Auditor

Compare a local Monaco (Configuration as Code) project against the live Dynatrace environment and report configuration drift.

# Audit an entire Monaco project
python scripts/monaco_auditor.py --project ./monaco-project

# Audit a specific schema only
python scripts/monaco_auditor.py --project ./monaco-project --schema builtin:alerting.profile

# Export drift report as JSON
python scripts/monaco_auditor.py --project ./monaco-project --format json --output drift.json

Example output:

┌──────────────────────────────────┬────────┬───────┬──────┬────────────────┬───────────────┐
│ Schema                           │ Status │ Local │ Live │ Only in Monaco │ Only in Live  │
├──────────────────────────────────┼────────┼───────┼──────┼────────────────┼───────────────┤
│ builtin:alerting.profile         │ OK     │ 5     │ 5    │ none           │ none          │
│ builtin:management-zones         │ DRIFT  │ 8     │ 10   │ none           │ legacy-zone-1 │
│                                  │        │       │      │                │ temp-mz-2023  │
└──────────────────────────────────┴────────┴───────┴──────┴────────────────┴───────────────┘

Summary: 1 schema(s) in sync, 1 schema(s) with drift

Project Structure

dynatrace-api-tools/
├── scripts/
│   ├── dql_runner.py
│   ├── extension_health_checker.py
│   ├── openpipeline_event_pusher.py
│   ├── mz_coverage_reporter.py
│   └── monaco_auditor.py
├── utils/
│   └── dt_client.py          # Shared API client (auth, retry, rate limiting)
├── .env.example
├── requirements.txt
└── README.md

Environment Variables

Variable Description
DT_ENV_URL Your Dynatrace environment URL (e.g. https://abc12345.live.dynatrace.com)
DT_API_TOKEN Dynatrace API token with required scopes (see table above)

License

MIT

About

Python CLI utilities for the Dynatrace API — Grail DQL, EF2.0 extension health, OpenPipeline events, Management Zone coverage, Monaco drift detection

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages