77 "time"
88
99 "github.com/function61/eventhorizon/pkg/ehevent"
10- "github.com/function61/gokit/ossignal"
11- "github.com/function61/gokit/stringutils"
10+ "github.com/function61/gokit/strings/stringutils"
1211 "github.com/function61/lambda-alertmanager/pkg/amdomain"
1312 "github.com/function61/lambda-alertmanager/pkg/amstate"
1413 "github.com/scylladb/termtables"
@@ -25,32 +24,29 @@ func alertEntry() *cobra.Command {
2524 Use : "mk [subject] [details]" ,
2625 Short : "Raise an alert" ,
2726 Args : cobra .ExactArgs (2 ),
28- Run : func (cmd * cobra.Command , args []string ) {
29- exitIfError ( alertRaise (
30- ossignal . InterruptOrTerminateBackgroundCtx ( nil ),
27+ RunE : func (cmd * cobra.Command , args []string ) error {
28+ return alertRaise (
29+ cmd . Context ( ),
3130 args [0 ],
32- args [1 ]))
31+ args [1 ])
3332 },
3433 })
3534
3635 cmd .AddCommand (& cobra.Command {
3736 Use : "ls" ,
3837 Short : "List active alerts" ,
3938 Args : cobra .NoArgs ,
40- Run : func (cmd * cobra.Command , args []string ) {
41- exitIfError (alertList (
42- ossignal .InterruptOrTerminateBackgroundCtx (nil )))
39+ RunE : func (cmd * cobra.Command , _ []string ) error {
40+ return alertList (cmd .Context ())
4341 },
4442 })
4543
4644 cmd .AddCommand (& cobra.Command {
4745 Use : "ack [id]" ,
4846 Short : "Acknowledge an alert" ,
4947 Args : cobra .ExactArgs (1 ),
50- Run : func (cmd * cobra.Command , args []string ) {
51- exitIfError (alertAck (
52- ossignal .InterruptOrTerminateBackgroundCtx (nil ),
53- args [0 ]))
48+ RunE : func (cmd * cobra.Command , args []string ) error {
49+ return alertAck (cmd .Context (), args [0 ])
5450 },
5551 })
5652
@@ -64,7 +60,7 @@ func alertRaise(ctx context.Context, subject string, details string) error {
6460 }
6561
6662 raised := amdomain .NewAlertRaised (
67- amstate .NewAlertId (),
63+ amstate .NewAlertID (),
6864 subject ,
6965 details ,
7066 ehevent .MetaSystemUser (time .Now ()))
@@ -89,7 +85,7 @@ func alertList(ctx context.Context) error {
8985
9086 for _ , alert := range app .State .ActiveAlerts () {
9187 view .AddRow (
92- alert .Id ,
88+ alert .ID ,
9389 alert .Timestamp .Format (time .RFC3339 ),
9490 alert .Subject ,
9591 stringutils .Truncate (removeLinebreaks (alert .Details ), 50 ))
@@ -100,19 +96,19 @@ func alertList(ctx context.Context) error {
10096 return nil
10197}
10298
103- func alertAck (ctx context.Context , alertId string ) error {
99+ func alertAck (ctx context.Context , alertID string ) error {
104100 app , err := getApp (ctx )
105101 if err != nil {
106102 return err
107103 }
108104
109105 acked := amdomain .NewAlertAcknowledged (
110- alertId ,
106+ alertID ,
111107 ehevent .MetaSystemUser (time .Now ()))
112108
113109 return app .Reader .TransactWrite (ctx , func () error {
114- if ! amstate .HasAlertWithId ( alertId , app .State .ActiveAlerts ()) {
115- return fmt .Errorf ("no alert: %s" , alertId )
110+ if ! amstate .HasAlertWithID ( alertID , app .State .ActiveAlerts ()) {
111+ return fmt .Errorf ("no alert: %s" , alertID )
116112 }
117113
118114 return app .AppendAfter (ctx , app .State .Version (), acked )
0 commit comments