Skip to content

Latest commit

 

History

History
220 lines (161 loc) · 9.97 KB

workflows.md

File metadata and controls

220 lines (161 loc) · 9.97 KB

Workflows

Dynatrace Automation workflows let you orchestrate multi-step processes, from scheduled health checks to incident remediation. dtctl gives you full lifecycle management: list, inspect, create, edit, execute, and monitor workflows and their executions from your terminal.

dtctl docs / Resources / Workflows

Supported operations

Operation Resource Command syntax Description Mutating Access
create scheduling-rule dtctl create scheduling-rule Create resources from files yes write
delete scheduling-rule dtctl delete scheduling-rule Delete resources yes delete
describe scheduling-rule dtctl describe scheduling-rule Show details of a specific resource no read
get scheduling-rules dtctl get scheduling-rules Display one or many resources no read
create workflow dtctl create workflow Create resources from files yes write
delete workflow dtctl delete workflow Delete resources yes delete
describe workflow dtctl describe workflow Show details of a specific resource no read
edit workflow dtctl edit workflow Edit a resource yes write
exec workflow dtctl exec workflow Execute workflows, functions, analyzers, SLOs, and code-level profiling yes run
get workflows dtctl get workflows Display one or many resources no read
history workflow dtctl history workflow Show version history of resources no read
restore workflow dtctl restore workflow Restore resources to a previous version yes write
describe workflow-execution dtctl describe workflow-execution Show details of a specific resource no read
get workflow-executions dtctl get workflow-executions Display one or many resources no read
logs workflow-execution dtctl logs workflow-execution Print logs for resources no read
get workflow-execution-task-result dtctl get workflow-execution-task-result Display one or many resources no read

Flags

These commands take dtctl's global flags (-o/--output, --context, --jq, -v, and more). Some verbs add their own flags (apply, diff, query, inventory); see the verb in COMMANDS.md. Individual commands may take further flags of their own — run dtctl <verb> <resource> --help for the authoritative list.

Required token scopes

Safety level Scopes
delete automation:rules:read, automation:rules:write
read automation:rules:read, automation:workflows:read
run automation:workflows:run
write automation:rules:write, automation:workflows:write

Output

get workflows prints a compact table by default; -o wide adds owner, trigger type, and last-run columns. -o json/-o yaml return the full resource for scripting. describe workflow shows metadata (owner, sharing, version), a task summary, and the workflow's URL in Dynatrace. describe workflow-execution shows status, timing, and a per-task breakdown.

Examples

# List all workflows (compact table)
dtctl get workflows

# Wide output with additional columns (owner, trigger type, last run)
dtctl get workflows -o wide

# Output as JSON or YAML for scripting
dtctl get workflows -o json

# Watch for changes in real time
dtctl get workflows --watch

# Filter by type (standard or simple) or title
dtctl get workflows --type simple
dtctl get workflows --search deploy

# Executions of one workflow, in one state (RUNNING, SUCCESS, ERROR, CANCELLED, UNKNOWN)
dtctl get workflow-executions --workflow workflow-123 --state ERROR

An unknown --type, --state or --trigger value is a usage error that lists the permitted values. List filters (--type, --mine, --state, ...) cannot be combined with an id.

Inspect a single workflow by name (interactive disambiguation if multiple match) or by ID:

dtctl describe workflow "My Workflow"
dtctl describe workflow workflow-123

Edit a workflow in your $EDITOR — dtctl downloads the current definition, opens it, and applies the diff on save (similar to kubectl edit):

dtctl edit workflow workflow-123

Create from a YAML file, or apply for idempotent create-or-update:

# Create (fails if the workflow already exists)
dtctl create workflow -f my-workflow.yaml

# Apply (creates if new, updates if existing)
dtctl apply -f my-workflow.yaml

# First apply: stamp the generated ID back into the file so future applies update in place
dtctl apply -f my-workflow.yaml --write-id

# CI/scripting: apply a template to a specific known workflow
dtctl apply -f my-workflow.yaml --id $WORKFLOW_ID

Trigger an execution and view its results:

# Run and wait for completion (the default)
dtctl exec workflow workflow-123

