--- a/pvl/syslog/rule.py Thu Jan 03 13:06:30 2013 +0200
+++ b/pvl/syslog/rule.py Thu Jan 03 13:14:29 2013 +0200
@@ -23,6 +23,11 @@
def apply (self, item) :
"""
Apply rule against given item.
+
+ Returns
+ None - skip
+ False - drop
+ (tag, line) - output
"""
# filter
@@ -51,4 +56,38 @@
if self.format :
# return
return self.tag, self.format.format(**item)
-
+
+class SyslogRules (object) :
+ """
+ Apply a set of rules against lines.
+ """
+
+ def __init__ (self, rules) :
+ self.rules = rules
+
+ def apply (self, item) :
+ """
+ Apply item against our rules, returning the first match (False/tag-line).
+ """
+
+ for rule in self.rules :
+ match = rule.apply(item)
+
+ if match is None :
+ continue
+ else :
+ break
+
+ return match
+
+ def process (self, items) :
+ """
+ Apply items against our rules, yielding any matches.
+ """
+
+ for item in items :
+ match = self.apply(item)
+
+ if match :
+ yield match
+