Skip to content

Commit

Permalink
Add notifications with Shoutrr (#3215)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeffrey Cafferata <[email protected]>
Co-authored-by: Tom Limoncelli <[email protected]>
  • Loading branch information
3 people authored Dec 9, 2024
1 parent 25652e0 commit e774e2d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
9 changes: 8 additions & 1 deletion documentation/notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
32 changes: 32 additions & 0 deletions pkg/notifications/shoutrrr.go
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit e774e2d

Please sign in to comment.