-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdynatrace_eda_workflow.yaml
181 lines (157 loc) · 6.1 KB
/
dynatrace_eda_workflow.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
metadata:
version: "1"
dependencies:
apps:
- id: dynatrace.automations
version: ^1.762.0
- id: dynatrace.redhat.ansible
version: ^0.3.2
inputs:
- type: connection
schema: app:dynatrace.redhat.ansible:eda-webhook.connection
targets:
- tasks.send_event_to_event-driven-ansible_1.connectionId
workflow:
title: Shadowman EDA Workflow
tasks:
merge_problem_data:
name: merge_problem_data
description: Build a custom task running js Code
action: dynatrace.automations:run-javascript
input:
script: |-
import { execution } from '@dynatrace-sdk/automation-utils';
export default async function ({ execution_id }) {
// your code goes here
// e.g. get the current execution
const ex = await execution(execution_id);
console.log('Automated script execution on behalf of', ex.trigger);
const problems = await ex.result("get_problem_details");
console.log(problems);
const obj1 = problems.eventInfo;
console.log(obj1);
let result = Object.assign(obj1)
console.log(result);
return result;
}
position:
x: 0
y: 2
predecessors:
- get_problem_details
conditions:
states:
get_problem_details: OK
get_problem_details:
name: get_problem_details
description: Build a custom task running js Code
action: dynatrace.automations:run-javascript
input:
script: >-
import { executionsClient } from '@dynatrace-sdk/client-automation';
import { problemsClient } from '@dynatrace-sdk/client-classic-environment-v2';
import { monitoredEntitiesClient } from '@dynatrace-sdk/client-classic-environment-v2';
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
export default async function ({ execution_id }) {
var retries = 0
// get the current execution
const ex = await executionsClient.getExecution({ id: execution_id });
console.log(`Problem ${ex.params.event['event.id']}.`)
if(!'event' in ex.params) { return { problem: null, affected_entities: [] } }
console.log("Loading Problem details...")
var probEvent = ex.params.event
var problem_request = {
problemId: probEvent['event.id'],
fields: 'recentComments'
}
var problem = await problemsClient.getProblem(problem_request);
console.log(`Problem ${problem.displayId} affects ${problem.impactedEntities.length} entities.`)
while (problem.impactedEntities.length == 0 && retries <= 10) {
console.log("No affected entities")
console.log("Waiting 5 seconds and then checking again")
await sleep(5000)
problem = await problemsClient.getProblem(problem_request)
console.log(`Problem ${problem.displayId} affects ${problem.impactedEntities.length} entities.`)
retries += 1
}
if (problem.impactedEntities.length > 0) {
//// load affected entities
var iE =problem.impactedEntities[0].entityId.id;
var entity_selector = `entityId("${iE}")`;
var entities_request = {
entitySelector: entity_selector,
fields: "+tags,+fromRelationships,+toRelationships"
}
console.log(`Entities ${entities_request}`)
var entities = await monitoredEntitiesClient.getEntities(entities_request);
} else { var entities = [] }
// Creating distributable information
var eventInfo = {
problemTitle: problem.title,
problemStatus: problem.status,
problemId: problem.displayId,
problemArea: problem.impactLevel,
problemLevel: problem.severityLevel,
impactedEntitiesId: problem.impactedEntities,
eventId: probEvent['event.id']
}
return {
entities,
eventInfo
};
}
position:
x: 0
y: 1
predecessors: []
send_event_to_event-driven-ansible_1:
name: send_event_to_event-driven-ansible_1
description: Send an event to the Red Hat Event-Driven-Ansible Controller via
Event Source Plugin
action: dynatrace.redhat.ansible:send-event-to-eda
input:
eventData: '{{ result("merge_problem_data") }}'
connectionId: ""
position:
x: 0
y: 3
predecessors:
- merge_problem_data
conditions:
states:
merge_problem_data: OK
description: ""
trigger:
eventTrigger:
filterQuery: >-
event.kind == "DAVIS_PROBLEM" AND event.status == "ACTIVE" AND
(event.status_transition == "CREATED" OR event.status_transition ==
"UPDATED" OR event.status_transition == "REOPENED") AND (event.category
== "ERROR" OR event.category == "RESOURCE_CONTENTION") AND
(maintenance.is_under_maintenance == false and
event.status_transition =="CREATED"
AND isNotNull(affected_entity_ids)
AND matchesPhrase(entity_tags,"shadowman")
)
isActive: true
uniqueExpression: '{{ event()["event.id"] }}-{{ "open" if
event()["event.status_transition"] in ("CREATED", "UPDATED", "REOPENED",
"REFRESHED") else "resolved" }}-{{
event()["dt.davis.last_reopen_timestamp"] }}'
triggerConfiguration:
type: davis-problem
value:
categories:
error: true
resource: true
entityTags: {}
customFilter: |+
maintenance.is_under_maintenance == false and
event.status_transition =="CREATED"
AND isNotNull(affected_entity_ids)
AND matchesPhrase(entity_tags,"shadowman")
onProblemClose: false
entityTagsMatch: all
schemaVersion: 3