Example unix shell scripts related to problems and logs.
- Copy the
.env-templateto.env - Make a Dyantrace API token and set the Dynatrace URL Token in
.envfile.- API v2 scopes
Ingest eventsRead problemsWrite problems
- API v1 scopes
Access problem and event feed, metrics, and topology
- API v2 scopes
Add a Javascript task with this code and modify as required for you needs. Refer to Dynatrace developer docs for more details on the SDK.
import { EventIngest, EventIngestEventType, eventsClient } from '@dynatrace-sdk/client-classic-environment-v2';
export default async function () {
const now = new Date();
const terminationEvent: EventIngest = {
eventType: EventIngestEventType.CustomAlert,
title: 'Test Problem - ' + now.toLocaleTimeString(),
properties: { 'Triggered by': 'Workflow' },
entitySelector: 'type(SERVICE),entityName.equals(OrderController)',
};
return await eventsClient.createEvent({ body: terminationEvent });
}
Use this script to send an event to one or more entities.
For an overview of Dynatrace events types, review Categories of Davis events
help docs.
Running script
./pushevent.sh PERFORMANCE_EVENT "type(SERVICE),entityName.equals(OrderController)"
Within Dynatrace view the problem in the problems app on in a notebook with DQL
Use this script to get the details for a problem.
The script passing the optional querystring parameters to get more details about the problem.
$DT_BASEURL/api/v2/problems/$DT_PROBLEM_ID?evidenceDetails,impactAnalysis,recentComments
Running script and formatting output with jq utility.
./getproblem.sh -3923117663478183459_1752459060000V2 | jq '.'
This script can be used to quickly close out an open problem.
From the URL within Dynatrace you get obtain the Problem ID. For example: -7079974447799175602_1752266005311V2
Running script:
./closeproblem.sh 5194648246915255341_1752457020268V2
Within Dynatrace there view the problem and review that it is closed.
Use this script to send a log line For an overview of Dynatrace log ingest API, review Dynatrace docs
Running script
./pushlog.sh
Within Dynatrace view the log in the logs app.