This repository was archived by the owner on May 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 440
/
Copy pathinterpolator.go
95 lines (76 loc) · 1.57 KB
/
interpolator.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
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
package alert
import (
"fmt"
"github.com/base-org/pessimism/internal/core"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
// TODO: add timestamp to the message
// Slack Formatting
const (
CodeBlockFmt = "```%s```"
// slackMsgFmt ... Slack message format
SlackMsgFmt = `
*%s %s*
Network: %s
Severity: %s
Session UUID: %s
*Assessment Content:*
%s
*Message:*
%s
`
)
const (
PagerDutyMsgFmt = `
Heuristic Triggered: %s
Network: %s
Assessment:
%s
`
)
// Telegram message format
const (
TelegramMsgFmt = `
*%s %s*
Network: *%s*
Severity: *%s*
Session UUID: *%s*
*Assessment Content:*
%s
*Message:*
%s
`
)
type Interpolator struct{}
func NewInterpolator() *Interpolator {
return &Interpolator{}
}
func (*Interpolator) SlackMessage(a core.Alert, msg string) string {
return fmt.Sprintf(SlackMsgFmt,
a.Sev.Symbol(),
a.HT.String(),
a.Net.String(),
cases.Title(language.English).String(a.Sev.String()),
a.HeuristicID.String(),
fmt.Sprintf(CodeBlockFmt, a.Content),
msg)
}
func (*Interpolator) PagerDutyMessage(a core.Alert) string {
return fmt.Sprintf(PagerDutyMsgFmt,
a.HT.String(),
a.Net.String(),
a.Content)
}
func (*Interpolator) TelegramMessage(a core.Alert, msg string) string {
sev := cases.Title(language.English).String(a.Sev.String())
ht := cases.Title(language.English).String(a.HT.String())
return fmt.Sprintf(TelegramMsgFmt,
a.Sev.Symbol(),
ht,
a.Net.String(),
sev,
a.HeuristicID.String(),
fmt.Sprintf(CodeBlockFmt, a.Content), // Reusing the Slack code block format
msg)
}