@@ -24,7 +24,7 @@ import (
24
24
type escalationID = int64
25
25
26
26
type Incident struct {
27
- Id int64 `db:"id"`
27
+ ID int64 `db:"id"`
28
28
ObjectID types.Binary `db:"object_id"`
29
29
StartedAt types.UnixMilli `db:"started_at"`
30
30
RecoveredAt types.UnixMilli `db:"recovered_at"`
@@ -79,11 +79,7 @@ func NewIncident(
79
79
}
80
80
81
81
func (i * Incident ) String () string {
82
- return fmt .Sprintf ("#%d" , i .Id )
83
- }
84
-
85
- func (i * Incident ) ID () int64 {
86
- return i .Id
82
+ return fmt .Sprintf ("#%d" , i .ID )
87
83
}
88
84
89
85
func (i * Incident ) HasManager () bool {
@@ -301,7 +297,7 @@ func (i *Incident) processSeverityChangedEvent(ctx context.Context, tx *sqlx.Tx,
301
297
i .logger .Infof ("Incident severity changed from %s to %s" , oldSeverity .String (), newSeverity .String ())
302
298
303
299
hr := & HistoryRow {
304
- IncidentID : i .Id ,
300
+ IncidentID : i .ID ,
305
301
EventID : types .MakeInt (ev .ID , types .TransformZeroIntToNull ),
306
302
Time : types .UnixMilli (time .Now ()),
307
303
Type : IncidentSeverityChanged ,
@@ -322,7 +318,7 @@ func (i *Incident) processSeverityChangedEvent(ctx context.Context, tx *sqlx.Tx,
322
318
RemoveCurrent (i .Object )
323
319
324
320
hr = & HistoryRow {
325
- IncidentID : i .Id ,
321
+ IncidentID : i .ID ,
326
322
EventID : types .MakeInt (ev .ID , types .TransformZeroIntToNull ),
327
323
Time : i .RecoveredAt ,
328
324
Type : Closed ,
@@ -358,7 +354,7 @@ func (i *Incident) processIncidentOpenedEvent(ctx context.Context, tx *sqlx.Tx,
358
354
i .logger .Infow (fmt .Sprintf ("Source %d opened incident at severity %q" , ev .SourceId , i .Severity .String ()), zap .String ("message" , ev .Message ))
359
355
360
356
hr := & HistoryRow {
361
- IncidentID : i .Id ,
357
+ IncidentID : i .ID ,
362
358
Type : Opened ,
363
359
Time : types .UnixMilli (ev .Time ),
364
360
EventID : types .MakeInt (ev .ID , types .TransformZeroIntToNull ),
@@ -381,7 +377,7 @@ func (i *Incident) handleMuteUnmute(ctx context.Context, tx *sqlx.Tx, ev *event.
381
377
return nil
382
378
}
383
379
384
- hr := & HistoryRow {IncidentID : i .Id , EventID : types .MakeInt (ev .ID , types .TransformZeroIntToNull ), Time : types .UnixMilli (time .Now ())}
380
+ hr := & HistoryRow {IncidentID : i .ID , EventID : types .MakeInt (ev .ID , types .TransformZeroIntToNull ), Time : types .UnixMilli (time .Now ())}
385
381
logger := i .logger .With (zap .String ("event" , ev .String ()))
386
382
if i .Object .IsMuted () {
387
383
hr .Type = Muted
@@ -415,7 +411,7 @@ func (i *Incident) onFilterRuleMatch(ctx context.Context, r *rule.Rule, tx *sqlx
415
411
}
416
412
417
413
hr := & HistoryRow {
418
- IncidentID : i .Id ,
414
+ IncidentID : i .ID ,
419
415
Time : types .UnixMilli (time .Now ()),
420
416
EventID : types .MakeInt (ev .ID , types .TransformZeroIntToNull ),
421
417
RuleID : types .MakeInt (r .ID , types .TransformZeroIntToNull ),
@@ -510,7 +506,7 @@ func (i *Incident) triggerEscalations(ctx context.Context, tx *sqlx.Tx, ev *even
510
506
}
511
507
512
508
hr := & HistoryRow {
513
- IncidentID : i .Id ,
509
+ IncidentID : i .ID ,
514
510
Time : state .TriggeredAt ,
515
511
EventID : types .MakeInt (ev .ID , types .TransformZeroIntToNull ),
516
512
RuleEscalationID : types .MakeInt (state .RuleEscalationID , types .TransformZeroIntToNull ),
@@ -544,7 +540,7 @@ func (i *Incident) notifyContacts(ctx context.Context, ev *event.Event, notifica
544
540
}
545
541
546
542
incidentUrl := baseUrl .JoinPath ("/notifications/incident" )
547
- incidentUrl .RawQuery = fmt .Sprintf ("id=%d" , i .ID () )
543
+ incidentUrl .RawQuery = fmt .Sprintf ("id=%d" , i .ID )
548
544
549
545
req := & plugin.NotificationRequest {
550
546
Object : & plugin.Object {
@@ -554,7 +550,7 @@ func (i *Incident) notifyContacts(ctx context.Context, ev *event.Event, notifica
554
550
ExtraTags : i .Object .ExtraTags ,
555
551
},
556
552
Incident : & plugin.Incident {
557
- Id : i .Id ,
553
+ Id : i .ID ,
558
554
Url : incidentUrl .String (),
559
555
Severity : i .Severity .String (),
560
556
},
@@ -659,7 +655,7 @@ func (i *Incident) processAcknowledgementEvent(ctx context.Context, tx *sqlx.Tx,
659
655
i .logger .Infof ("Contact %q role changed from %s to %s" , contact .String (), oldRole .String (), newRole .String ())
660
656
661
657
hr := & HistoryRow {
662
- IncidentID : i .Id ,
658
+ IncidentID : i .ID ,
663
659
Key : recipientKey ,
664
660
EventID : types .MakeInt (ev .ID , types .TransformZeroIntToNull ),
665
661
Type : RecipientRoleChanged ,
@@ -737,7 +733,7 @@ func (i *Incident) getRecipientsChannel(t time.Time) rule.ContactChannels {
737
733
func (i * Incident ) restoreRecipients (ctx context.Context ) error {
738
734
contact := & ContactRow {}
739
735
var contacts []* ContactRow
740
- err := i .db .SelectContext (ctx , & contacts , i .db .Rebind (i .db .BuildSelectStmt (contact , contact )+ ` WHERE "incident_id" = ?` ), i .Id )
736
+ err := i .db .SelectContext (ctx , & contacts , i .db .Rebind (i .db .BuildSelectStmt (contact , contact )+ ` WHERE "incident_id" = ?` ), i .ID )
741
737
if err != nil {
742
738
i .logger .Errorw ("Failed to restore incident recipients from the database" , zap .Error (err ))
743
739
return err
0 commit comments