diff --git a/database/main.go b/database/main.go index e974b11..a205a3a 100644 --- a/database/main.go +++ b/database/main.go @@ -46,24 +46,18 @@ func (db *DB) SendTo(e *log.Entry) (*log.Entry, *Host, []*Notify) { } // return default notify list if host.Notifies == nil || len(host.Notifies) == 0 { - return entry, host, db.DefaultNotify - } - // return with host specify list - for _, notify := range host.NotifiesByAddress { - if lvl := notify.MaxPrioIn; e.Level >= lvl { - continue - } - stopForTo := false - for _, expr := range notify.RegexIn { - if expr.MatchString(e.Message) { - stopForTo = true - continue + for _, notify := range db.DefaultNotify { + if notify.Send(e) { + toList = append(toList, notify) } } - if stopForTo { - continue + } else { + // return with host specify list + for _, notify := range host.NotifiesByAddress { + if notify.Send(e) { + toList = append(toList, notify) + } } - toList = append(toList, notify) } return entry, host, toList } diff --git a/database/notify.go b/database/notify.go index 3963d30..c9f2527 100644 --- a/database/notify.go +++ b/database/notify.go @@ -68,6 +68,18 @@ func (n *Notify) Address() string { return n.Protocol + ":" + n.To } +func (n *Notify) Send(e *log.Entry) bool { + if lvl := n.MaxPrioIn; e.Level >= lvl { + return false + } + for _, expr := range n.RegexIn { + if expr.MatchString(e.Message) { + return false + } + } + return true +} + // -- global notify func (db *DB) InitNotify() { @@ -79,7 +91,6 @@ func (db *DB) InitNotify() { db.NotifiesByAddress[n.Address()] = n } } - func (db *DB) AddNotify(n *Notify) { db.Notifies = append(db.Notifies, n) db.NotifiesByAddress[n.Address()] = n