[BUGFIX] show hostname
This commit is contained in:
parent
5699de00cb
commit
c46cea3c7a
|
@ -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 {
|
||||||
|
|
|
@ -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")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue