filter also default
This commit is contained in:
		
							parent
							
								
									0ebee067dc
								
							
						
					
					
						commit
						d2ca796145
					
				| 
						 | 
					@ -46,25 +46,19 @@ 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) {
 | 
				
			||||||
 | 
										toList = append(toList, notify)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
			// return with host specify list
 | 
								// return with host specify list
 | 
				
			||||||
			for _, notify := range host.NotifiesByAddress {
 | 
								for _, notify := range host.NotifiesByAddress {
 | 
				
			||||||
			if lvl := notify.MaxPrioIn; e.Level >= lvl {
 | 
									if notify.Send(e) {
 | 
				
			||||||
				continue
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			stopForTo := false
 | 
					 | 
				
			||||||
			for _, expr := range notify.RegexIn {
 | 
					 | 
				
			||||||
				if expr.MatchString(e.Message) {
 | 
					 | 
				
			||||||
					stopForTo = true
 | 
					 | 
				
			||||||
					continue
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			if stopForTo {
 | 
					 | 
				
			||||||
				continue
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
					toList = append(toList, notify)
 | 
										toList = append(toList, notify)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		return entry, host, toList
 | 
							return entry, host, toList
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	host = db.NewHost(addr)
 | 
						host = db.NewHost(addr)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue