@@ -3,10 +3,12 @@ package config
33import (
44 "flag"
55 "fmt"
6- "github.com/ouqiang/supervisor-event-listener/utils"
7- "gopkg.in/ini.v1"
86 "os"
97 "strings"
8+
9+ "github.com/ouqiang/supervisor-event-listener/utils"
10+ "github.com/ouqiang/supervisor-event-listener/utils/tmpfslog"
11+ "gopkg.in/ini.v1"
1012)
1113
1214type Config struct {
@@ -15,6 +17,7 @@ type Config struct {
1517 MailServer MailServer
1618 MailUser MailUser
1719 Slack Slack
20+ BearyChat BearyChat
1821}
1922
2023type WebHook struct {
@@ -26,6 +29,12 @@ type Slack struct {
2629 Channel string
2730}
2831
32+ type BearyChat struct {
33+ WebHookUrl string
34+ Channel string
35+ Timeout int
36+ }
37+
2938// 邮件服务器
3039type MailServer struct {
3140 User string
@@ -54,12 +63,14 @@ func ParseConfig() *Config {
5463 section := file .Section ("default" )
5564 notifyType := section .Key ("notify_type" ).String ()
5665 notifyType = strings .TrimSpace (notifyType )
57- if ! utils .InStringSlice ([]string {"mail" , "slack" , "webhook" }, notifyType ) {
66+ if ! utils .InStringSlice ([]string {"mail" , "slack" , "webhook" , "bearychat" }, notifyType ) {
5867 Exit ("不支持的通知类型-" + notifyType )
5968 }
6069
6170 config := & Config {}
6271 config .NotifyType = notifyType
72+
73+ tmpfslog .Info ("notifyType: %+v\n " , config .NotifyType )
6374 switch notifyType {
6475 case "mail" :
6576 config .MailServer = parseMailServer (section )
@@ -68,8 +79,9 @@ func ParseConfig() *Config {
6879 config .Slack = parseSlack (section )
6980 case "webhook" :
7081 config .WebHook = parseWebHook (section )
82+ case "bearychat" :
83+ config .BearyChat = parseBearyChat (section )
7184 }
72-
7385 return config
7486}
7587
@@ -134,6 +146,23 @@ func parseWebHook(section *ini.Section) WebHook {
134146 return webHook
135147}
136148
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+
137166func Exit (msg string ) {
138167 fmt .Fprintln (os .Stderr , msg )
139168 os .Exit (1 )
0 commit comments