diff --git a/documentation/notifications.md b/documentation/notifications.md index ddbec9a5d2..894eab4c91 100644 --- a/documentation/notifications.md +++ b/documentation/notifications.md @@ -19,7 +19,8 @@ Notifications are set up in your credentials JSON file. They will use the `notif } , "notifications": { "slack_url": "https://api.slack.com/apps/0XXX0X0XX0/incoming-webhooks", - "teams_url": "https://outlook.office.com/webhook/00000000-0000-0000-0000-000000000000@00000000-0000-0000-0000-000000000000/IncomingWebhook/00000000000000000000000000000000/00000000-0000-0000-0000-000000000000" + "teams_url": "https://outlook.office.com/webhook/00000000-0000-0000-0000-000000000000@00000000-0000-0000-0000-000000000000/IncomingWebhook/00000000000000000000000000000000/00000000-0000-0000-0000-000000000000", + "shoutrrr_url": "discover://token@id" } ``` {% endcode %} @@ -94,6 +95,12 @@ This is Stack Overflow's built in chat system. This is probably not useful for m Configure `bonfire_url` to be the full url including room and api key. +### Shoutrrr (email, Discord, Pushover, etc.) + +DNSControl can use many other notification methods via Shoutrrr, such as email (SMTP), Discord, Pushover and others. See the [Shoutrrr documentation](https://containrrr.dev/shoutrrr/latest/services/overview/) for a list of supported methods and configuration instructions. + +Configure `shoutrrr_url` with the Shoutrrr URL to be notified. + ## Future work Yes, this seems pretty limited right now in what it can do. We didn't want to add a bunch of notification types if nobody was going to use them. The good news is, it should diff --git a/go.mod b/go.mod index 9ba59fb183..7639260ce6 100644 --- a/go.mod +++ b/go.mod @@ -59,6 +59,7 @@ require ( require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0 github.com/G-Core/gcore-dns-sdk-go v0.2.9 + github.com/containrrr/shoutrrr v0.8.0 github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v5 v5.0.3 github.com/fatih/color v1.18.0 github.com/fbiville/markdown-table-formatter v0.3.0 diff --git a/go.sum b/go.sum index 0e7d043e54..c8cc78e5bb 100644 --- a/go.sum +++ b/go.sum @@ -99,6 +99,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk github.com/cloudflare/cloudflare-go v0.111.0 h1:bFgl5OyR7iaV9DkTaoI2jU8X4rXDzEaFDaPfMTp+Ewo= github.com/cloudflare/cloudflare-go v0.111.0/go.mod h1:w5c4Vm00JjZM+W0mPi6QOC+eWLncGQPURtgDck3z5xU= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/containrrr/shoutrrr v0.8.0 h1:mfG2ATzIS7NR2Ec6XL+xyoHzN97H8WPjir8aYzJUSec= +github.com/containrrr/shoutrrr v0.8.0/go.mod h1:ioyQAyu1LJY6sILuNyKaQaw+9Ttik5QePU8atnAdO2o= github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc= github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= @@ -194,6 +196,8 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golangci/lint-1 v0.0.0-20181222135242-d2cdd8c08219/go.mod h1:/X8TswGSh1pIozq4ZwCfxS0WA5JGXguxk94ar/4c87Y= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= diff --git a/pkg/notifications/shoutrrr.go b/pkg/notifications/shoutrrr.go new file mode 100644 index 0000000000..a8c362bbe9 --- /dev/null +++ b/pkg/notifications/shoutrrr.go @@ -0,0 +1,32 @@ +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 + }) +} + +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() {}