Add phone call support
Implements: https://todo.xenrox.net/~xenrox/ntfy-alertmanager/18
This commit is contained in:
parent
b58f93bd4f
commit
7efc6cdbc2
4 changed files with 39 additions and 1 deletions
|
@ -17,7 +17,7 @@ the configuration file will be read from `/etc/ntfy-alertmanager/config`. The fo
|
|||
of this file is [scfg].
|
||||
|
||||
ntfy-alertmanager has support for setting ntfy [priority], [tags], [icon], [action buttons]
|
||||
(which can be used to create an Alertmanager silence) and [email notifications].
|
||||
(which can be used to create an Alertmanager silence), [email notifications] and [phone calls].
|
||||
Define a decreasing order of labels in the config file and map those labels to tags, priority, an icon or an email address.
|
||||
|
||||
- For priority and icon the first found value will be chosen. An icon for "resolved" alerts will take precedence.
|
||||
|
@ -49,6 +49,8 @@ labels {
|
|||
icon "https://foo.com/critical.png"
|
||||
# Forward messages which severity "critical" to the specified email address.
|
||||
email-address foo@bar.com
|
||||
# Call the specified number. Use `yes` to pick the first of your verified numbers.
|
||||
call yes
|
||||
}
|
||||
|
||||
severity "info" {
|
||||
|
@ -77,6 +79,8 @@ ntfy {
|
|||
access-token foobar
|
||||
# Forward all messages to the specified email address.
|
||||
email-address foo@bar.com
|
||||
# Call the specified number for all alerts. Use `yes` to pick the first of your verified numbers.
|
||||
call +123456789
|
||||
}
|
||||
|
||||
alertmanager {
|
||||
|
@ -140,6 +144,7 @@ or write to me directly on matrix [@xenrox:xenrox.net].
|
|||
[icon]: https://docs.ntfy.sh/publish/#icons
|
||||
[action buttons]: https://docs.ntfy.sh/publish/#action-buttons
|
||||
[email notifications]: https://docs.ntfy.sh/publish/#e-mail-notifications
|
||||
[phone calls]: https://ntfy.xenrox.net/docs/publish/#phone-calls
|
||||
[issue tracker]: https://todo.xenrox.net/~xenrox/ntfy-alertmanager
|
||||
[mailing list]: https://lists.xenrox.net/~xenrox/public-inbox
|
||||
[@xenrox:xenrox.net]: https://matrix.to/#/@xenrox:xenrox.net
|
||||
|
|
16
config.go
16
config.go
|
@ -43,6 +43,7 @@ type ntfyConfig struct {
|
|||
Password string
|
||||
AccessToken string
|
||||
emailAddress string
|
||||
call string
|
||||
}
|
||||
|
||||
type labels struct {
|
||||
|
@ -55,6 +56,7 @@ type labelConfig struct {
|
|||
Tags []string
|
||||
Icon string
|
||||
emailAddress string
|
||||
call string
|
||||
}
|
||||
|
||||
type cacheConfig struct {
|
||||
|
@ -210,6 +212,13 @@ func readConfig(path string) (*config, error) {
|
|||
}
|
||||
}
|
||||
|
||||
d = labelDir.Children.Get("call")
|
||||
if d != nil {
|
||||
if err := d.ParseParams(&labelConfig.call); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
labels[fmt.Sprintf("%s:%s", labelName, name)] = *labelConfig
|
||||
}
|
||||
}
|
||||
|
@ -267,6 +276,13 @@ func readConfig(path string) (*config, error) {
|
|||
}
|
||||
}
|
||||
|
||||
d = ntfyDir.Children.Get("call")
|
||||
if d != nil {
|
||||
if err := d.ParseParams(&config.ntfy.call); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
cacheDir := cfg.Get("cache")
|
||||
|
||||
if cacheDir != nil {
|
||||
|
|
|
@ -25,6 +25,7 @@ labels {
|
|||
tags "rotating_light"
|
||||
icon "https://foo.com/critical.png"
|
||||
email-address foo@bar.com
|
||||
call yes
|
||||
}
|
||||
|
||||
severity "info" {
|
||||
|
@ -76,6 +77,7 @@ cache {
|
|||
Tags: []string{"rotating_light"},
|
||||
Icon: "https://foo.com/critical.png",
|
||||
emailAddress: "foo@bar.com",
|
||||
call: "yes",
|
||||
},
|
||||
"severity:info": {Priority: "1"},
|
||||
"instance:example.com": {Tags: []string{"computer", "example"}},
|
||||
|
|
15
main.go
15
main.go
|
@ -52,6 +52,7 @@ type notification struct {
|
|||
tags string
|
||||
icon string
|
||||
emailAddress string
|
||||
call string
|
||||
silenceBody string
|
||||
fingerprint string
|
||||
status string
|
||||
|
@ -102,6 +103,7 @@ func (br *bridge) singleAlertNotifications(p *payload) []*notification {
|
|||
}
|
||||
|
||||
n.emailAddress = br.cfg.ntfy.emailAddress
|
||||
n.call = br.cfg.ntfy.call
|
||||
|
||||
for _, labelName := range br.cfg.labels.Order {
|
||||
val, ok := alert.Labels[labelName]
|
||||
|
@ -126,6 +128,10 @@ func (br *bridge) singleAlertNotifications(p *payload) []*notification {
|
|||
n.emailAddress = labelConfig.emailAddress
|
||||
}
|
||||
|
||||
if n.call == "" {
|
||||
n.call = labelConfig.call
|
||||
}
|
||||
|
||||
for _, val := range labelConfig.Tags {
|
||||
if !sliceContains(tags, val) {
|
||||
tags = append(tags, val)
|
||||
|
@ -205,6 +211,7 @@ func (br *bridge) multiAlertNotification(p *payload) *notification {
|
|||
}
|
||||
|
||||
n.emailAddress = br.cfg.ntfy.emailAddress
|
||||
n.call = br.cfg.ntfy.call
|
||||
|
||||
for _, labelName := range br.cfg.labels.Order {
|
||||
val, ok := p.CommonLabels[labelName]
|
||||
|
@ -229,6 +236,10 @@ func (br *bridge) multiAlertNotification(p *payload) *notification {
|
|||
n.emailAddress = labelConfig.emailAddress
|
||||
}
|
||||
|
||||
if n.call == "" {
|
||||
n.call = labelConfig.call
|
||||
}
|
||||
|
||||
for _, val := range labelConfig.Tags {
|
||||
if !sliceContains(tags, val) {
|
||||
tags = append(tags, val)
|
||||
|
@ -287,6 +298,10 @@ func (br *bridge) publish(n *notification) error {
|
|||
req.Header.Set("X-Email", n.emailAddress)
|
||||
}
|
||||
|
||||
if n.call != "" {
|
||||
req.Header.Set("X-Call", n.call)
|
||||
}
|
||||
|
||||
if n.silenceBody != "" {
|
||||
url := br.cfg.BaseURL + "/silences"
|
||||
|
||||
|
|
Loading…
Reference in a new issue