filter also default
This commit is contained in:
parent
0ebee067dc
commit
d2ca796145
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue