/
logentryfetcher.go
63 lines (51 loc) · 1.2 KB
/
logentryfetcher.go
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
package alert
import (
"context"
"github.com/target/goalert/alert/alertlog"
"github.com/pkg/errors"
)
type LogEntryFetcher interface {
// LogEntry fetches the latest log entry for a given alertID and type.
LogEntry(ctx context.Context) (*alertlog.Entry, error)
}
type logError struct {
isAlreadyAcknowledged bool
isAlreadyClosed bool
alertID int
_type alertlog.Type
logDB *alertlog.Store
}
func (logError) ClientError() bool { return true }
func (e logError) LogEntry(ctx context.Context) (*alertlog.Entry, error) {
return e.logDB.FindLatestByType(ctx, e.alertID, e._type)
}
func (e logError) Error() string {
if e.isAlreadyAcknowledged {
return "alert is already acknowledged"
}
if e.isAlreadyClosed {
return "alert is already closed"
}
return "unknown status update"
}
func AlertID(err error) int {
var e logError
if errors.As(err, &e) {
return e.alertID
}
return 0
}
func IsAlreadyAcknowledged(err error) bool {
var e logError
if errors.As(err, &e) {
return e.isAlreadyAcknowledged
}
return false
}
func IsAlreadyClosed(err error) bool {
var e logError
if errors.As(err, &e) {
return e.isAlreadyClosed
}
return false
}