dt is a Python client for the Dynatrace Rest API.
It focuses on ease of use and nice type hints, perfect to explore the API and create quick scripts
Install
$ pip install dt
Simple Demo
fromdynatraceimportDynatracefromdynatraceimportTOO_MANY_REQUESTS_WAITfromdynatrace.environment_v2.tokens_apiimportSCOPE_METRICS_READ, SCOPE_METRICS_INGESTfromdatetimeimportdatetime, timedelta# Create a Dynatrace clientdt=Dynatrace("environment_url", "api_token")
# Create a client that handles too many requests (429)# dt = Dynatrace("environment_url", "api_token", too_many_requests_strategy=TOO_MANY_REQUESTS_WAIT )# Create a client that automatically retries on errors, up to 5 times, with a 1 second delay between retries# dt = Dynatrace("environment_url", "api_token", retries=5, retry_delay_ms=1000 )# Get all hosts and some propertiesforentityindt.entities.list('type("HOST")', fields="properties.memoryTotal,properties.monitoringMode"):
print(entity.entity_id, entity.display_name, entity.properties)
# Get idle CPU for all hostsformetricindt.metrics.query("builtin:host.cpu.idle", resolution="Inf"):
print(metric)
# Print dimensions, timestamp and values for the AWS Billing Metricformetricindt.metrics.query("ext:cloud.aws.billing.estimatedChargesByRegionCurrency"):
fordatainmetric.data:
fortimestamp, valueinzip(data.timestamps, data.values):
print(data.dimensions, timestamp, value)
# Get all ActiveGatesforagindt.activegates.list():
print(ag)
# Get metric descriptions for all host metricsformindt.metrics.list("builtin:host.*"):
print(m)
# Delete endpoints that contain the word testforpluginindt.plugins.list():
# This could also be dt.get_endpoints(plugin.id)forendpointinplugin.endpoints:
if"test"inendpoint.name:
endpoint.delete(plugin.id)
# Prints dashboard ID, owner and number of tilesfordashboardindt.dashboards.list():
full_dashboard=dashboard.get_full_dashboard()
print(full_dashboard.id, dashboard.owner, len(full_dashboard.tiles))
# Delete API Tokens that haven't been used for more than 3 monthsfortokenindt.tokens.list(fields="+lastUsedDate,+scopes"):
iftoken.last_used_dateandtoken.last_used_date<datetime.now() -timedelta(days=90):
print(f"Deleting token! {token}, last used date: {token.last_used_date}")
# Create an API Token that can read and ingest metricsnew_token=dt.tokens.create("metrics_token", scopes=[SCOPE_METRICS_READ, SCOPE_METRICS_INGEST])
print(new_token.token)
Implementation Progress
Environment API V2
API
Level
Access
Access Tokens - API tokens
✔️
dt.tokens
Access tokens - Tenant tokens
✔️
dt.tenant_tokens
ActiveGates
✔️
dt.activegates
ActiveGates - Auto-update configuration
✔️
dt.activegates_autoupdate_configuration
ActiveGates - Auto-update jobs
✔️
dt.activegates_autoupdate_jobs
Audit Logs
✔️
dt.audit_logs
Extensions 2.0
✔️
dt.extensions_v2
Logs
⚠️
dt.logs
Metrics
✔️
dt.metrics
Monitored entities
⚠️
dt.entities
Monitored entities - Custom tags
✔️
dt.custom_tags
Network zones
❌
Problems
✔️
dt.problems
Security problems
❌
Service-level objectives
✔️
dt.slos
Environment API V1
API
Level
Access
Anonymization
❌
Cluster time
✔️
dt.time
Cluster version
❌
Deployment
✔️
dt.deployment
Events
⚠️
dt.events
JavaScript tag management
❌
Log monitoring - Custom devices
❌
Log monitoring - Hosts
❌
Log monitoring - Process groups
❌
Maintenance window
❌
OneAgent on a host
❌
Problem
❌
Synthetic - Locations and nodes
❌
Synthetic - Monitors
⚠️
dt.synthetic_monitors
Synthetic - Third party
✔️
dt.third_part_synthetic_tests
Threshold
❌
Timeseries
⚠️
dt.timeseries
Tokens
❌
Topology & Smartscape - Application
❌
Topology & Smartscape - Custom device
⚠️
dt.custom_devices
Topology & Smartscape - Host
⚠️
Topology & Smartscape - Process
❌
Topology & Smartscape - Process group
❌
Topology & Smartscape - Service
❌
User sessions
❌
Configuration API V1
API
Level
Access
Alerting Profiles
❌
Anomaly detection - Applications
❌
Anomaly detection - AWS
❌
Anomaly detection - Database services
❌
Anomaly detection - Disk events
❌
Anomaly detection - Hosts
❌
Anomaly detection - Metric events
❌
Anomaly detection - Process groups
❌
Anomaly detection - Services
❌
Anomaly detection - VMware
❌
Automatically applied tags
⚠️
AWS credentials configuration
❌
AWS PrivateLink
❌
Azure credentials configuration
❌
Calculated metrics - Log monitoring
❌
Calculated metrics - Mobile & custom applications
❌
Calculated metrics - Services
❌
Calculated metrics - Synthetic
❌
Calculated metrics - Web applications
❌
Cloud Foundry credentials configuration
❌
Conditional naming
❌
Credential vault
❌
Dashboards
⚠️
dt.dashboards
Data privacy and security
❌
Extensions
✔️
dt.extensions
Frequent issue detection
❌
Kubernetes credentials configuration
❌
Maintenance windows
❌
Management zones
⚠️
Notifications
⚠️
dt.notifications
OneAgent - Environment-wide configuration
✔️
dt.oneagents_config_environment
OneAgent in a host group
✔️
dt.oneagents_config_hostgroup
OneAgent on a host
✔️
dt.oneagents_config_host
Plugins
⚠️
dt.plugins
Remote environments
❌
Reports
❌
RUM - Allowed beacon origins for CORS
❌
RUM - Application detection rules
❌
RUM - Application detection rules - Host detection
❌
RUM - Content resources
❌
RUM - Geographic regions - custom client IP headers
❌
RUM - Geographic regions - IP address mapping
❌
RUM - Mobile and custom application configuration
❌
RUM - Web application configuration
❌
Service - Custom services
❌
Service - Detection full web request
❌
Service - Detection full web service
❌
Service - Detection opaque and external web request
❌
Service - Detection opaque and external web service