Module: check_mk
Branch: master
Commit: 06ed3c299286c6fe30e2390e82eff48a854ed529
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=06ed3c299286c6…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Jul 22 08:16:02 2016 +0200
EC: Fixed master/slave sync; removed various debug logs from EC code
---
bin/mkeventd | 13 ++++++-------
web/htdocs/mkeventd.py | 31 +++++++++++++++++++++++++++++++
web/plugins/wato/mkeventd.py | 12 +++++-------
3 files changed, 42 insertions(+), 14 deletions(-)
diff --git a/bin/mkeventd b/bin/mkeventd
index 5e23175..c0f73c6 100755
--- a/bin/mkeventd
+++ b/bin/mkeventd
@@ -623,16 +623,12 @@ def update_mongodb_history_lifetime():
except OperationFailure:
pass # Ignore not existing index
- log(repr(g_config['history_lifetime']))
-
# Delete messages after x days
g_mongo_db.ec_archive.ensure_index([('dt', DESCENDING)],
expireAfterSeconds = g_config['history_lifetime'],
unique = False
)
- log(repr(get_mongodb_max_history_age()))
-
def mongodb_next_id(name, first_id = 0):
ret = g_mongo_db.counters.find_and_modify(
query = { '_id': name },
@@ -2225,7 +2221,6 @@ class EventServer:
elif type(rule["state"]) == tuple and rule["state"][0] ==
"text_pattern":
for key in [ '2', '1', '0', '3' ]:
if key in rule["state"][1]:
- log(repr(rule["state"][1][key]))
match_groups = match(rule["state"][1][key],
event["text"], complete = False)
if match_groups != False:
event["state"] = int(key)
@@ -2711,7 +2706,9 @@ class StatusServer:
continue
else:
allow_commands = True
- self.handle_client(client_socket, allow_commands, addr_info and
addr_info[0] or "")
+
+ self.handle_client(client_socket, allow_commands,
+ addr_info and addr_info[0] or "")
g_perfcounters.count_time("request", time.time() - before)
except Exception, e:
@@ -3794,7 +3791,9 @@ def get_state_from_master():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(repl_settings["connect_timeout"])
sock.connect(repl_settings["master"])
- sock.sendall("REPLICATE %d\n" % (g_slave_status["last_sync"]
and g_slave_status["last_sync"] or 0))
+ sock.sendall("REPLICATE %d\n" %
+ (g_slave_status["last_sync"] and
g_slave_status["last_sync"] or 0))
+ sock.shutdown(socket.SHUT_WR)
response_text = ""
while True:
diff --git a/web/htdocs/mkeventd.py b/web/htdocs/mkeventd.py
index 9622dca..38e4de6 100644
--- a/web/htdocs/mkeventd.py
+++ b/web/htdocs/mkeventd.py
@@ -181,6 +181,37 @@ def send_event(event):
return rfc
+# Only use this for master/slave replication. For status queries use livestatus
+def query_ec_directly(query):
+ try:
+ sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ try:
+ timeout = config.mkeventd_connect_timeout
+ except:
+ timeout = 10
+
+ sock.settimeout(timeout)
+ sock.connect(socket_path)
+ sock.sendall(query)
+ sock.shutdown(socket.SHUT_WR)
+
+ response_text = ""
+ while True:
+ chunk = sock.recv(8192)
+ response_text += chunk
+ if not chunk:
+ break
+
+ return eval(response_text)
+ except SyntaxError, e:
+ raise MKGeneralException(_("Invalid response from event daemon: "
+ "<pre>%s</pre>") % response_text)
+
+ except Exception, e:
+ raise MKGeneralException(_("Cannot connect to event daemon via %s: %s")
%
+ (socket_path, e))
+
+
def execute_command(name, args=None, site=None):
if args:
formated_args = ";" + ";".join(args)
diff --git a/web/plugins/wato/mkeventd.py b/web/plugins/wato/mkeventd.py
index 4ecf996..1d221f4 100644
--- a/web/plugins/wato/mkeventd.py
+++ b/web/plugins/wato/mkeventd.py
@@ -1359,14 +1359,12 @@ def mode_mkeventd_rules(phase):
table.end()
-# TODO: Make use of ec via livestatus when core is ready
def copy_rules_from_master():
- raise MKGeneralException(_("This is not working at the moment. Will fix this
soon."))
- #answer = mkeventd.query("REPLICATE 0")
- #if "rules" not in answer:
- # raise MKGeneralException(_("Cannot get rules from local event
daemon."))
- #rule_packs = answer["rules"]
- #save_mkeventd_rules([], rule_packs)
+ answer = mkeventd.query_ec_directly("REPLICATE 0")
+ if "rules" not in answer:
+ raise MKGeneralException(_("Cannot get rules from local event
daemon."))
+ rule_packs = answer["rules"]
+ save_mkeventd_rules([], rule_packs)
def mode_mkeventd_edit_rule_pack(phase):