Module: check_mk
Branch: master
Commit: 5d7b6f1b67b10d83877cc8a8e5cdad81c609d9e3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5d7b6f1b67b10d…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Oct 20 13:30:42 2017 +0200
notify.log: Refactored livestatus communication
* Use standard livestatus python API
* Marked helper function as private one
Change-Id: I9587a2818550d4b61d100a83a1f5247414b7c362
---
cmk_base/notify.py | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)
diff --git a/cmk_base/notify.py b/cmk_base/notify.py
index dd7955b..5e697b0 100644
--- a/cmk_base/notify.py
+++ b/cmk_base/notify.py
@@ -1742,20 +1742,6 @@ def substitute_context(template, context):
# | Some generic helper functions |
# '----------------------------------------------------------------------'
-def livestatus_send_command(command):
- try:
- message = "COMMAND [%d] %s\n" % (time.time(), command)
- sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
- sock.connect(cmk.paths.livestatus_unix_socket)
- sock.send(message)
- sock.close()
- except Exception, e:
- if cmk.debug.enabled():
- raise
- notify_log("WARNING: cannot send livestatus command: %s" % e)
- notify_log("Command was: %s" % command)
-
-
def format_exception():
import traceback, StringIO, sys
txt = StringIO.StringIO()
@@ -1809,4 +1795,14 @@ def core_notification_log(plugin, plugin_context):
log_message = "%s NOTIFICATION: %s;%s;%s;%s;%s" % (
what, contact, spec, state, plugin or "plain email", output)
- livestatus_send_command("LOG;" + log_message.encode("utf-8"))
+ _send_livestatus_command("LOG;%s" % log_message)
+
+
+def _send_livestatus_command(command):
+ try:
+ livestatus.LocalConnection().command("[%d] %s" % (time.time(),
command.encode("utf-8")))
+ except Exception, e:
+ if cmk.debug.enabled():
+ raise
+ notify_log("WARNING: cannot send livestatus command: %s" % e)
+ notify_log("Command was: %s" % command)