From c46cea3c7af073ed76019fe7fc90cf4c1f536355 Mon Sep 17 00:00:00 2001 From: Martin Geno Date: Sun, 5 Nov 2017 17:23:10 +0100 Subject: [PATCH] [BUGFIX] show hostname --- notify/config/config.go | 13 ++++++++----- notify/xmpp/main.go | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/notify/config/config.go b/notify/config/config.go index 91844b3..8b3aa69 100644 --- a/notify/config/config.go +++ b/notify/config/config.go @@ -19,10 +19,10 @@ type NotifyState struct { LastseenNotify map[string]time.Time `json:"-"` } -func (state *NotifyState) SendTo(e *log.Entry) []string { +func (state *NotifyState) SendTo(e *log.Entry) (*log.Entry, []string) { hostname, ok := e.Data["hostname"].(string) if !ok { - return nil + return e, nil } if to, ok := state.HostTo[hostname]; ok { if e.Message != AlertMsg && hostname != "" { @@ -48,13 +48,16 @@ func (state *NotifyState) SendTo(e *log.Entry) []string { toList = append(toList, toEntry) } if replaceHostname, ok := state.Hostname[hostname]; ok { - e.WithField("hostname", replaceHostname) + entry := e.WithField("hostname", replaceHostname) + entry.Level = e.Level + entry.Message = e.Message + return entry, toList } - return toList + return e, toList } else { state.HostTo[hostname] = make(map[string]bool) } - return nil + return e, nil } func (state *NotifyState) AddRegex(to, expression string) error { diff --git a/notify/xmpp/main.go b/notify/xmpp/main.go index cf62e16..4c20501 100644 --- a/notify/xmpp/main.go +++ b/notify/xmpp/main.go @@ -64,7 +64,7 @@ func Init(config *lib.NotifyConfig, state *configNotify.NotifyState, bot *bot.Bo } func (n *Notifier) Fire(e *log.Entry) error { - to := n.state.SendTo(e) + e, to := n.state.SendTo(e) if to == nil { return errors.New("no reciever found") }