github.com/philhug/dnscontrol@v0.2.4-0.20180625181521-921fa9849001/pkg/notifications/bonfire.go (about) 1 package notifications 2 3 import ( 4 "fmt" 5 "net/http" 6 "strings" 7 ) 8 9 func init() { 10 initers = append(initers, func(cfg map[string]string) Notifier { 11 if url, ok := cfg["bonfire_url"]; ok { 12 return bonfireNotifier(url) 13 } 14 return nil 15 }) 16 } 17 18 // bonfire notifier for stack exchange internal chat. String is just url with room and token in it 19 type bonfireNotifier string 20 21 func (b bonfireNotifier) Notify(domain, provider, msg string, err error, preview bool) { 22 var payload string 23 if preview { 24 payload = fmt.Sprintf(`**Preview: %s[%s] -** %s`, domain, provider, msg) 25 } else if err != nil { 26 payload = fmt.Sprintf(`**ERROR running correction on %s[%s] -** (%s) Error: %s`, domain, provider, msg, err) 27 } else { 28 payload = fmt.Sprintf(`Successfully ran correction for **%s[%s]** - %s`, domain, provider, msg) 29 } 30 // chat doesn't markdownify multiline messages. Split in two so the first line can have markdown 31 parts := strings.SplitN(payload, "\n", 2) 32 for _, p := range parts { 33 http.Post(string(b), "text/markdown", strings.NewReader(p)) 34 } 35 } 36 37 func (b bonfireNotifier) Done() {}