From 6f686f2b09a5230b5d792c6690ce94adc2abee41 Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Mon, 20 May 2013 12:05:28 -0700 Subject: [PATCH] Attach multiple tags to logstash events. * modules/openstack_project/files/logstash/log-pusher.py: If a list of tags is provided under a source file configured in the yaml config attach those tags to the log events generated from that source file. Example yaml: source-files: - name: console.html retry-get: True tags: - foo - bar Change-Id: Ib74abad2d06d3e52e5b21b0fb38033f9474ab4e4 Reviewed-on: https://review.openstack.org/29808 Reviewed-by: James E. Blair Approved: Clark Boylan Reviewed-by: Clark Boylan Tested-by: Jenkins --- .../openstack_project/files/logstash/log-pusher.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/openstack_project/files/logstash/log-pusher.py b/modules/openstack_project/files/logstash/log-pusher.py index 86c2a69f24..a07f0d3f54 100644 --- a/modules/openstack_project/files/logstash/log-pusher.py +++ b/modules/openstack_project/files/logstash/log-pusher.py @@ -94,7 +94,7 @@ class LogRetriever(threading.Thread): } def __init__(self, eventq, logq, log_address, - filename, retry=False, job_filter=''): + filename, retry=False, job_filter='', tags=None): threading.Thread.__init__(self) self.eventq = eventq self.logq = logq @@ -102,7 +102,9 @@ class LogRetriever(threading.Thread): self.log_address = log_address self.filename = filename self.job_filter = job_filter - self.tag = [self.filename] + self.tags = [self.filename] + if tags: + self.tags.extend(tags) def run(self): while True: @@ -125,7 +127,7 @@ class LogRetriever(threading.Thread): for line in log_lines: out_event = {} out_event["@fields"] = fields - out_event["@tags"] = self.tag + out_event["@tags"] = self.tags out_event["event_message"] = line self.logq.put(out_event) @@ -308,8 +310,8 @@ class Server(object): source_file['name'], retry=source_file.get('retry-get', self.default_retry), - job_filter=source_file.get('filter', - '')) + job_filter=source_file.get('filter', ''), + tags=source_file.get('tags', [])) self.retrievers.append(retriever) def setup_catchers(self):