Module: check_mk
Branch: master
Commit: 44fb3de2486ff00abb8a07429e1839cc97e72940
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=44fb3de2486ff0…
Author: Óscar Nájera <on(a)mathias-kettner.de>
Date: Fri Sep 21 10:35:23 2018 +0200
Extract read_bulk_contexts
Change-Id: I1c6959e5e84a6dbf2832f54ab2daf6a83ebb14c7
---
cmk/notification_plugins/asciimail.py | 30 +-----------------------------
cmk/notification_plugins/mail.py | 25 +------------------------
cmk/notification_plugins/utils.py | 27 +++++++++++++++++++++++++++
3 files changed, 29 insertions(+), 53 deletions(-)
diff --git a/cmk/notification_plugins/asciimail.py
b/cmk/notification_plugins/asciimail.py
index 98b55ad..9fee7ef 100644
--- a/cmk/notification_plugins/asciimail.py
+++ b/cmk/notification_plugins/asciimail.py
@@ -141,34 +141,6 @@ def construct_content(context):
return body
-def read_bulk_contexts():
- parameters = {}
- contexts = []
- in_params = True
-
- # First comes a section with global variables
- for line in sys.stdin:
- line = line.strip()
- if not line:
- in_params = False
- context = {}
- contexts.append(context)
- else:
- try:
- key, value = line.split("=", 1)
- value = value.replace("\1", "\n")
- except:
- sys.stderr.write("Invalid line '%s' in bulked notification
context\n" % line)
- continue
-
- if in_params:
- parameters[key] = value
- else:
- context[key] = value
-
- return parameters, contexts
-
-
def find_wato_folder(context):
# Same as in notify.py
for tag in context.get("HOSTTAGS", "").split():
@@ -210,7 +182,7 @@ def get_bulk_notification_subject(contexts, hosts):
def main():
if bulk_mode:
content_txt = ""
- parameters, contexts = read_bulk_contexts()
+ parameters, contexts = utils.read_bulk_contexts()
hosts = set([])
for context in contexts:
context.update(parameters)
diff --git a/cmk/notification_plugins/mail.py b/cmk/notification_plugins/mail.py
index 9a83ce9..db54919 100644
--- a/cmk/notification_plugins/mail.py
+++ b/cmk/notification_plugins/mail.py
@@ -917,29 +917,6 @@ def render_elements(context, elements):
utils.substitute_context(tmpl_html, context)
-def read_bulk_contexts():
- parameters = {}
- contexts = []
- in_params = True
-
- # First comes a section with global variables
- for line in sys.stdin:
- line = line.strip()
- if not line:
- in_params = False
- context = {}
- contexts.append(context)
- else:
- key, value = line.split("=", 1)
- value = value.replace("\1", "\n")
- if in_params:
- parameters[key] = value
- else:
- context[key] = value
-
- return parameters, contexts
-
-
def find_wato_folder(context):
# Same as in notify.py
for tag in context.get("HOSTTAGS", "").split():
@@ -983,7 +960,7 @@ def main():
attachments = []
content_txt = ""
content_html = ""
- parameters, contexts = read_bulk_contexts()
+ parameters, contexts = utils.read_bulk_contexts()
hosts = set([])
for context in contexts:
context.update(parameters)
diff --git a/cmk/notification_plugins/utils.py b/cmk/notification_plugins/utils.py
index 37f61fa..3299cd2 100644
--- a/cmk/notification_plugins/utils.py
+++ b/cmk/notification_plugins/utils.py
@@ -142,3 +142,30 @@ def send_mail_sendmail(m, target, from_address):
sys.stdout.write("Spooled mail to local mail transmission agent\n")
return 0
+
+def read_bulk_contexts():
+ parameters = {}
+ contexts = []
+ in_params = True
+
+ # First comes a section with global variables
+ for line in sys.stdin:
+ line = line.strip()
+ if not line:
+ in_params = False
+ context = {}
+ contexts.append(context)
+ else:
+ try:
+ key, value = line.split("=", 1)
+ value = value.replace("\1", "\n")
+ except:
+ sys.stderr.write("Invalid line '%s' in bulked notification
context\n" % line)
+ continue
+
+ if in_params:
+ parameters[key] = value
+ else:
+ context[key] = value
+
+ return parameters, contexts