-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathworkflow_helper.yaml
336 lines (314 loc) · 11.2 KB
/
workflow_helper.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
---
workflows:
notify:
description: send chat message through chat system
meta:
inputs:
- name: chat_system
description: >
A system name that supports :code:`reply` and :code:`say` function, can be
either :code:`slack` or :code:`slack_bot`, by default :code:`slack_bot`.
- name: notify
description: >
A list of channels to which the message is beng sent, a special name :code:`reply`
means replying to the slashcommand user.
- name: notify_on_error
description: >
A list of additional channels to which the message is beng sent if the message_type is
error or failure.
- name: message_type
description: >
The type of the message used for coloring, could be :code:`success`, :code:`failure`,
:code:`error`, :code:`normal`, :code:`warning`, or :code:`announcement`
- name: chat_colors
description: >
A map from message_type to color codes. This should usually be defined in default context
so it can be shared.
- name: update
description: >
Set to true to update a previous message identified with :code:`ts`.
notes:
- This workflow wraps around :code:`say` and :code:`reply` method, and allows multiple recipients.
- For example
- example: |
---
workflows:
attention:
call_workflow: notify
with:
notify:
- "#honeydipper-notify"
- "#myteam"
notify_on_error:
- "#oncall"
message_type: $labels.status
message: "work status is {{ .labels.status }}"
on_error: exit
on_failure: exit
steps:
- if_match:
message_type:
- "error"
- "failure"
export:
notify+: $?ctx.notify_on_error
- call_workflow: channel_translate
with:
channel_names: $?ctx.notify
- if:
- $?ctx.channel_ids
iterate_parallel: $?ctx.channel_ids
iterate_as: channel_id
switch: $ctx.channel_id
cases:
"reply":
call_function: '{{ .ctx.chat_system }}.reply'
"add_response":
call_function: '{{ .ctx.chat_system }}.add_response'
default:
call_function: '{{ .ctx.chat_system }}.{{ empty .ctx.update |ternary "say" "update_message" }}'
export_on_failure: &slack_status_detail
status_detail: |
```
{{ .ctx.message | toJson }}
```
export_on_error: *slack_status_detail
no_export:
- notify
- channel_ids
workflow_announcement:
meta:
notes:
- This workflow sends announcement messages to the slack channels. It can be used in the hooks to
automatically announce the start of the workflow executions.
- example: |
---
workflows:
do_something:
with:
hooks:
on_first_action:
- workflow_announcement
steps:
- ...
- ...
call_workflow: notify
with:
message_type: announcement
message: $?ctx.event_announcement
message-: |-
An event is triggered for `{{ .ctx._meta_event }}` with id <{{ coalesce .ctx._event_url "https://honeydipper.io" }}|{{ coalesce .ctx._event_id "unspecified" }}>{{ with .ctx._event_detail }}
{{ . }}{{ end }}
message+: |
invoking workflow `{{ coalesce .ctx._meta_desc .ctx._meta_name .ctx.performing }}`
workflow_status:
meta:
notes:
- This workflow sends workflow status messages to the slack channels. It can be used in the hooks to
automatically announce the exit status of the workflow executions.
- example: |
---
workflows:
do_something:
with:
hooks:
on_exit:
- workflow_status
steps:
- ...
- ...
call_workflow: notify
with:
message_type: $labels.status
message: $?ctx.status_message
message-: |-
`{{ coalesce .ctx._meta_desc .ctx._meta_name "Unnamed workflow" }}` is completed with status `{{ .labels.status }}`
{{- if not (empty .ctx.links) }}
{{ range $k, $v := .ctx.links }}
{{- if ne $v.text "deleted" }}
• <{{ $v.url }}|{{ coalesce $v.text $k }}>
{{- end }}
{{- end }}
{{- end }}
{{ if ne .labels.status "success" }}
{{ printf "\nwhile performing `%s`\n" .labels.performing }}
```{{ if (gt (len .labels.reason) 512) }}
{{ printf "%s\n...skipped...\n%s" (trunc 256 .labels.reason) (substr (int (sub (len .labels.reason) 256)) -1 .labels.reason) }}
{{ else }}
{{ .labels.reason }}
{{ end }}```
{{ end }}
message+: $?ctx.status_detail
reload:
description: reload honeydipper config
meta:
inputs:
- name: force
description: >
If force is truy, Honeydipper will simply quit, expecting to be re-started by deployment manager.
notes:
- For example
- example: |
---
rules:
- when:
source:
system: slack_bot
trigger: slashcommand
do:
if_match:
command: reload
call_workflow: reload
with:
force: $?ctx.parameters
call_driver: redispubsub.send
with:
broadcastSubject: reload
data:
force: $?ctx.force
resume_workflow:
description: resume a suspended workflow
meta:
inputs:
- name: resume_token
description: >
Every suspended workflow has a :code:`resume_token`, use this to match the workflow to be resumed
- name: labels_status
description: >
Continue the workflow with a dipper message that with the specified status
- name: labels_reason
description: >
Continue the workflow with a dipper message that with the specified reason
- name: resume_payload
description: >
Continue the workflow with a dipper message that with the given payload
notes:
- For example
- example: |
---
rules:
- when:
source:
system: slack_bot
trigger: interact
do:
call_workflow: resume_workflow
with:
resume_token: $ctx.slack_payload.callback_id
labels_status: success
resume_payload: $ctx.slack_payload
call_driver: redispubsub.send
with:
broadcastSubject: resume_session
labels:
status: $ctx.labels_status
reason: $?ctx.labels_reason
data:
payload: $?ctx.resume_payload
key: $ctx.resume_token
snooze_alert:
description: snooze an alert
meta:
inputs:
- name: alert_system
description: >
The alert system used for monitoring, by default :code:`opsgenie`
- name: alert_Id
description: >
The Id of the alert, usually exported from the alert event
- name: duration
description: >
How long to snooze the alert for, using golang time format, by default :code:`20m`
notes:
- >
This workflow is just a wraper around the :code:`opsgenie.snooze` function. It also sends a
notification through chat to inform if the snoozing is success or not.
- For example
- example: |
---
rules:
- when:
source:
system: opsgenie
trigger: alert
do:
steps:
- call_workflow: snooze_alert
- call_workflow: do_something
if:
- $?ctx.alert_Id
on_error: continue
steps:
- call_function: '{{ .ctx.alert_system }}.snooze'
- call_workflow: notify
with:
message_type: $labels.status
message: |-
Snoozing `{{ .ctx.alert_system }}` alert <{{ coalesce .ctx.alert_url "./#" }}|#{{ coalesce .ctx.alert_Id "unspecified" }}> returns `{{ .labels.status }}`{{ if ne .labels.status "success" }}
```{{ .labels.reason }}```{{ end }}
send_heartbeat:
call_function: '{{ .ctx.alert_system }}.heartbeat'
description: sending heartbeat to alert system
meta:
inputs:
- name: alert_system
description: >
The alert system used for monitoring, by default :code:`opsgenie`
- name: heartbeat
description: >
The name of the heartbeat
notes:
- >
This workflow is just a wraper around the :code:`opsgenie.heartbeat` function.
channel_translate:
description: translate channel_names to channel_ids
meta:
inputs:
- name: channel_names
description: a list of channel names to be translated
- name: channel_maps
description: a map from channel names to ids
exports:
- name: channel_ids
description: a list of channel ids corresponding to the input names
notes:
- By pre-populating a map, we don't have to make API calls to slack everytime we need to convert a channel name to a ID.
- This is used by :code:`slashcommand` workflow and :code:`notify` workflow to automatically translate the names.
- example: |
---
workflows:
attention:
with:
channel_map:
'#private_channel1': UGKLASE
'#private_channel2': UYTFYJ2
'#private_channel3': UYUJH56
'#private_channel4': UE344HJ
'@private_user': U78JS2F
steps:
- call_workflow: channel_translate
with:
channel_names:
- '#private_channel1'
- '#private_channel3'
- '@private_user'
- '#public_channel1'
- call_workflow: loop_send_slack_message
# with:
# channel_ids:
# - UGKLASE
# - UYUJH56
# - U78JS2F
# - '#public_channel1' # remain unchanged if missing from the map
with:
translated: |-
:yaml:---
{{- range default (list) .ctx.channel_names | uniq }}
- "{{ if or (empty $.ctx.channel_map) (hasKey $.ctx.channel_map . | not) }}{{ . }}{{ else }}{{ index $.ctx.channel_map . }}{{ end }}"
{{- end }}
export:
channel_ids: |-
:yaml:---
{{- range default (list) .ctx.translated | uniq }}
- "{{ . }}"
{{- end }}