Module: check_mk
Branch: master
Commit: ae650865e2fa591d86254b10255ef1e9f47acb1c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ae650865e2fa59…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Thu Apr 4 09:57:05 2019 +0200
mk_mongodb: isolate piggyback logic
Change-Id: I862d37113bf74ab1c9bafbd7348c72e9313488b1
---
agents/plugins/mk_mongodb | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/agents/plugins/mk_mongodb b/agents/plugins/mk_mongodb
index b272559..b93d5ad 100755
--- a/agents/plugins/mk_mongodb
+++ b/agents/plugins/mk_mongodb
@@ -15,9 +15,22 @@ import os
import pprint
import sys
import time
+from contextlib import contextmanager
import pymongo # pylint: disable=import-error
+@contextmanager
+def piggyback(info):
+ piggyhost = info.get("setName") if info else None
+ if piggyhost:
+ sys.stdout.write("<<<<%s>>>>\n" % piggyhost)
+ try:
+ yield
+ finally:
+ if piggyhost:
+ sys.stdout.write("<<<<>>>>\n")
+
+
def section_instance(server_status):
sys.stdout.write("<<<mongodb_instance:sep(9)>>>\n")
sys.stdout.write("version\t%s\n" % server_status["version"])
@@ -68,11 +81,8 @@ def main():
if repl_info and not repl_info.get("ismaster"):
return
- if repl_info:
- sys.stdout.write("<<<<%s>>>>\n" %
repl_info["setName"])
- potentially_piggybacked_sections(client, server_status, repl_info)
- if repl_info:
- sys.stdout.write("<<<<>>>>\n")
+ with piggyback(repl_info):
+ potentially_piggybacked_sections(client, server_status, repl_info)
def potentially_piggybacked_sections(client, server_status, repl_info):