forked from StackExchange/dnscontrol
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add notifications with Shoutrrr (fixes StackExchange#2994)
- Loading branch information
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package notifications | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/containrrr/shoutrrr" | ||
) | ||
|
||
func init() { | ||
initers = append(initers, func(cfg map[string]string) Notifier { | ||
if url, ok := cfg["shoutrrr_url"]; ok { | ||
return shoutrrrNotifier(url) | ||
} | ||
return nil | ||
}) | ||
} | ||
|
||
// bonfire notifier for stack exchange internal chat. String is just url with room and token in it | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
type shoutrrrNotifier string | ||
|
||
func (b shoutrrrNotifier) Notify(domain, provider, msg string, err error, preview bool) { | ||
var payload string | ||
if preview { | ||
payload = fmt.Sprintf("DNSControl preview: %s[%s]:\n%s", domain, provider, msg) | ||
} else if err != nil { | ||
payload = fmt.Sprintf("DNSControl ERROR running correction on %s[%s]:\n%s\nError: %s", domain, provider, msg, err) | ||
} else { | ||
payload = fmt.Sprintf("DNSControl successfully ran correction for %s[%s]:\n%s", domain, provider, msg) | ||
} | ||
shoutrrr.Send(string(b), payload) | ||
} | ||
|
||
func (b shoutrrrNotifier) Done() {} |
This comment does not apply to the Shoutrrr implementation. Also known as copy/paste development ;-)