mirror of
https://github.com/crazy-max/diun.git
synced 2025-12-27 23:46:31 +01:00
Configuration transposed into environment variables (#82)
Configuration file not required anymore DIUN_DB env var renamed DIUN_DB_PATH Only accept duration as timeout value (10 becomes 10s) Add getting started doc Enhanced documentation Add note about test notifications (#79) Improve configuration management Fix telegram init All fields in configuration now camelCased Improve configuration validation Update doc Update FAQ Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package notif
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/crazy-max/diun/v3/internal/model"
|
||||
"github.com/crazy-max/diun/v3/internal/notif/amqp"
|
||||
"github.com/crazy-max/diun/v3/internal/notif/gotify"
|
||||
@@ -18,15 +20,15 @@ import (
|
||||
// Client represents an active webhook notification object
|
||||
type Client struct {
|
||||
cfg *model.Notif
|
||||
app model.App
|
||||
meta model.Meta
|
||||
notifiers []notifier.Notifier
|
||||
}
|
||||
|
||||
// New creates a new notification instance
|
||||
func New(config *model.Notif, app model.App, userAgent string) (*Client, error) {
|
||||
func New(config *model.Notif, meta model.Meta) (*Client, error) {
|
||||
var c = &Client{
|
||||
cfg: config,
|
||||
app: app,
|
||||
meta: meta,
|
||||
notifiers: []notifier.Notifier{},
|
||||
}
|
||||
|
||||
@@ -37,31 +39,31 @@ func New(config *model.Notif, app model.App, userAgent string) (*Client, error)
|
||||
|
||||
// Add notifiers
|
||||
if config.Amqp != nil {
|
||||
c.notifiers = append(c.notifiers, amqp.New(config.Amqp, app))
|
||||
c.notifiers = append(c.notifiers, amqp.New(config.Amqp, meta))
|
||||
}
|
||||
if config.Gotify != nil {
|
||||
c.notifiers = append(c.notifiers, gotify.New(config.Gotify, app, userAgent))
|
||||
c.notifiers = append(c.notifiers, gotify.New(config.Gotify, meta))
|
||||
}
|
||||
if config.Mail != nil {
|
||||
c.notifiers = append(c.notifiers, mail.New(config.Mail, app))
|
||||
c.notifiers = append(c.notifiers, mail.New(config.Mail, meta))
|
||||
}
|
||||
if config.RocketChat != nil {
|
||||
c.notifiers = append(c.notifiers, rocketchat.New(config.RocketChat, app, userAgent))
|
||||
c.notifiers = append(c.notifiers, rocketchat.New(config.RocketChat, meta))
|
||||
}
|
||||
if config.Script != nil {
|
||||
c.notifiers = append(c.notifiers, script.New(config.Script, app))
|
||||
c.notifiers = append(c.notifiers, script.New(config.Script, meta))
|
||||
}
|
||||
if config.Slack != nil {
|
||||
c.notifiers = append(c.notifiers, slack.New(config.Slack, app))
|
||||
c.notifiers = append(c.notifiers, slack.New(config.Slack, meta))
|
||||
}
|
||||
if config.Teams != nil {
|
||||
c.notifiers = append(c.notifiers, teams.New(config.Teams, app, userAgent))
|
||||
c.notifiers = append(c.notifiers, teams.New(config.Teams, meta))
|
||||
}
|
||||
if config.Telegram != nil {
|
||||
c.notifiers = append(c.notifiers, telegram.New(config.Telegram, app))
|
||||
c.notifiers = append(c.notifiers, telegram.New(config.Telegram, meta))
|
||||
}
|
||||
if config.Webhook != nil {
|
||||
c.notifiers = append(c.notifiers, webhook.New(config.Webhook, app, userAgent))
|
||||
c.notifiers = append(c.notifiers, webhook.New(config.Webhook, meta))
|
||||
}
|
||||
|
||||
log.Debug().Msgf("%d notifier(s) created", len(c.notifiers))
|
||||
@@ -73,7 +75,7 @@ func (c *Client) Send(entry model.NotifEntry) {
|
||||
for _, n := range c.notifiers {
|
||||
log.Debug().Str("image", entry.Image.String()).Msgf("Sending %s notification...", n.Name())
|
||||
if err := n.Send(entry); err != nil {
|
||||
log.Error().Err(err).Str("image", entry.Image.String()).Msgf("%s notification failed", n.Name())
|
||||
log.Error().Err(err).Str("image", entry.Image.String()).Msgf("%s notification failed", strings.Title(n.Name()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user