File tree Expand file tree Collapse file tree 3 files changed +29
-7
lines changed Expand file tree Collapse file tree 3 files changed +29
-7
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ type Config struct {
23
23
Platform Platform
24
24
Token string
25
25
Channel string
26
+ Source string
27
+ Severity string
26
28
}
27
29
28
30
func NewNotify (config * Config ) * Notify {
@@ -66,6 +68,8 @@ func (n *Notify) sendSlackNotify(msg string) error {
66
68
func (n * Notify ) sendPagerdutyNotify (msg string ) error {
67
69
app := pagerduty .New (pagerduty.Options {
68
70
Token : n .config .Token ,
71
+ Source : n .config .Source ,
72
+ Severity : n .config .Severity ,
69
73
})
70
74
err := app .Send (msg )
71
75
return err
Original file line number Diff line number Diff line change @@ -36,13 +36,25 @@ func TestNotify_Send(t *testing.T) {
36
36
args {msg : "test case" },
37
37
},
38
38
{
39
- "test pagerduty notify " ,
39
+ "test pagerduty severity is null " ,
40
40
fields {config : & Config {
41
41
Platform : Platform ("pagerduty" ),
42
42
Token : os .Getenv ("PAGERDUTY_TOKEN" ),
43
+ Source : "api-test" ,
44
+ Severity : "" ,
43
45
}},
44
46
args {msg : "test pagerduty" },
45
47
},
48
+ {
49
+ "test pagerduty severity is error" ,
50
+ fields {config : & Config {
51
+ Platform : Platform ("pagerduty" ),
52
+ Token : os .Getenv ("PAGERDUTY_TOKEN" ),
53
+ Source : "api-test" ,
54
+ Severity : "error" ,
55
+ }},
56
+ args {msg : "test pagerduty is error" },
57
+ },
46
58
}
47
59
for _ , tt := range tests {
48
60
t .Run (tt .name , func (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -15,8 +15,10 @@ const (
15
15
)
16
16
17
17
type Options struct {
18
- Token string `json:"token"`
19
- Text string `json:"text"`
18
+ Token string `json:"token"`
19
+ Source string `json:"source"`
20
+ Severity string `json:"severity"`
21
+ Text string `json:"text"`
20
22
}
21
23
22
24
type pagerduty struct {
@@ -59,8 +61,8 @@ func (c *client) Send(message string) error {
59
61
pdOpt := & pagerduty {
60
62
Payload : payload {
61
63
Summary : message ,
62
- Source : "monitoringtool:cloudvendor:central-region-dc-01:852559987:cluster/api-stats-prod-003" ,
63
- Severity : "info" ,
64
+ Source : c . opt . Source ,
65
+ Severity : c . opt . Severity ,
64
66
},
65
67
RoutingKey : c .opt .Token ,
66
68
EventAction : "trigger" ,
@@ -93,8 +95,12 @@ func (c *client) Send(message string) error {
93
95
}
94
96
95
97
func (c * client ) check (msg string ) error {
96
- if c .opt .Token == "" {
97
- return errors .New ("missing auth token" )
98
+ if c .opt .Token == "" || c .opt .Source == "" {
99
+ return errors .New ("missing config" )
100
+ }
101
+
102
+ if c .opt .Severity == "" {
103
+ c .opt .Severity = "critical"
98
104
}
99
105
100
106
if msg == "" {
You can’t perform that action at this time.
0 commit comments