filter also default

This commit is contained in:
Martin/Geno 2019-06-30 09:33:45 +02:00
parent 0ebee067dc
commit d2ca796145
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
2 changed files with 21 additions and 16 deletions

View File

@ -46,24 +46,18 @@ func (db *DB) SendTo(e *log.Entry) (*log.Entry, *Host, []*Notify) {
} }
// return default notify list // return default notify list
if host.Notifies == nil || len(host.Notifies) == 0 { if host.Notifies == nil || len(host.Notifies) == 0 {
return entry, host, db.DefaultNotify for _, notify := range db.DefaultNotify {
} if notify.Send(e) {
// return with host specify list toList = append(toList, notify)
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
} }
} }
if stopForTo { } else {
continue // 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 return entry, host, toList
} }

View File

@ -68,6 +68,18 @@ func (n *Notify) Address() string {
return n.Protocol + ":" + n.To 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 // -- global notify
func (db *DB) InitNotify() { func (db *DB) InitNotify() {
@ -79,7 +91,6 @@ func (db *DB) InitNotify() {
db.NotifiesByAddress[n.Address()] = n db.NotifiesByAddress[n.Address()] = n
} }
} }
func (db *DB) AddNotify(n *Notify) { func (db *DB) AddNotify(n *Notify) {
db.Notifies = append(db.Notifies, n) db.Notifies = append(db.Notifies, n)
db.NotifiesByAddress[n.Address()] = n db.NotifiesByAddress[n.Address()] = n