-
Notifications
You must be signed in to change notification settings - Fork 9
/
opsgenie.yaml
433 lines (398 loc) · 15.2 KB
/
opsgenie.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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
---
systems:
opsgenie:
description: |
This system enables Honeydipper to integrate with `opsgenie`, so Honeydipper can
react to opsgenie alerts and take actions through opsgenie API.
meta:
configurations:
- name: API_KEY
description: The API key used for making API calls to `opsgenie`
- name: token
description: >
A token used for authenticate incoming webhook requests, every webhook request
must carry a form field **Token** in the post body or url query that matches the value
- name: path
description: The path portion of the webhook url, by default :code:`/opsgenie`
notes:
- For example
- example: |
---
systems:
opsgenie:
data:
API_KEY: ENC[gcloud-kms,...masked...]
token: ENC[gcloud-kms,...masked...]
path: "/webhook/opsgenie"
- Assuming the domain name for the webhook server is :code:`myhoneydipper.com', you should
configure the webhook in your opsgenie integration with url like below
- |
.. code-block::
https://myhoneydipper.com/webhook/opsgenie?token=...masked...
data:
API_KEY: _place_holder_
token: _place_holder_
path: "/opsgenie"
functions:
snooze:
driver: web
rawAction: request
parameters:
URL: https://api.opsgenie.com/v2/alerts/{{ .ctx.alert_Id }}/snooze?identifierType=tiny
header:
Content-Type: application/json; charset=utf-8
Authorization: GenieKey {{ .sysData.API_KEY }}
method: POST
content:
endTime: '{{ now.UTC.Add ( duration (default "+20m" .ctx.duration) ) | ISO8601 }}'
user: honeydipper
source: honeydipper
notes: snoozed due to honeydipper automation
retry: 2
export:
result: $data.json.result
description: >
This function will snooze the alert with given alert ID.
meta:
inputs:
- name: alert_Id
description: The ID of the alert to be snoozed
- name: duration
description: For how long the alert should be snoozed, use golang time format
exports:
- name: result
description: The return result of the API call
notes:
- See below for example
- example: |
---
rules:
- when:
source:
system: opsgenie
trigger: alert
do:
if_match:
alert_message: :regex:test-alert
call_function: opsgenie.snooze
# alert_Id is exported from the event
schedules:
driver: web
rawAction: request
parameters:
URL: https://api.opsgenie.com/v2/schedules{{ with .ctx.scheduleId }}/{{ . }}?identifierType={{ default "name" $.ctx.scheduleIdType }}{{ end }}
method: GET
header:
Authorization: GenieKey {{ .sysData.API_KEY }}
form:
limit: "100"
retry: 2
export:
schedule: $data.json.data
schedules: $data.json.data
meta:
description:
- This function list all on-call schedules or fetch a schedule detail if given a schedule identifier.
- highlight: This function only fetches first 100 schedules when listing.
type: important
inputs:
- name: scheduleId
description: The name or ID or the schedule of interest; if missing, list all schedules.
- name: scheduleIdType
description: The type of the identifier, :code:`name` or :code:`id`.
exports:
- name: schedule
description: For fetching detail, the data structure that contains the schedule detail
- name: schedules
description: For listing, a list of data structure contains the schedule details
notes:
- See below for example
- example: |
---
workflows:
steps:
- call_function: opsgenie.schedules
whoisoncall:
driver: web
rawAction: request
parameters:
URL: https://api.opsgenie.com/v2/schedules/{{ .ctx.scheduleId }}/on-calls
method: GET
header:
Authorization: GenieKey {{ .sysData.API_KEY }}
form:
identifierType: $ctx.scheduleIdType,"name"
flat: $ctx.flat,"true"
retry: 2
export:
result: $data.json.data
meta:
description:
- This function gets the current on-call persons for the given schedule.
- highlight: Use the `opsgenie_whoisoncall`_ workflow instead.
type: important
inputs:
- name: scheduleId
description: The name or ID or the schedule of interest, required
- name: scheduleIdType
description: The type of the identifier, :code:`name` or :code:`id`.
- name: flat
description: If true, will only return the usernames, otherwise, will return all including notification, team etc.
exports:
- name: result
description: the data portion of the json payload.
notes:
- See below for example
- example: |
---
workflows:
steps:
- call_function: opsgenie.whoisoncall
with:
scheduleId: sre_schedule
users:
driver: web
rawAction: request
parameters:
URL: https://api.opsgenie.com/v2/users{{ with .ctx.userId }}/{{ . }}{{ end }}
method: GET
header:
Authorization: GenieKey {{ .sysData.API_KEY }}
form:
offset: $ctx.opsgenie_offset,"0"
query: $ctx.query,""
order: $ctx.order,"asc"
sort: $ctx.sort,""
retry: 2
export:
user: $data.json.data
users+: $data.json.data
opsgenie_offset: '{{ with .data.json.paging }}{{ with .next }}{{ splitList "offset=" . | rest | first | splitList "&" | first }}{{ end }}{{ end }}'
meta:
description:
- This function gets the user detail with a given ID or list all users
inputs:
- name: userId
description: The ID of the user for which to get details; if missing, list users
- name: offset
description: Number of users to skip from start, used for paging
- name: query
description: >-
:code:`Field:value` combinations with most of user fields to make more advanced searches.
Possible fields are :code:`username`, :code:`fullName blocked`, :code:`verified`, :code:`role`,
:code:`locale`, :code:`timeZone`, :code:`userAddress` and :code:`createdAt`
- name: order
description: The direction of the sorting, :code:`asc` or :code:`desc`, default is :code:`asc`
- name: sort
description: >-
The field used for sorting the result, could be :code:`username`, :code:`fullname` or
:code:`insertedAt`.
exports:
- name: user
description: The detail of user in a map, or a list of users
- name: users
description: The detail of user in a map, or a list of users
- name: opsgenie_offset
description: The offset that can be used for continue fetching the rest of the users, for paging
notes:
- See below for example
- example: |
---
workflows:
steps:
- call_function: opsgenie.users
with:
query: username:foobar
contact:
driver: web
rawAction: request
parameters:
URL: https://api.opsgenie.com/v2/users/{{ .ctx.userId }}/contacts
method: GET
header:
Authorization: GenieKey {{ .sysData.API_KEY }}
retry: 2
export:
contacts: $data.json.data
description: >
This function gets the user's contact methods
meta:
inputs:
- name: userId
description: The ID of the user for which to get contact methods
exports:
- name: contacts
description: The detail of user's contact method in a map, or a list of user's contact methods
notes:
- See below for example
- example: |
---
workflows:
steps:
- call_workflow: do_something
- call_function: opsgenie.contact
with:
userId: username@example.com
heartbeat:
driver: web
rawAction: request
parameters:
URL: https://api.opsgenie.com/v2/heartbeats/{{ .ctx.heartbeat }}/ping
method: GET
header:
Authorization: GenieKey {{ .sysData.API_KEY }}
retry: 2
export:
result: $data.json.result
description: >
This function will send a heartbeat request to opsgenie.
meta:
inputs:
- name: heartbeat
description: The name of the heartbeat as configured in your opsgenie settings
exports:
- name: result
description: The return result of the API call
notes:
- See below for example
- example: |
---
workflows:
steps:
- call_workflow: do_something
- call_function: opsgenie.heartbeat
with:
heartbeat: test-heart-beat
triggers:
alert:
driver: webhook
if_match:
method: POST
form:
token: $sysData.token
url: '/opsgenie'
export:
alert_message: $event.json.alert.message
alert_alias: $event.json.alert.alias
alert_Id: $event.json.alert.tinyId
alert_system: "opsgenie"
alert_url: "https://opsg.in/a/i/{{ .event.json.alert.alertId }}"
_event_id: $event.json.alert.tinyId
_event_detail: |-
```{{ .event.json.alert.message }}
{{ .event.json.alert.alias }}```
_event_url: "https://opsg.in/a/i/{{ .event.json.alert.alertId }}"
description: This event is triggered when an opsgenie alert is raised.
meta:
matching_parameters:
- name: .json.alert.message
description: This field can used to match alert with only certain messages
- name: .json.alert.alias
description: This field is to match only the alerts with certain alias
exports:
- name: alert_message
description: This context variable will be set to the detailed message of the alert.
- name: alert_alias
description: This context variable will be set to the alias of the alert.
- name: alert_Id
description: This context variable will be set to the short alert ID.
- name: alert_system
description: This context variable will be set to the constant string, :code:`opsgenie`
- name: alert_url
description: This context variable will be set to the url of the alert, used for creating links
notes:
- See below snippet for example
- example: |
---
rules:
- when:
source:
system: opsgenie
trigger: alert
if_match:
json:
alert:
message: :regex:^test-alert.*$
do:
call_workflow: notify
with:
message: 'The alert url is {{ .ctx.alert_url }}'
workflows:
opsgenie_users:
steps:
- call_function: opsgenie.users
- while:
- $?ctx.opsgenie_offset
steps:
- call_function: opsgenie.users
meta:
description:
- This workflow wraps around the :code:`opsgenie.users` function and handles paging to get all users from Opsgenie.
opsgenie_whoisoncall:
description: get opsgenie on call table
steps:
- call_function: opsgenie.schedules
- call_workflow: opsgenie_users
- export:
email_lookup: |
:yaml:---
{{ range .ctx.users }}
"{{ .username }}": {{ .fullName }}
{{ end }}
- iterate: $ctx.schedules
iterate_as: schedule
steps:
- if_any:
- '{{ empty .ctx.schedule_pattern }}'
- '{{ contains (lower .ctx.schedule_pattern) (lower .ctx.schedule.name) }}'
call_function: opsgenie.whoisoncall
with:
scheduleId: $ctx.schedule.id
scheduleIdType: id
export:
on_call_table: |
:yaml:---
{{ .ctx.schedule.name }}: {{ $sep := "" }}{{ range .ctx.result.onCallRecipients }}
{{- $sep }}
{{- if hasKey $.ctx.email_lookup . }}{{ index $.ctx.email_lookup . }}{{ else }}{{ . }}{{ end }}{{ $sep = "," }}
{{- end }}
no_export:
- schedules
- users
- email_lookup
meta:
description:
- This workflow wraps around multiple api calls to :code:`opsgenie` and produce a `on_call_table` datastructure.
inputs:
- name: schedule_pattern
description: Optional, the keyword used for filtering the on call schedules.
exports:
- name: on_call_table
description: A map from on call schedule names to lists of users.
notes:
- This is usually used for showing the on-call table in response to slash commands.
- For example
- example: |
---
workflows:
show_on_calls:
with:
alert_system: opsgenie
no_export:
- '*'
steps:
- call: '{{ .ctx.alert_system }}_whoisoncall'
- call: notify
with:
notify*:
- reply
response_type: in_channel
blocks:
- type: section
text:
type: mrkdn
text: |
*===== On call users ======*
{{- range $name, $users := .ctx.on_call_table }}
*{{ $name }}*: {{ join ", " $users }}
{{- end }}