summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2012-09-16 16:48:26 +0200
committerDavid Sommerseth <davids@redhat.com>2012-09-16 16:48:26 +0200
commit5add7968b5d0b336d944d3d494778e6318c5e646 (patch)
treedb853114560c5f0b6e63c68e44f81fa0348906dd
parent47e1a42a990732fafb2fb3a06feefca9194d9452 (diff)
downloadlogactio-5add7968b5d0b336d944d3d494778e6318c5e646.tar.gz
logactio-5add7968b5d0b336d944d3d494778e6318c5e646.tar.xz
logactio-5add7968b5d0b336d944d3d494778e6318c5e646.zip
Add support for specific reporter modules in Rule sections
Adding a 'reporters' variable in a [Rule:*] section will override the default reporter defined in [Logfile:*] Signed-off-by: David Sommerseth <davids@redhat.com>
-rw-r--r--LogActio/__init__.py44
1 files changed, 37 insertions, 7 deletions
diff --git a/LogActio/__init__.py b/LogActio/__init__.py
index 7aee369..0e71af3 100644
--- a/LogActio/__init__.py
+++ b/LogActio/__init__.py
@@ -43,18 +43,26 @@ class WatcherThread(threading.Thread):
return self.__logfile
- def AddRule(self, prefix, regex, threshold):
+ def AddRule(self, prefix, regex, threshold, reporters):
# Adds a rule specific for this log file
rule = {"prefix": prefix,
"regex": re.compile(regex),
"threshold": int(threshold),
"current_count": 0,
- "alerts_sent": 0}
+ "alerts_sent": 0,
+ "reporters": reporters}
self.__rules.append(rule)
+
def StartWatcher(self):
- # Start the reporter module
+ # Start the default reporter module
self.__reporter._Start()
+
+ # Start reporter modules declared in rules
+ for r in self.__rules:
+ if r.has_key("reporters") and r["reporters"] is not None:
+ r["reporters"]._Start()
+
# Start the thread with this watcher
self.start()
@@ -88,14 +96,25 @@ class WatcherThread(threading.Thread):
info = "|".join(m.groups()) # Gather regex exctracted info
if len(info) == 0:
info = None
- self.__reporter.ProcessEvent(self.__logfile, alert["prefix"], info,
- alert["current_count"], alert["threshold"])
+
+ # Send the alert event to be processed, prioritise the
+ # rule specific reporter over the default reporter
+ rep = alert.has_key("reporters") and alert["reporters"] or self.__reporter
+ rep.ProcessEvent(self.__logfile, alert["prefix"], info,
+ alert["current_count"], alert["threshold"])
fp.close()
return 0
def Shutdown(self):
self.__shutdown = True
+
+ # Shutdown rule specific reporters
+ for r in self.__rules:
+ if r.has_key("reporters") and r["reporters"] is not None:
+ r["reporters"]._Shutdown()
+
+ # Shutdown default reporters
self.__reporter._Shutdown()
@@ -254,10 +273,21 @@ class LogActio(object):
idx = __logfileidx.index(logf)
except ValueError:
raise Exception("** ERROR ** Logfile '%s' is not configured" % self.__cfg.get(entry, "logfile"))
+ try:
+ # Check if this rule has specific reporters confingured
+ repname = self.__cfg.get(entry, "reporters")
+ reps = __reporters[repname]
+ except ConfigParser.NoOptionError:
+ # If nothing was found, that's okay
+ reps = None
+ except KeyError, e:
+ raise Exception("No reporters are configured as '%s'" % repname)
+
# Add the rule to the proper WatchThread
self.__watchthreads[idx].AddRule(rulename,
- self.__cfg.get(entry, "regex"),
- self.__cfg.get(entry, "threshold"))
+ self.__cfg.get(entry, "regex"),
+ self.__cfg.get(entry, "threshold"),
+ reps)
del __logfileidx