# Pass input as a JSON object, then show task results when it finishes
dtctl exec workflow workflow-123 --input '{"env":"prod"}' --show-results

# Fire and forget: return the execution ID immediately
dtctl exec workflow workflow-123 --no-wait

# List recent executions, or the short alias
dtctl get workflow-executions
dtctl get wfe

# Describe a specific execution, and stream its logs
dtctl describe wfe exec-456
dtctl logs wfe exec-456 --follow

# Retrieve the output of one task within an execution
dtctl get workflow-execution-task-result exec-456 --task my_task -o json

dtctl logs wfe <id> --tasks and --all print every task log they can fetch. If a task log cannot be fetched, the command marks it inline, names the failed tasks on stderr, and exits non-zero. A single missing (404) task log does not fail the command when other task logs were fetched. With --follow, a failed fetch prints a warning and streaming continues; the command exits non-zero only if a task log is still missing after the execution has finished. Status lines and "No logs available." go to stderr, so stdout carries only log text. In agent mode the result is {"log": "..."} (with --tasks/--all, "tasks": [{"name", "state", "log"}], and an error field on a task whose log could not be fetched), and --follow is a usage error.

View and restore version history:

dtctl history workflow workflow-123
dtctl restore workflow workflow-123 5

Delete a workflow (permanent; dtctl prompts for confirmation in interactive mode, use --plain to skip it in CI):

dtctl delete workflow workflow-123

Notes

Act on workflows you don't own

The Automation API only lets you change a workflow you own or that was shared with you, whatever dtctl's safety level. An administrator can use Workflow admin mode, as in the Workflows app, by passing --admin-access. It works with get, describe, edit, delete, history and restore workflow, the workflow-execution commands, and apply:

dtctl get workflow <workflow-id> --admin-access
dtctl apply -f workflow.yaml --admin-access

The token needs the automation:workflows:admin scope, and the tenant's IAM policy needs the automation:workflows:admin permission. dtctl auth login requests the scope at the readwrite-all and dangerously-unrestricted safety levels; log in again if your session predates it.

Example workflow definition

A workflow file combines a schedule trigger with one or more tasks. This example runs a script every morning and posts the result to Slack:

title: Daily Health Check
description: Runs a health check every morning and posts results to Slack
owner: Operations
trigger:
  schedule:
    rule: "0 8 * * *"   # Every day at 08:00 UTC
    timezone: UTC
    isActive: true
tasks:
  check_health:
    name: check_health
    action: dynatrace.automations:run-javascript
    description: Run health check script
    input:
      script: |
        import { execution } from '@dynatrace-sdk/automation-utils';
        export default async function ({ executionId }) {
          const exe = await execution(executionId);
          const params = exe.params;
          console.log(`Running health check for env: ${params.env || 'default'}`);
          return { status: 'healthy', checkedAt: new Date().toISOString() };
        }
    position:
      x: 0
      y: 1
  notify_slack:
    name: notify_slack
    action: dynatrace.slack:slack-send-message
    description: Post results to Slack
    input:
      channel: "#ops-alerts"
      message: "Health check completed: {{ result('check_health').status }}"
    conditions:
      states:
        check_health: OK
    position:
      x: 0
      y: 2

Executions and task results

exec workflow waits until the execution reaches a terminal state (success, error, or cancelled), bounded by --timeout (default 30m). The exit code reflects the result: it is non-zero when the execution ends in error, is cancelled, or the timeout expires. Add --show-results to print the output of each task once the execution finishes. --no-wait returns the execution ID immediately; earlier releases did this by default, so scripts that start a workflow and move on need --no-wait.

Simple workflows expose execution details only for runs started with monitoring, and dtctl requests monitoring only when it waits. For a simple workflow started with --no-wait, get wfe, logs wfe and task results are not available.

Watch mode

dtctl get workflows --watch highlights additions, modifications, and deletions to workflows as they happen. Press Ctrl+C to stop watching.

Troubleshooting

If you forget --write-id on the first apply and a duplicate workflow gets created, recover without creating another duplicate by re-running apply with both --write-id and the ID from the first run:

dtctl apply -f my-workflow.yaml --write-id --id <id-from-first-run>