mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-14 06:06:38 +01:00
feat(notifications): add title field to template data (#1125)
This commit is contained in:
parent
1d59fb83dd
commit
aa02d8d31b
9 changed files with 94 additions and 35 deletions
|
|
@ -58,6 +58,7 @@ type shoutrrrTypeNotifier struct {
|
|||
done chan bool
|
||||
legacyTemplate bool
|
||||
params *types.Params
|
||||
hostname string
|
||||
}
|
||||
|
||||
// GetScheme returns the scheme part of a Shoutrrr URL
|
||||
|
|
@ -78,10 +79,11 @@ func (n *shoutrrrTypeNotifier) GetNames() []string {
|
|||
return names
|
||||
}
|
||||
|
||||
func newShoutrrrNotifier(tplString string, acceptedLogLevels []log.Level, legacy bool, title string, delay time.Duration, urls ...string) t.Notifier {
|
||||
func newShoutrrrNotifier(tplString string, acceptedLogLevels []log.Level, legacy bool, hostname string, delay time.Duration, urls ...string) t.Notifier {
|
||||
|
||||
notifier := createNotifier(urls, acceptedLogLevels, tplString, legacy)
|
||||
notifier.params = &types.Params{"title": title}
|
||||
notifier.hostname = hostname
|
||||
notifier.params = &types.Params{"title": GetTitle(hostname)}
|
||||
log.AddHook(notifier)
|
||||
|
||||
// Do the sending in a separate goroutine so we don't block the main process.
|
||||
|
|
@ -147,7 +149,9 @@ func (n *shoutrrrTypeNotifier) buildMessage(data Data) (string, error) {
|
|||
}
|
||||
|
||||
func (n *shoutrrrTypeNotifier) sendEntries(entries []*log.Entry, report t.Report) {
|
||||
msg, err := n.buildMessage(Data{entries, report})
|
||||
title, _ := n.params.Title()
|
||||
host := n.hostname
|
||||
msg, err := n.buildMessage(Data{entries, report, title, host})
|
||||
|
||||
if msg == "" {
|
||||
// Log in go func in case we entered from Fire to avoid stalling
|
||||
|
|
@ -240,4 +244,6 @@ func getShoutrrrTemplate(tplString string, legacy bool) (tpl *template.Template,
|
|||
type Data struct {
|
||||
Entries []*log.Entry
|
||||
Report t.Report
|
||||
Title string
|
||||
Host string
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue