Module: check_mk
Branch: master
Commit: b142028db7aedebc1ec5f398e24f61d281538405
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b142028db7aede…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Feb 6 08:29:38 2015 +0100
Prepared icon painter for new icon plugin api
---
web/htdocs/htmllib.py | 2 +-
web/plugins/icons/builtin.py | 3 +-
web/plugins/views/painters.py | 69 +++++++++++++++++++++++++++++++----------
3 files changed, 54 insertions(+), 20 deletions(-)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 5748609..f92cf9d 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -356,7 +356,7 @@ class html:
def render_icon(self, icon, help="", middle=True):
align = middle and ' align=absmiddle' or ''
title = help and ' title="%s"' % self.attrencode(help) or ""
- if "/" in icon:
+ if "/" in icon or "." in icon:
src = "images/" + icon
else:
src = "images/icon_%s.png" % icon
diff --git a/web/plugins/icons/builtin.py b/web/plugins/icons/builtin.py
index 5f5eeea..0b6c8c8 100644
--- a/web/plugins/icons/builtin.py
+++ b/web/plugins/icons/builtin.py
@@ -110,8 +110,7 @@ def paint_rule_editor(what, row, tags, custom_vars):
else:
title = _("View and edit parameters for this host")
- url = html.makeuri_contextless(urlvars, "wato.py")
- return '<a href="%s">%s</a>' % (url, html.render_icon('rulesets', title))
+ return 'rulesets', html.makeuri_contextless(urlvars, "wato.py"), title
multisite_icons.append({
'service_columns': [ 'description', 'check_command', "host_name" ],
diff --git a/web/plugins/views/painters.py b/web/plugins/views/painters.py
index 3b9cc21..94eb8e8 100644
--- a/web/plugins/views/painters.py
+++ b/web/plugins/views/painters.py
@@ -141,12 +141,60 @@ def paint_icons(what, row):
tags = []
output = ""
+ icon_rename_regex = regex('<img src="([^"]*)"[^>]*>')
for icon in multisite_icons:
if icon.get('type', 'icon') == 'icon':
try:
- icon_output = icon['paint'](what, row, tags, custom_vars)
- if icon_output is not None:
- output += icon_output
+ title = None
+ link = None
+
+ # In old versions, the icons produced html code directly. The new API
+ # is that the icon functions need to return:
+ # a) None - nothing to be rendered
+ # b) single string - the icon name (without .png)
+ # c) tuple - icon, link
+ # d) triple - icon, link, title
+ result = icon['paint'](what, row, tags, custom_vars)a
+
+ if result == None:
+ continue
+
+ elif type(result) in [str,unicode]:
+ if result[0] == '<':
+ # seems like an old format icon (html code). In regular rendering
+ # case (html), it can simply be appended to the output. Otherwise
+ # extract the icon name from icon images
+ if html.output_format == "html":
+ output += result
+ else:
+ # Strip icon names out of HTML code that is generated by htmllib.render_icon()
+ for n in icon_rename_regex.findall(result):
+ if n.startswith("images/"):
+ n = n[7:]
+ if n.startswith("icon_"):
+ n = n[5:]
+ if n.endswith(".png"):
+ n = n[:-4]
+ elif n.endswith(".gif"):
+ n = n[:-4]
+ output += ' '+n.encode('utf-8')
+ continue
+ else:
+ icon_name = result
+ else:
+ if len(result) == 2:
+ icon_name, link = result
+ elif len(result) == 3:
+ icon_name, link, title = result
+
+ if html.output_format == "html":
+ if link:
+ output += '<a href="%s">' % link
+ output += html.render_icon(icon_name, title)
+ if link:
+ output += '</a>'
+ else:
+ output = ' '+icon_name
except Exception, e:
import traceback
output += 'Exception in icon plugin!<br />' + traceback.format_exc()
@@ -154,20 +202,7 @@ def paint_icons(what, row):
if html.output_format == "html":
return "icons", output
else:
- # Strip icon names out of HTML code that is generated by htmllib.render_icon()
- icon_rename_regex = regex('<img src="([^"]*)"[^>]*>')
- icons = []
- for n in icon_rename_regex.findall(output):
- if n.startswith("images/"):
- n = n[7:]
- if n.startswith("icon_"):
- n = n[5:]
- if n.endswith(".png"):
- n = n[:-4]
- elif n.endswith(".gif"):
- n = n[:-4]
- icons.append(n.encode('utf-8'))
- return "icons", " ".join(icons)
+ return "icons", output.strip()
def iconpainter_columns(what):
cols = set(['site',
Module: check_mk
Branch: master
Commit: dc911b2ef640d8744a673cf12abf246b3d9e8b18
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=dc911b2ef640d8…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Feb 5 16:13:12 2015 +0100
#1978 FIX Fixed linking to other views using "joined columns"
Creating views with a joined columns which links to another view
resulted in an exception when displaying the view.
---
.werks/1978 | 11 +++++++++++
ChangeLog | 1 +
web/htdocs/views.py | 14 ++++++++------
3 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/.werks/1978 b/.werks/1978
new file mode 100644
index 0000000..d0844e4
--- /dev/null
+++ b/.werks/1978
@@ -0,0 +1,11 @@
+Title: Fixed linking to other views using "joined columns"
+Level: 1
+Component: multisite
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.7i1
+Date: 1423149130
+
+Creating views with a joined columns which links to another view
+resulted in an exception when displaying the view.
diff --git a/ChangeLog b/ChangeLog
index 26cbd65..2b75bcf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -182,6 +182,7 @@
* 1972 FIX: Prevent erasing of quicksearch field when sidebar is reloaded (e.g. during activate changes)...
* 1221 FIX: veeam_client: Multisite perfometer is now more robust
* 1989 FIX: Fix sorting of services in availability views
+ * 1978 FIX: Fixed linking to other views using "joined columns"...
WATO:
* 1760 Added search form to manual checks page
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index 0d0d2bc..76c7eff 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -2017,11 +2017,9 @@ def paint(p, row, tdattrs=""):
html.write("<td %s>%s</td>" % (tdattrs, content))
return content != ""
-def paint_painter(painter, row, join_key=None):
- if join_key != None:
- row = row.get("JOIN", {}).get(join_key)
- if not row:
- return "", "" # no join information available for that column
+def paint_painter(painter, row):
+ if not row:
+ return "", "" # no join information available for that column
if "args" in painter:
return painter["paint"](row, *painter["args"])
@@ -2036,7 +2034,11 @@ def prepare_paint(p, row):
linkview = p[1]
tooltip = len(p) > 2 and p[2] or None
- tdclass, content = paint_painter(painter, row, join_key=get_join_key(p))
+ join_key = get_join_key(p)
+ if join_key != None:
+ row = row.get("JOIN", {}).get(join_key)
+
+ tdclass, content = paint_painter(painter, row)
if tdclass == "" and content == "":
return tdclass, content
Module: check_mk
Branch: master
Commit: 3b15ced4b1155d67e0051b3f0be23e1b9d617a81
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3b15ced4b1155d…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Feb 5 14:24:15 2015 +0100
Optimized the memory footprint of the Check_MK check helper processes
which are used when using the CMC.
Conflicts:
ChangeLog
modules/check_mk_base.py
---
.werks/1977 | 11 +++++++
ChangeLog | 1 +
modules/check_mk.py | 75 ++++++++++++++++++++++++++--------------------
modules/check_mk_base.py | 2 ++
4 files changed, 57 insertions(+), 32 deletions(-)
diff --git a/.werks/1977 b/.werks/1977
new file mode 100644
index 0000000..aa29d5e
--- /dev/null
+++ b/.werks/1977
@@ -0,0 +1,11 @@
+Title: Dramatically reduced size of Check_MK check helper processes
+Level: 2
+Component: core
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.7i1
+Date: 1423142432
+
+Optimized the memory footprint of the Check_MK check helper processes
+which are used when using the CMC.
diff --git a/ChangeLog b/ChangeLog
index c17c21e..26cbd65 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,7 @@
* 1919 FIX: cmk --snmpwalk: continue if one of the OIDs to walk fails
* 1880 FIX: inventory_processes rules can now be configured without setting levels...
* 1882 FIX: Fixed exception "filesystem_levels" not defined when compiling config for nagios
+ * 1977 FIX: Dramatically reduced size of Check_MK check helper processes...
Checks & Agents:
* 1665 agent_netapp: New special agent for NetApp monitoring via Web-API...
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 9743053..578129a 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -1572,6 +1572,7 @@ def in_binary_hostlist(hostname, conf):
return False
+
# Pick out the last element of an entry if it is a dictionary.
# This is a new feature (1.2.0p3) that allows to add options
# to rules. Currently only the option "disabled" is being
@@ -1595,6 +1596,7 @@ def all_matching_hosts(tags, hostlist):
matching.add(hostname)
return matching
+g_converted_rulesets_cache = {}
def convert_service_ruleset(ruleset):
new_rules = []
@@ -1616,18 +1618,11 @@ def convert_service_ruleset(ruleset):
hosts = all_matching_hosts(tags, hostlist)
new_rules.append((item, hosts, servlist))
- # Replace rules inplace. This finally modifies it, so we
- # need this conversion only once
- ruleset[:] = new_rules
-
-def serviceruleset_is_converted(ruleset):
- if not ruleset:
- return True # empty rulesets are converted in a trivial way
+ g_converted_rulesets_cache[id(ruleset)] = new_rules
- if type(ruleset[0]) != tuple:
- return False
- return type(ruleset[0][1]) == set
+def serviceruleset_is_converted(ruleset):
+ return id(ruleset) in g_converted_rulesets_cache
# Compute outcome of a service rule set that has an item
@@ -1636,11 +1631,12 @@ def service_extra_conf(hostname, service, ruleset):
convert_service_ruleset(ruleset)
entries = []
- for item, hosts, servlist in ruleset:
+ for item, hosts, servlist in g_converted_rulesets_cache[id(ruleset)]:
if hostname in hosts and in_extraconf_servicelist(servlist, service):
entries.append(item)
return entries
+
def convert_boolean_service_ruleset(ruleset):
new_rules = []
for rule in ruleset:
@@ -1667,27 +1663,15 @@ def convert_boolean_service_ruleset(ruleset):
hosts = all_matching_hosts(tags, hostlist)
new_rules.append((negate, hosts, servlist))
- # Replace rules inplace. This finally modifies it, so we
- # need this conversion only once
- ruleset[:] = new_rules
-
-
-def boolean_serviceruleset_is_converted(ruleset):
- if not ruleset:
- return True # empty rulesets are converted in a trivial way
-
- if type(ruleset[0]) != tuple:
- return False
-
- return type(ruleset[0][1]) == set
+ g_converted_rulesets_cache[id(ruleset)] = new_rules
# Compute outcome of a service rule set that just say yes/no
def in_boolean_serviceconf_list(hostname, service_description, ruleset):
- if not boolean_serviceruleset_is_converted(ruleset):
+ if not serviceruleset_is_converted(ruleset):
convert_boolean_service_ruleset(ruleset)
- for negate, hosts, servlist in ruleset:
+ for negate, hosts, servlist in g_converted_rulesets_cache[id(ruleset)]:
if hostname in hosts and \
in_extraconf_servicelist(servlist, service_description):
return not negate
@@ -1743,6 +1727,7 @@ def in_extraconf_hostlist(hostlist, hostname):
return False
+
def in_extraconf_servicelist(list, item):
for pattern in list:
# Allow negation of pattern with prefix '!'
@@ -2962,7 +2947,29 @@ no_inventory_possible = None
# of all autochecks files. The check helpers of the running core just
# use those files, so that changes in the actual config do not harm
# the running system.
-derived_config_variable_names = [ "hosttags", "all_hosts_untagged" ]
+
+derived_config_variable_names = [ "hosttags" ]
+
+# These variables are part of the Check_MK configuration, but are not needed
+# by the Check_MK keepalive mode, so exclude them from the packed config
+skipped_config_variable_names = [
+ "define_contactgroups",
+ "define_hostgroups",
+ "define_servicegroups",
+ "service_contactgroups",
+ "host_contactgroups",
+ "service_groups",
+ "host_groups",
+ "contacts",
+ "host_paths",
+ "timeperiods",
+ "host_attributes",
+ "all_hosts_untagged",
+ "extra_service_conf",
+ "extra_host_conf",
+ "extra_nagios_conf",
+]
+
def pack_config():
# Checks whether or not a variable can be written to the config.mk
# and read again from it.
@@ -2978,11 +2985,15 @@ def pack_config():
filepath = var_dir + "/core/config.mk"
out = file(filepath + ".new", "w")
- out.write("#!/usr/bin/python\n# encoding: utf-8\n# Created by Check_MK. Dump of the currently active configuration\n\n")
+ out.write("#!/usr/bin/python\n"
+ "# encoding: utf-8\n"
+ "# Created by Check_MK. Dump of the currently active configuration\n\n")
for varname in list(config_variable_names) + derived_config_variable_names:
- val = globals()[varname]
- if packable(varname, val):
- out.write("\n%s = %r\n" % (varname, val))
+ if varname not in skipped_config_variable_names:
+ val = globals()[varname]
+ if packable(varname, val):
+ out.write("\n%s = %r\n" % (varname, val))
+
for varname, factory_setting in factory_settings.items():
if varname in globals():
out.write("\n%s = %r\n" % (varname, globals()[varname]))
@@ -4895,7 +4906,7 @@ def copy_globals():
"g_check_table_cache", "g_singlehost_checks",
"g_nodesof_cache", "g_compiled_regexes", "vars_before_config",
"g_initial_times", "g_keepalive_initial_memusage",
- "g_dns_cache", "g_ip_lookup_cache" ] \
+ "g_dns_cache", "g_ip_lookup_cache", "g_converted_rulesets_cache" ] \
and type(value).__name__ not in [ "function", "module", "SRE_Pattern" ]:
global_saved[varname] = copy.copy(value)
return global_saved
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 0ea9407..7d502a0 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -91,6 +91,8 @@ def reset_global_caches():
g_dns_cache = {}
global g_ip_lookup_cache
g_ip_lookup_cache = None # permanently cached ipaddresses from ipaddresses.cache
+ global g_converted_rulesets_cache
+ g_converted_rulesets_cache = {}
reset_global_caches()