Module: check_mk
Branch: master
Commit: 55300bc53082ce7d6d80786bc4170bd03bc56b4a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=55300bc53082ce…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Nov 4 12:40:58 2016 +0100
Fixed handling of not logged in sites
---
web/htdocs/htmllib.py | 2 +-
web/htdocs/wato.py | 19 +++++-------
web/htdocs/watolib.py | 73 +++++++++++++++++++++++++++++++-------------
web/plugins/wato/mkeventd.py | 21 +++++++++++++
4 files changed, 82 insertions(+), 33 deletions(-)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 10821c6..29714d2 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -1478,7 +1478,7 @@ class html(DeprecationWrapper):
for key, val in self.all_vars().items():
if key not in [ "request", "output_format" ] +
exclude_vars:
- request[key] = val
+ request[key] = val.decode("utf-8")
return request
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index f6e9dd5..a3e2aab 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -4920,18 +4920,13 @@ class ModeActivateChanges(WatoMode, ActivateChanges):
def _activation_status(self):
table.begin("site-status", searchable=False, sortable=False)
- for site_id, site in sort_sites(wato_activation_sites()):
+ for site_id, site in sort_sites(self._activation_sites()):
table.row()
- if site.get("disabled"):
- site_status = {}
- status = "disabled"
- else:
- site_status = sites.state(site_id, {})
- status = site_status.get("state", "unknown")
+ site_status, status = self._get_site_status(site_id, site)
- is_online = status in [ "online", "disabled" ]
- is_logged_in = config.site_is_local(site_id) or "secret" in
site
+ is_online = self._site_is_online(status)
+ is_logged_in = self._site_is_logged_in(site_id, site)
has_foreign = self._site_has_foreign_changes(site_id)
can_activate_all = not has_foreign or
config.user.may("wato.activateforeign")
@@ -5036,9 +5031,11 @@ class ModeAjaxStartActivation(WatoWebApiMode):
if not activate_until:
raise MKUserError("activate_until", _("Missing parameter
\"%s\".") % "activate_until")
+ manager = ActivateChangesManager()
+
sites = request.get("sites", "").strip()
if not sites:
- sites = get_dirty_sites()
+ sites = manager.dirty_and_active_activation_sites()
else:
sites = sites.split(",")
@@ -5048,7 +5045,6 @@ class ModeAjaxStartActivation(WatoWebApiMode):
activate_foreign = request.get("activate_foreign", "0") ==
"1"
- manager = ActivateChangesManager()
activation_id = manager.start(sites, activate_until, comment, activate_foreign)
return {
@@ -5057,6 +5053,7 @@ class ModeAjaxStartActivation(WatoWebApiMode):
+
class ModeAjaxActivationState(WatoWebApiMode):
def page(self):
init_wato_datastructures()
diff --git a/web/htdocs/watolib.py b/web/htdocs/watolib.py
index a088dfa..0590f9d 100644
--- a/web/htdocs/watolib.py
+++ b/web/htdocs/watolib.py
@@ -168,13 +168,17 @@ def log_entry(linkinfo, action, message, user_id=None):
link = linkinfo
if user_id == None and config.user.id != None:
- user_id = config.user.id.encode("utf-8")
+ user_id = config.user.id
elif user_id == '':
user_id = '-'
+ if user_id:
+ user_id = user_id.encode("utf-8")
+
make_nagios_directory(os.path.dirname(audit_log_path))
with create_user_file(audit_log_path, "ab") as f:
- f.write("%d %s %s %s %s\n" % (int(time.time()), link, user_id, action,
message))
+ f.write("%d %s %s %s %s\n" % (int(time.time()), link, user_id,
+ action, message))
def log_audit(linkinfo, action, message, user_id = None):
@@ -3481,12 +3485,6 @@ def wato_slave_sites():
if site.get("replication") ]
-def wato_activation_sites():
- return [ (site_id, site) for site_id, site in config.configured_sites()
- if config.site_is_local(site_id)
- or site.get("replication") ]
-
-
def declare_site_attribute():
undeclare_host_attribute("site")
declare_host_attribute(SiteAttribute(), show_in_table = True, show_in_folder = True)
@@ -3580,15 +3578,6 @@ def update_login_sites_replication_status():
update_replication_status(site_id, {'need_sync': True})
-def get_dirty_sites():
- dirty = []
- repstatus = load_replication_status()
- for site_id, _unused_site in wato_activation_sites():
- if repstatus[site_id].get("changes", []):
- dirty.append(site_id)
- return dirty
-
-
def automation_push_snapshot():
site_id = html.var("siteid")
@@ -3783,7 +3772,47 @@ class ActivateChanges(object):
def _changes_of_site(self, site_id):
- return self._repstatus[site_id].get("changes", [])
+ return self._repstatus.get(site_id, {}).get("changes", [])
+
+
+ # Returns the list of sites that should be shown on activation page
+ def _activation_sites(self):
+ return [ (site_id, site) for site_id, site in config.configured_sites()
+ if config.site_is_local(site_id)
+ or site.get("replication") ]
+
+
+ # Returns the list of sites that should be used when activating all
+ # affected sites.
+ def dirty_and_active_activation_sites(self):
+ dirty = []
+ for site_id, site in self._activation_sites():
+ status = self._get_site_status(site_id, site)[1]
+ is_online = self._site_is_online(status)
+ is_logged_in = self._site_is_logged_in(site_id, site)
+
+ if is_online and is_logged_in and self._changes_of_site(site_id):
+ dirty.append(site_id)
+ return dirty
+
+
+ def _site_is_logged_in(self, site_id, site):
+ return config.site_is_local(site_id) or "secret" in site
+
+
+ def _site_is_online(self, status):
+ return status in [ "online", "disabled" ]
+
+
+ def _get_site_status(self, site_id, site):
+ if site.get("disabled"):
+ site_status = {}
+ status = "disabled"
+ else:
+ site_status = sites.state(site_id, {})
+ status = site_status.get("state", "unknown")
+
+ return site_status, status
def _site_has_foreign_changes(self, site_id):
@@ -3803,7 +3832,7 @@ class ActivateChanges(object):
def _last_activation_state(self, site_id):
- last_activation_id = self._repstatus[site_id].get("last_activation")
+ last_activation_id = self._repstatus.get(site_id,
{}).get("last_activation")
manager = ActivateChangesManager()
try:
manager.load(last_activation_id)
@@ -3937,7 +3966,7 @@ class ActivateChangesManager(ActivateChanges):
def _get_sites(self, sites):
for site_id in sites:
- if site_id not in dict(wato_activation_sites()):
+ if site_id not in dict(self._activation_sites()):
raise MKUserError("sites", _("The site \"%s\"
does not exist.") % site_id)
return sites
@@ -4189,6 +4218,8 @@ class ActivateChangesSite(threading.Thread, ActivateChanges):
if self._is_activate_needed(self._site_id):
configuration_warnings = self._do_activate()
+ else:
+ configuration_warnings = []
self._confirm_activated_changes()
@@ -4524,7 +4555,7 @@ def create_snapshot(comment):
data["comment"] = _("Activated changes by %s.") % config.user.id
if comment:
- data["comment"] = _("Comment: %s") % comment
+ data["comment"] += _("Comment: %s") % comment
data["created_by"] = config.user.id
data["type"] = "automatic"
diff --git a/web/plugins/wato/mkeventd.py b/web/plugins/wato/mkeventd.py
index 687e930..359d420 100644
--- a/web/plugins/wato/mkeventd.py
+++ b/web/plugins/wato/mkeventd.py
@@ -1675,6 +1675,27 @@ def mode_mkeventd_changes(phase):
else:
html.write("<div class=info>" + _("There are no pending
changes.") + "</div>")
+
+# TODO: Remove when wato recode finished
+def parse_audit_log(name):
+ log_path = log_dir + "/" + name + ".log"
+ if not os.path.exists(log_path):
+ return []
+
+ entries = []
+ for line in file(log_path):
+ line = line.rstrip().decode("utf-8")
+ splitted = line.split(None, 4)
+
+ if len(splitted) == 5 and splitted[0].isdigit():
+ splitted[0] = int(splitted[0])
+ entries.append(splitted)
+
+ entries.reverse()
+
+ return entries
+
+
def log_mkeventd(what, message):
log_entry(None, what, message, "audit.log") # central WATO audit log
# TODO: Change to new changes tracking!