-
Notifications
You must be signed in to change notification settings - Fork 0
/
dt-api-alerting-profile.yml
203 lines (203 loc) · 6.9 KB
/
dt-api-alerting-profile.yml
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# create dynatrace alerting profile with management zone
# host_name -> target host to execute playbook
# dt_config_api_endpoint -> dynatrace configuration api endpoint (include trailing /)
# dt_api_token -> dynatrace api token with read & write access
# dt_mz_name -> name of existing dynatrace management zone (used to name alerting profile)
# dt_mz_64id -> unique 64 bit integer id of existing management zone
# dt_ap_uuid -> unique UUID to assign new alerting profile
# dt_notification_name -> name to assign dynatrace email notification
# dt_notification_uuid -> unique UUID id to assign dynatrace email notification
# dt_email_receiver -> email address for to: recipients
---
-
hosts: "{{ host_name }}"
name: "create dynatrace alerting profile with management zone"
tasks:
-
name: "generate alerting profile uuid"
set_fact:
dt_ap_uuid: "{{ 9999999999999999999999 | random | to_uuid }}"
when: dt_ap_uuid is undefined
-
name: "validate alerting profile uuid is available"
uri:
url: "{{ dt_config_api_endpoint }}alertingProfiles?Api-Token={{ dt_api_token }}"
method: GET
return_content: yes
status_code: 200
register: existing_ap
failed_when: 'dt_ap_uuid|string in existing_ap.content'
-
name: "generate notification uuid"
set_fact:
dt_notification_uuid: "{{ 9999999999999999999999 | random | to_uuid }}"
when: dt_notification_uuid is undefined
-
name: "validate notification UUID is available"
uri:
url: "{{ dt_config_api_endpoint }}notifications?Api-Token={{ dt_api_token }}"
method: GET
return_content: yes
status_code: 200
register: existing_notifications
failed_when: 'dt_notification_uuid|string in existing_notifications.content'
-
name: "validate management zone 64 bit id exists"
uri:
url: "{{ dt_config_api_endpoint }}managementZones?Api-Token={{ dt_api_token }}"
method: GET
return_content: yes
status_code: 200
register: existing_mz
failed_when: 'dt_mz_64id|string not in existing_mz.content'
-
name: "validate alerting profile payload"
uri:
url: "{{ dt_config_api_endpoint }}alertingProfiles/validator?Api-Token={{ dt_api_token }}"
method: POST
body:
displayName: "{{ dt_mz_name }}"
rules:
- severityLevel: ERROR
tagFilter:
includeMode: NONE
delayInMinutes: 15
- severityLevel: PERFORMANCE
tagFilter:
includeMode: NONE
delayInMinutes: 15
- severityLevel: RESOURCE_CONTENTION
tagFilter:
includeMode: NONE
delayInMinutes: 15
- severityLevel: CUSTOM_ALERT
tagFilter:
includeMode: NONE
delayInMinutes: 0
- severityLevel: MONITORING_UNAVAILABLE
tagFilter:
includeMode: NONE
delayInMinutes: 0
- severityLevel: AVAILABILITY
tagFilter:
includeMode: NONE
delayInMinutes: 0
managementZoneId: "{{ dt_mz_64id }}"
eventTypeFilters: []
body_format: json
status_code: 204
return_content: yes
register: new_ap
-
name: "create alerting profile"
uri:
url: "{{ dt_config_api_endpoint }}alertingProfiles/{{ dt_ap_uuid }}?Api-Token={{ dt_api_token }}"
method: PUT
body:
id: "{{ dt_ap_uuid }}"
displayName: "{{ dt_mz_name }}"
rules:
- severityLevel: ERROR
tagFilter:
includeMode: NONE
delayInMinutes: 15
- severityLevel: PERFORMANCE
tagFilter:
includeMode: NONE
delayInMinutes: 15
- severityLevel: RESOURCE_CONTENTION
tagFilter:
includeMode: NONE
delayInMinutes: 15
- severityLevel: CUSTOM_ALERT
tagFilter:
includeMode: NONE
delayInMinutes: 0
- severityLevel: MONITORING_UNAVAILABLE
tagFilter:
includeMode: NONE
delayInMinutes: 0
- severityLevel: AVAILABILITY
tagFilter:
includeMode: NONE
delayInMinutes: 0
managementZoneId: "{{ dt_mz_64id }}"
eventTypeFilters: []
body_format: json
status_code: 201
return_content: yes
register: new_ap
-
name: "convert response to json object"
set_fact:
new_ap_json: "{{ new_ap.content | from_json }}"
-
name: "obtain ap uuid from json object"
set_fact:
dt_new_ap_uuid: "{{ new_ap_json.id }}"
-
name: "validate alerting profile uuid exists"
uri:
url: "{{ dt_config_api_endpoint }}alertingProfiles?Api-Token={{ dt_api_token }}"
method: GET
return_content: yes
status_code: 200
register: existing_ap
failed_when: 'dt_new_ap_uuid|string not in existing_ap.content'
-
name: "validate notification rule payload"
uri:
url: "{{ dt_config_api_endpoint }}notifications/validator?Api-Token={{ dt_api_token }}"
method: POST
body:
type: EMAIL
name: "{{ dt_notification_name }}"
alertingProfile: "{{ dt_new_ap_uuid }}"
active: true
subject: "{State} Problem {ProblemID}: {ImpactedEntity}"
body: "{ProblemDetailsHTML}"
receivers:
- "{{ dt_email_receiver }}"
ccReceivers: []
shouldSendForResolvedProblems: true
body_format: json
status_code: 204
return_content: yes
register: new_notification
-
name: "create notification rule"
uri:
url: "{{ dt_config_api_endpoint }}notifications/{{ dt_notification_uuid }}?Api-Token={{ dt_api_token }}"
method: PUT
body:
id: "{{ dt_notification_uuid }}"
type: EMAIL
name: "{{ dt_notification_name }}"
alertingProfile: "{{ dt_new_ap_uuid }}"
active: true
subject: "{State} Problem {ProblemID}: {ImpactedEntity}"
body: "{ProblemDetailsHTML}"
receivers:
- "{{ dt_email_receiver }}"
ccReceivers: []
shouldSendForResolvedProblems: true
body_format: json
status_code: 201
return_content: yes
register: new_notification
-
name: "convert response to json object"
set_fact:
new_notification_json: "{{ new_notification.content | from_json }}"
-
name: "obtain notification uuid from json object"
set_fact:
dt_new_notification_uuid: "{{ new_notification_json.id }}"
-
name: "output alerting profile uuid"
debug:
msg: "{{ dt_new_ap_uuid }}"
-
name: "output notification uuid"
debug:
msg: "{{ dt_new_notification_uuid }}"