@@ -3,10 +3,12 @@ package config
3
3
import (
4
4
"flag"
5
5
"fmt"
6
- "github.com/ouqiang/supervisor-event-listener/utils"
7
- "gopkg.in/ini.v1"
8
6
"os"
9
7
"strings"
8
+
9
+ "github.com/ouqiang/supervisor-event-listener/utils"
10
+ "github.com/ouqiang/supervisor-event-listener/utils/tmpfslog"
11
+ "gopkg.in/ini.v1"
10
12
)
11
13
12
14
type Config struct {
@@ -15,6 +17,7 @@ type Config struct {
15
17
MailServer MailServer
16
18
MailUser MailUser
17
19
Slack Slack
20
+ BearyChat BearyChat
18
21
}
19
22
20
23
type WebHook struct {
@@ -26,6 +29,12 @@ type Slack struct {
26
29
Channel string
27
30
}
28
31
32
+ type BearyChat struct {
33
+ WebHookUrl string
34
+ Channel string
35
+ Timeout int
36
+ }
37
+
29
38
// 邮件服务器
30
39
type MailServer struct {
31
40
User string
@@ -54,12 +63,14 @@ func ParseConfig() *Config {
54
63
section := file .Section ("default" )
55
64
notifyType := section .Key ("notify_type" ).String ()
56
65
notifyType = strings .TrimSpace (notifyType )
57
- if ! utils .InStringSlice ([]string {"mail" , "slack" , "webhook" }, notifyType ) {
66
+ if ! utils .InStringSlice ([]string {"mail" , "slack" , "webhook" , "bearychat" }, notifyType ) {
58
67
Exit ("不支持的通知类型-" + notifyType )
59
68
}
60
69
61
70
config := & Config {}
62
71
config .NotifyType = notifyType
72
+
73
+ tmpfslog .Info ("notifyType: %+v\n " , config .NotifyType )
63
74
switch notifyType {
64
75
case "mail" :
65
76
config .MailServer = parseMailServer (section )
@@ -68,8 +79,9 @@ func ParseConfig() *Config {
68
79
config .Slack = parseSlack (section )
69
80
case "webhook" :
70
81
config .WebHook = parseWebHook (section )
82
+ case "bearychat" :
83
+ config .BearyChat = parseBearyChat (section )
71
84
}
72
-
73
85
return config
74
86
}
75
87
@@ -134,6 +146,23 @@ func parseWebHook(section *ini.Section) WebHook {
134
146
return webHook
135
147
}
136
148
149
+ func parseBearyChat (section * ini.Section ) BearyChat {
150
+ url := section .Key ("bearychat.webhook_url" ).String ()
151
+ if url == "" {
152
+ Exit ("WebHookUrl配置错误" )
153
+ }
154
+ timeout , err := section .Key ("bearychat.timeout" ).Int ()
155
+ channel := section .Key ("bearychat.channel" ).String ()
156
+ if err != nil {
157
+ Exit (err .Error ())
158
+ }
159
+ return BearyChat {
160
+ WebHookUrl : strings .TrimSpace (url ),
161
+ Channel : strings .TrimSpace (channel ),
162
+ Timeout : timeout ,
163
+ }
164
+ }
165
+
137
166
func Exit (msg string ) {
138
167
fmt .Fprintln (os .Stderr , msg )
139
168
os .Exit (1 )
0 commit comments