[BUGFIX] show hostname

This commit is contained in:
Martin Geno 2017-11-05 17:23:10 +01:00
parent 5699de00cb
commit c46cea3c7a
No known key found for this signature in database
GPG Key ID: F0D39A37E925E941
2 changed files with 9 additions and 6 deletions

View File

@ -19,10 +19,10 @@ type NotifyState struct {
LastseenNotify map[string]time.Time `json:"-"` 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) hostname, ok := e.Data["hostname"].(string)
if !ok { if !ok {
return nil return e, nil
} }
if to, ok := state.HostTo[hostname]; ok { if to, ok := state.HostTo[hostname]; ok {
if e.Message != AlertMsg && hostname != "" { if e.Message != AlertMsg && hostname != "" {
@ -48,13 +48,16 @@ func (state *NotifyState) SendTo(e *log.Entry) []string {
toList = append(toList, toEntry) toList = append(toList, toEntry)
} }
if replaceHostname, ok := state.Hostname[hostname]; ok { 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 { } else {
state.HostTo[hostname] = make(map[string]bool) state.HostTo[hostname] = make(map[string]bool)
} }
return nil return e, nil
} }
func (state *NotifyState) AddRegex(to, expression string) error { func (state *NotifyState) AddRegex(to, expression string) error {

View File

@ -64,7 +64,7 @@ func Init(config *lib.NotifyConfig, state *configNotify.NotifyState, bot *bot.Bo
} }
func (n *Notifier) Fire(e *log.Entry) error { func (n *Notifier) Fire(e *log.Entry) error {
to := n.state.SendTo(e) e, to := n.state.SendTo(e)
if to == nil { if to == nil {
return errors.New("no reciever found") return errors.New("no reciever found")
} }