-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathincidents.go
More file actions
734 lines (637 loc) · 22.5 KB
/
incidents.go
File metadata and controls
734 lines (637 loc) · 22.5 KB
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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
package flashduty
import (
"context"
"fmt"
"golang.org/x/sync/errgroup"
)
const defaultQueryLimit = 20
// ListIncidentsInput contains parameters for listing incidents
type ListIncidentsInput struct {
IncidentIDs []string // Direct lookup by IDs (if set, other filters are ignored)
Progress string // Filter: Triggered, Processing, Closed (comma-separated for multiple)
Severity string // Filter: Info, Warning, Critical
ChannelIDs []int64 // Filter by collaboration space IDs
// Deprecated: use ChannelIDs. If both are set, ChannelIDs wins; otherwise
// a non-zero ChannelID is wrapped into a single-element ChannelIDs slice.
// The backend /incident/list endpoint expects channel_ids (array) — singular
// channel_id is silently ignored.
ChannelID int64
StartTime int64 // Unix timestamp (seconds), required if no IncidentIDs
EndTime int64 // Unix timestamp (seconds), required if no IncidentIDs
// Query is the backend's full-text search field on /incident/list. It
// searches across title/labels/content via Doris and also resolves a 24-char
// ObjectID to incident_ids and a 6-char string to a num lookup. Prefer this
// over Title for free-form search; fall back to Title only when the caller
// wants exact/regex/wildcard matching against the title field alone.
Query string
Title string
Limit int
Page int
IncludeAlerts bool
// AlertsPreviewLimit caps how many alerts per incident populate
// AlertsPreview when IncludeAlerts is true. When <=0, falls back to the
// SDK's defaultQueryLimit. Smaller values reduce response size sharply
// for callers (e.g. LLMs) that just want a representative sample rather
// than an exhaustive list — drill into one incident with ListIncidentAlerts
// when the full set is needed.
AlertsPreviewLimit int
}
// ListIncidentsOutput contains the result of listing incidents
type ListIncidentsOutput struct {
Incidents []EnrichedIncident `json:"incidents"`
Total int `json:"total"`
}
// ListIncidents queries incidents by IDs or filters, returns enriched data with names
func (c *Client) ListIncidents(ctx context.Context, input *ListIncidentsInput) (*ListIncidentsOutput, error) {
limit := input.Limit
if limit <= 0 {
limit = defaultQueryLimit
}
var rawIncidents []RawIncident
var err error
if len(input.IncidentIDs) > 0 {
rawIncidents, err = c.fetchIncidentsByIDs(ctx, input.IncidentIDs)
} else {
if input.StartTime == 0 || input.EndTime == 0 {
return nil, fmt.Errorf("both start_time and end_time are required for time-based queries")
}
page := input.Page
if page <= 0 {
page = 1
}
rawIncidents, err = c.fetchIncidentsByFilters(ctx, input.Progress, input.Severity, mergeChannelIDs(input.ChannelIDs, input.ChannelID), input.StartTime, input.EndTime, input.Query, input.Title, limit, page)
}
if err != nil {
return nil, fmt.Errorf("unable to retrieve incidents: %w", err)
}
if len(rawIncidents) == 0 {
return &ListIncidentsOutput{
Incidents: []EnrichedIncident{},
Total: 0,
}, nil
}
enrichedIncidents, err := c.enrichIncidents(ctx, rawIncidents)
if err != nil {
return nil, fmt.Errorf("unable to load additional incident details: %w", err)
}
// AlertsTotal is always populated so callers can use it as a volume gauge
// without paying the preview payload cost; AlertsPreview is only filled
// when IncludeAlerts is true. When the caller doesn't want previews, the
// per-incident fetch uses limit=1 and the returned items are discarded.
if len(enrichedIncidents) > 0 {
previewLimit := 1
if input.IncludeAlerts {
previewLimit = input.AlertsPreviewLimit
if previewLimit <= 0 {
previewLimit = defaultQueryLimit
}
}
g, gctx := errgroup.WithContext(ctx)
for i := range enrichedIncidents {
incidentID := enrichedIncidents[i].IncidentID
g.Go(func() error {
alerts, total, fetchErr := c.fetchIncidentAlerts(gctx, incidentID, previewLimit)
if fetchErr != nil {
return fetchErr
}
if input.IncludeAlerts {
enrichedIncidents[i].AlertsPreview = alerts
}
enrichedIncidents[i].AlertsTotal = total
return nil
})
}
if err := g.Wait(); err != nil {
return nil, fmt.Errorf("unable to retrieve alerts: %w", err)
}
}
return &ListIncidentsOutput{
Incidents: enrichedIncidents,
Total: len(enrichedIncidents),
}, nil
}
// IncidentTimelineOutput contains timeline data for a single incident
type IncidentTimelineOutput struct {
IncidentID string `json:"incident_id"`
Timeline []TimelineEvent `json:"timeline"`
Total int `json:"total"`
}
// GetIncidentTimelines fetches timelines for one or more incidents concurrently
func (c *Client) GetIncidentTimelines(ctx context.Context, incidentIDs []string) ([]IncidentTimelineOutput, error) {
if len(incidentIDs) == 0 {
return nil, fmt.Errorf("incident_ids must contain at least one valid ID")
}
type timelineResult struct {
IncidentID string
Items []RawTimelineItem
}
results := make([]timelineResult, len(incidentIDs))
g, gctx := errgroup.WithContext(ctx)
for i, id := range incidentIDs {
g.Go(func() error {
items, err := c.fetchIncidentTimeline(gctx, id)
if err != nil {
return err
}
results[i] = timelineResult{IncidentID: id, Items: items}
return nil
})
}
if err := g.Wait(); err != nil {
return nil, fmt.Errorf("unable to retrieve timeline: %w", err)
}
// Collect all person IDs from all timelines
allPersonIDs := make([]int64, 0)
for _, r := range results {
allPersonIDs = append(allPersonIDs, collectTimelinePersonIDs(r.Items)...)
}
// Batch fetch person info
personMap, err := c.fetchPersonInfos(ctx, allPersonIDs)
if err != nil {
return nil, fmt.Errorf("unable to load person details: %w", err)
}
// Build enriched response
output := make([]IncidentTimelineOutput, 0, len(results))
for _, r := range results {
enrichedEvents := enrichTimelineItems(r.Items, personMap)
output = append(output, IncidentTimelineOutput{
IncidentID: r.IncidentID,
Timeline: enrichedEvents,
Total: len(enrichedEvents),
})
}
return output, nil
}
// IncidentAlertsOutput contains alerts data for a single incident
type IncidentAlertsOutput struct {
IncidentID string `json:"incident_id"`
Alerts []AlertPreview `json:"alerts"`
Total int `json:"total"`
}
// ListIncidentAlerts fetches alerts for one or more incidents concurrently
func (c *Client) ListIncidentAlerts(ctx context.Context, incidentIDs []string, limit int) ([]IncidentAlertsOutput, error) {
if len(incidentIDs) == 0 {
return nil, fmt.Errorf("incident_ids must contain at least one valid ID")
}
if limit <= 0 {
limit = defaultQueryLimit
}
results := make([]IncidentAlertsOutput, len(incidentIDs))
g, gctx := errgroup.WithContext(ctx)
for i, id := range incidentIDs {
g.Go(func() error {
alerts, total, err := c.fetchIncidentAlerts(gctx, id, limit)
if err != nil {
return err
}
results[i] = IncidentAlertsOutput{IncidentID: id, Alerts: alerts, Total: total}
return nil
})
}
if err := g.Wait(); err != nil {
return nil, fmt.Errorf("unable to retrieve alerts: %w", err)
}
return results, nil
}
// ListSimilarIncidents finds similar historical incidents for a given incident
func (c *Client) ListSimilarIncidents(ctx context.Context, incidentID string, limit int) (*ListIncidentsOutput, error) {
if limit <= 0 {
limit = defaultQueryLimit
}
requestBody := map[string]any{
"incident_id": incidentID,
"p": 1,
"limit": limit,
}
result, err := postData[struct {
Items []RawIncident `json:"items"`
Total int `json:"total"`
}](c, ctx, "/incident/past/list", requestBody, "unable to find similar incidents")
if err != nil {
return nil, err
}
if result == nil || len(result.Items) == 0 {
return &ListIncidentsOutput{
Incidents: []EnrichedIncident{},
Total: 0,
}, nil
}
enrichedIncidents, err := c.enrichIncidents(ctx, result.Items)
if err != nil {
return nil, fmt.Errorf("unable to load additional incident details: %w", err)
}
return &ListIncidentsOutput{
Incidents: enrichedIncidents,
Total: result.Total,
}, nil
}
// CreateIncidentInput contains parameters for creating an incident
type CreateIncidentInput struct {
Title string // Required. Length: 3-200 characters
Severity string // Required. Info, Warning, Critical
ChannelID int64 // Optional collaboration space ID
Description string // Optional. Max 6144 characters
AssignedTo []int // Optional person IDs to assign as responders
}
// CreateIncident creates a new incident
func (c *Client) CreateIncident(ctx context.Context, input *CreateIncidentInput) (any, error) {
requestBody := map[string]any{
"title": input.Title,
"incident_severity": input.Severity,
}
if input.ChannelID > 0 {
requestBody["channel_id"] = input.ChannelID
}
if input.Description != "" {
requestBody["description"] = input.Description
}
if len(input.AssignedTo) > 0 {
requestBody["assigned_to"] = map[string]any{
"type": "assign",
"person_ids": input.AssignedTo,
}
}
data, err := postData[any](c, ctx, "/incident/create", requestBody, "failed to create incident")
if err != nil {
return nil, err
}
if data == nil {
return nil, nil
}
return *data, nil
}
// UpdateIncidentInput contains parameters for updating an incident
type UpdateIncidentInput struct {
IncidentID string // Required
Title string // Optional, empty = skip
Description string // Optional
Severity string // Optional
Impact string // Optional
RootCause string // Optional
Resolution string // Optional
CustomFields map[string]any // Optional
}
// UpdateIncident updates an incident's fields. Returns the list of updated field names.
//
// Built-in fields (title, description, severity, impact, root_cause, resolution)
// are sent in a single POST to /incident/reset. The legacy per-field endpoints
// (/incident/{title,description,severity}/reset) are deliberately not used:
// they require JWT/cookie auth in the gateway, while /incident/reset accepts
// app_key, which is what SDK callers carry. Custom fields go through
// /incident/field/reset, one call per field, because that endpoint takes a
// single field_name/field_value pair.
func (c *Client) UpdateIncident(ctx context.Context, input *UpdateIncidentInput) ([]string, error) {
updatedFields := make([]string, 0)
resetBody := map[string]any{"incident_id": input.IncidentID}
if input.Title != "" {
resetBody["title"] = input.Title
updatedFields = append(updatedFields, "title")
}
if input.Description != "" {
resetBody["description"] = input.Description
updatedFields = append(updatedFields, "description")
}
if input.Severity != "" {
resetBody["incident_severity"] = input.Severity
updatedFields = append(updatedFields, "severity")
}
if input.Impact != "" {
resetBody["impact"] = input.Impact
updatedFields = append(updatedFields, "impact")
}
if input.RootCause != "" {
resetBody["root_cause"] = input.RootCause
updatedFields = append(updatedFields, "root_cause")
}
if input.Resolution != "" {
resetBody["resolution"] = input.Resolution
updatedFields = append(updatedFields, "resolution")
}
if len(resetBody) > 1 {
if err := postEmpty(c, ctx, "/incident/reset", resetBody, "unable to update incident"); err != nil {
return nil, err
}
}
if len(input.CustomFields) > 0 {
for fieldName, fieldValue := range input.CustomFields {
if fieldName == "" {
return nil, fmt.Errorf("custom field name must not be empty")
}
for _, c := range fieldName {
isValid := (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'
if !isValid {
return nil, fmt.Errorf("custom field name '%s' contains invalid characters (only alphanumeric and underscore allowed)", fieldName)
}
}
if err := c.updateCustomField(ctx, input.IncidentID, fieldName, fieldValue); err != nil {
return nil, fmt.Errorf("unable to update custom field '%s': %w", fieldName, err)
}
updatedFields = append(updatedFields, fieldName)
}
}
if len(updatedFields) == 0 {
return nil, fmt.Errorf("no fields specified to update")
}
return updatedFields, nil
}
// AckIncidents acknowledges one or more incidents
func (c *Client) AckIncidents(ctx context.Context, incidentIDs []string) error {
requestBody := map[string]any{
"incident_ids": incidentIDs,
}
return postEmpty(c, ctx, "/incident/ack", requestBody, "unable to acknowledge incidents")
}
// CloseIncidents closes (resolves) one or more incidents
func (c *Client) CloseIncidents(ctx context.Context, incidentIDs []string) error {
requestBody := map[string]any{
"incident_ids": incidentIDs,
}
return postEmpty(c, ctx, "/incident/resolve", requestBody, "unable to close incidents")
}
// fetchIncidentsByIDs fetches incidents by their IDs
func (c *Client) fetchIncidentsByIDs(ctx context.Context, incidentIDs []string) ([]RawIncident, error) {
requestBody := map[string]any{
"incident_ids": incidentIDs,
}
result, err := postData[struct {
Items []RawIncident `json:"items"`
}](c, ctx, "/incident/list-by-ids", requestBody, "unable to fetch incidents by IDs")
if err != nil {
return nil, err
}
if result == nil {
return nil, nil
}
return result.Items, nil
}
// fetchIncidentsByFilters fetches incidents by filters
func (c *Client) fetchIncidentsByFilters(ctx context.Context, progress, severity string, channelIDs []int64, startTime, endTime int64, query, title string, limit, page int) ([]RawIncident, error) {
requestBody := map[string]any{
"p": page,
"limit": limit,
"start_time": startTime,
"end_time": endTime,
}
if progress != "" {
requestBody["progress"] = progress
}
if severity != "" {
requestBody["incident_severity"] = severity
}
if len(channelIDs) > 0 {
requestBody["channel_ids"] = channelIDs
}
if query != "" {
requestBody["query"] = query
}
if title != "" {
requestBody["title"] = title
}
result, err := postData[struct {
Items []RawIncident `json:"items"`
}](c, ctx, "/incident/list", requestBody, "unable to fetch incidents")
if err != nil {
return nil, err
}
if result == nil {
return nil, nil
}
return result.Items, nil
}
// GetIncidentDetailInput contains parameters for getting incident detail
type GetIncidentDetailInput struct {
IncidentID string // Required
}
// GetIncidentDetailOutput contains full incident detail
type GetIncidentDetailOutput struct {
Incident IncidentDetail `json:"incident"`
}
// GetIncidentDetail fetches detailed information for a single incident
func (c *Client) GetIncidentDetail(ctx context.Context, input *GetIncidentDetailInput) (*GetIncidentDetailOutput, error) {
if input == nil {
return nil, fmt.Errorf("incident detail input is required")
}
requestBody := map[string]any{
"incident_id": input.IncidentID,
}
incident, err := postOptionalData[IncidentDetail](c, ctx, "/incident/info", requestBody, "failed to get incident detail")
if err != nil {
return nil, err
}
if incident == nil {
return nil, fmt.Errorf("incident not found: %s", input.IncidentID)
}
return &GetIncidentDetailOutput{Incident: *incident}, nil
}
// GetIncidentFeedInput contains parameters for getting incident feed/timeline
type GetIncidentFeedInput struct {
IncidentID string // Required
Limit int // Max results (default 20)
Page int // Page number (default 1)
Asc bool // Sort ascending by time (default false)
}
// GetIncidentFeedOutput contains incident feed events
type GetIncidentFeedOutput struct {
Items []TimelineEvent `json:"items"`
HasNextPage bool `json:"has_next_page"`
}
// GetIncidentFeed fetches the feed/timeline for an incident with enriched person names
func (c *Client) GetIncidentFeed(ctx context.Context, input *GetIncidentFeedInput) (*GetIncidentFeedOutput, error) {
if input == nil {
return nil, fmt.Errorf("incident feed input is required")
}
limit := input.Limit
if limit <= 0 {
limit = defaultQueryLimit
}
page := input.Page
if page <= 0 {
page = 1
}
requestBody := map[string]any{
"incident_id": input.IncidentID,
"limit": limit,
"p": page,
"asc": input.Asc,
}
result, err := postData[struct {
Items []RawTimelineItem `json:"items"`
HasNextPage bool `json:"has_next_page"`
}](c, ctx, "/incident/feed", requestBody, "failed to get incident feed")
if err != nil {
return nil, err
}
if result == nil || len(result.Items) == 0 {
return &GetIncidentFeedOutput{
Items: []TimelineEvent{},
HasNextPage: false,
}, nil
}
// Enrich with person names
personIDs := collectTimelinePersonIDs(result.Items)
personMap, err := c.fetchPersonInfos(ctx, personIDs)
if err != nil {
return nil, fmt.Errorf("failed to load person details for feed: %w", err)
}
enrichedItems := enrichTimelineItems(result.Items, personMap)
return &GetIncidentFeedOutput{
Items: enrichedItems,
HasNextPage: result.HasNextPage,
}, nil
}
// ListPostMortemsInput contains parameters for listing post-mortem reports
type ListPostMortemsInput struct {
// Deprecated: /incident/post-mortem/list does not support incident_id filtering.
IncidentID string
Status string // drafting or published
TeamIDs []int64 // Optional team filter
ChannelIDs []int64 // Optional channel filter
CreatedAtStartSeconds int64 // Optional creation time lower bound
CreatedAtEndSeconds int64 // Optional creation time upper bound
OrderBy string // created_at_seconds or updated_at_seconds
Asc bool // Sort ascending when true
Limit int // Max results (default 20)
Page int // Page number (default 1)
SearchAfterCtx string // Cursor for the next page
}
// ListPostMortemsOutput contains post-mortem reports
type ListPostMortemsOutput struct {
PostMortems []PostMortem `json:"post_mortems"`
Total int `json:"total"`
HasNextPage bool `json:"has_next_page"`
SearchAfterCtx string `json:"search_after_ctx,omitempty"`
}
// ListPostMortems queries post-mortem reports
func (c *Client) ListPostMortems(ctx context.Context, input *ListPostMortemsInput) (*ListPostMortemsOutput, error) {
if input == nil {
return nil, fmt.Errorf("post-mortem query input is required")
}
limit := input.Limit
if limit <= 0 {
limit = defaultQueryLimit
}
page := input.Page
if page <= 0 {
page = 1
}
requestBody := map[string]any{
"limit": limit,
"p": page,
}
if input.Status != "" {
requestBody["status"] = input.Status
}
if len(input.TeamIDs) > 0 {
requestBody["team_ids"] = input.TeamIDs
}
if len(input.ChannelIDs) > 0 {
requestBody["channel_ids"] = input.ChannelIDs
}
if input.CreatedAtStartSeconds > 0 {
requestBody["created_at_start_seconds"] = input.CreatedAtStartSeconds
}
if input.CreatedAtEndSeconds > 0 {
requestBody["created_at_end_seconds"] = input.CreatedAtEndSeconds
}
if input.OrderBy != "" {
requestBody["order_by"] = input.OrderBy
}
if input.Asc {
requestBody["asc"] = true
}
if input.SearchAfterCtx != "" {
requestBody["search_after_ctx"] = input.SearchAfterCtx
}
result, err := postData[struct {
Items []PostMortem `json:"items"`
Total int `json:"total"`
HasNextPage bool `json:"has_next_page"`
SearchAfterCtx string `json:"search_after_ctx,omitempty"`
}](c, ctx, "/incident/post-mortem/list", requestBody, "failed to list post-mortems")
if err != nil {
return nil, err
}
postMortems := []PostMortem{}
total := 0
hasNextPage := false
searchAfterCtx := ""
if result != nil {
postMortems = result.Items
total = result.Total
hasNextPage = result.HasNextPage
searchAfterCtx = result.SearchAfterCtx
}
return &ListPostMortemsOutput{
PostMortems: postMortems,
Total: total,
HasNextPage: hasNextPage,
SearchAfterCtx: searchAfterCtx,
}, nil
}
// updateCustomField is a helper to update a custom field
func (c *Client) updateCustomField(ctx context.Context, incidentID, fieldName string, fieldValue any) error {
requestBody := map[string]any{
"incident_id": incidentID,
"field_name": fieldName,
"field_value": fieldValue,
}
return postEmpty(c, ctx, "/incident/field/reset", requestBody, "failed to update custom field")
}
// MergeIncidentsInput contains parameters for merging incidents
type MergeIncidentsInput struct {
SourceIncidentIDs []string // Required: IDs to merge (max 100)
TargetIncidentID string // Required: destination incident
}
// MergeIncidents merges source incidents into a target incident
func (c *Client) MergeIncidents(ctx context.Context, input *MergeIncidentsInput) error {
if input == nil {
return fmt.Errorf("merge incidents input is required")
}
requestBody := map[string]any{
"source_incident_ids": input.SourceIncidentIDs,
"target_incident_id": input.TargetIncidentID,
}
return postEmpty(c, ctx, "/incident/merge", requestBody, "failed to merge incidents")
}
// SnoozeIncidentsInput contains parameters for snoozing incidents
type SnoozeIncidentsInput struct {
IncidentIDs []string // Required
Minutes int64 // Required: snooze duration in minutes (max 1440)
}
// SnoozeIncidents snoozes one or more incidents for the specified duration
func (c *Client) SnoozeIncidents(ctx context.Context, input *SnoozeIncidentsInput) error {
if input == nil {
return fmt.Errorf("snooze incidents input is required")
}
requestBody := map[string]any{
"incident_ids": input.IncidentIDs,
"minutes": input.Minutes,
}
return postEmpty(c, ctx, "/incident/snooze", requestBody, "failed to snooze incidents")
}
// ReopenIncidents reopens one or more closed incidents
func (c *Client) ReopenIncidents(ctx context.Context, incidentIDs []string) error {
requestBody := map[string]any{
"incident_ids": incidentIDs,
}
return postEmpty(c, ctx, "/incident/reopen", requestBody, "failed to reopen incidents")
}
// ReassignIncidentsInput contains parameters for reassigning incidents
type ReassignIncidentsInput struct {
IncidentIDs []string // Required
PersonIDs []int64 // Required: new responders
}
// ReassignIncidents reassigns one or more incidents to new responders
func (c *Client) ReassignIncidents(ctx context.Context, input *ReassignIncidentsInput) error {
if input == nil {
return fmt.Errorf("reassign incidents input is required")
}
requestBody := map[string]any{
"incident_ids": input.IncidentIDs,
"assigned_to": map[string]any{
"type": "assign",
"person_ids": input.PersonIDs,
},
}
return postEmpty(c, ctx, "/incident/assign", requestBody, "failed to reassign incidents")
}