Module: check_mk
Branch: master
Commit: 5a9f13b6164009e23aa897bdd9b9145a21481493
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5a9f13b6164009…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Jul 31 11:05:24 2017 +0200
All global setting defaults can be read from effective defaults
Rewrote global setting management to always read the default settings of
all domains from the effective defaults instead of the valuespecs.
We can now set defaults in a single place instead of two places.
Change-Id: I53b5f64b4feec3bfb5f008a813aee918a591026f
---
web/.f12 | 2 +-
web/htdocs/config.py | 24 +++++++++++++++++++++++-
web/htdocs/wato.py | 31 +++++++++----------------------
web/htdocs/watolib.py | 29 +++++++++++++++++++++++++++++
4 files changed, 62 insertions(+), 24 deletions(-)
diff --git a/web/.f12 b/web/.f12
index b10da3e..b5405f5 100644
--- a/web/.f12
+++ b/web/.f12
@@ -1,11 +1,11 @@
#!/bin/bash
SITE=${SITE:-$(cat ../.site 2>/dev/null || true)}
SITE=${SITE:-$(omd sites --bare | head -n 1)}
+echo "Update site $SITE..."
echo "Copy CRE files..."
sudo rsync \
--exclude "*cmc.py" \
- --exclude "*omd_configuration.py" \
-arx htdocs plugins /omd/sites/$SITE/share/check_mk/web/
# Also deploy all other directories of same type
diff --git a/web/htdocs/config.py b/web/htdocs/config.py
index 92ecb65..ad1aa67 100644
--- a/web/htdocs/config.py
+++ b/web/htdocs/config.py
@@ -24,7 +24,11 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-import os, pprint, glob
+import os
+import pprint
+import glob
+import copy
+
import i18n
import log
from lib import *
@@ -54,6 +58,9 @@ config_dir = cmk.paths.var_dir + "/web"
# Detect modification in configuration
modification_timestamps = []
+# Stores the initial configuration values
+default_config = {}
+
# Global table of available permissions. Plugins may add their own
# permissions by calling declare_permission()
permissions_by_name = {}
@@ -116,6 +123,7 @@ def include(filename):
except Exception, e:
raise MKConfigError(_("Cannot read configuration file %s: %s:") %
(filename, e))
+
# Load multisite.mk and all files in multisite.d/. This will happen
# for *each* HTTP request.
# FIXME: Optimize this to cache the config etc. until either the config files or plugins
@@ -126,8 +134,12 @@ def load_config():
global modification_timestamps, sites
modification_timestamps = []
+
# Set default values for all user-changable configuration settings
+ vars_before_plugins = all_nonfunction_vars()
load_plugins(True)
+ vars_after_plugins = all_nonfunction_vars()
+ load_default_config(vars_before_plugins, vars_after_plugins)
# Initialze sites with default site configuration. Need to do it here to
# override possibly deleted sites
@@ -156,6 +168,11 @@ def load_config():
sites = default_single_site_configuration()
+def load_default_config(vars_before_plugins, vars_after_plugins):
+ new_vars = vars_after_plugins.difference(vars_before_plugins)
+ default_config.update(dict([ (k, copy.deepcopy(globals()[k])) for k in new_vars ]))
+
+
def reporting_available():
try:
# Check the existance of one arbitrary config variable from the
@@ -178,6 +195,11 @@ def hide_language(lang):
return lang in hide_languages
+def all_nonfunction_vars():
+ return set([ name for name,value in globals().items()
+ if name[0] != '_' and type(value) != type(lambda:0) ])
+
+
def get_language(default=None):
if default == None:
return default_language
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 233d907..a2b0c91 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -6834,11 +6834,7 @@ class ModeGlobalSettings(WatoMode):
super(ModeGlobalSettings, self).__init__()
self._search = None
- # 1. Check_MK program defaults
- # Get default settings of all configuration variables of interest in the domain
- # "check_mk". (this also reflects the settings done in main.mk)
- self._default_values = check_mk_local_automation("get-configuration",
[], get_check_mk_config_var_names())
-
+ self._default_values = ConfigDomain.get_all_default_globals()
self._global_settings = {}
self._current_settings = {}
@@ -6908,7 +6904,7 @@ class ModeGlobalSettings(WatoMode):
forms.header(group_name, isopen=search)
header_is_painted = True
- default_value = self._default_values.get(varname,
valuespec.default_value())
+ default_value = self._default_values[varname]
edit_url = folder_preserving_link([("mode",
self._edit_mode()),
("varname", varname),
@@ -7001,7 +6997,7 @@ class ModeEditGlobals(ModeGlobalSettings):
action = html.var("_action")
domain, valuespec, need_restart, allow_reset, in_global_settings =
configvars()[varname]
- def_value = self._default_values.get(varname, valuespec.default_value())
+ def_value = self._default_values[varname]
if action == "reset" and not is_a_checkbox(valuespec):
c = wato_confirm(
@@ -7132,21 +7128,16 @@ def mode_edit_configvar(phase, what = 'globalvars'):
else:
return "globalvars"
- check_mk_vars = check_mk_local_automation("get-configuration", [],
[varname])
- if varname in current_settings:
- value = current_settings[varname]
- else:
- if siteid:
- globalsettings = load_configuration_settings()
- check_mk_vars.update(globalsettings)
- value = check_mk_vars.get(varname, valuespec.default_value())
+ default_values = ConfigDomain.get_all_default_globals()
if siteid:
- defvalue = check_mk_vars.get(varname, valuespec.default_value())
+ global_settings = load_configuration_settings()
else:
- defvalue = valuespec.default_value()
+ global_settings = {}
+ defvalue = default_values[varname]
+ value = current_settings.get(varname, global_settings.get(varname, defvalue))
html.begin_form("value_editor", method="POST")
forms.header(valuespec.title())
@@ -9833,7 +9824,7 @@ class ModeEditSiteGlobals(ModeSites, ModeGlobalSettings):
return
domain, valuespec, need_restart, allow_reset, in_global_settings =
configvars()[varname]
- def_value = self._global_settings.get(varname, self._default_values.get(varname,
valuespec.default_value()))
+ def_value = self._global_settings.get(varname, self._default_values[varname])
if action == "reset" and not is_a_checkbox(valuespec):
c = wato_confirm(
@@ -10268,10 +10259,6 @@ def sort_sites(sitelist):
return sitelist
-def get_check_mk_config_var_names():
- return [ varname for (varname, var) in configvars().items() if var[0] ==
ConfigDomainCore ]
-
-
#.
# .--Automation-Webservice-----------------------------------------------.
# | _ _ _ _ |
diff --git a/web/htdocs/watolib.py b/web/htdocs/watolib.py
index d53d229..7799a36 100644
--- a/web/htdocs/watolib.py
+++ b/web/htdocs/watolib.py
@@ -298,6 +298,14 @@ class ConfigDomain(object):
return True
+ @classmethod
+ def get_all_default_globals(cls):
+ settings = {}
+ for domain in ConfigDomain.enabled_domains():
+ settings.update(domain().default_globals())
+ return settings
+
+
def config_dir(self):
raise NotImplementedError()
@@ -352,6 +360,19 @@ class ConfigDomain(object):
self.save(settings, site_specific=True)
+ def default_globals(self):
+ settings = {}
+ for varname, var in configvars().items():
+ domain, valuespec = var[:2]
+ if domain == self.__class__:
+ settings[varname] = valuespec.default_value()
+ return settings
+
+
+ def _get_global_config_var_names(self):
+ return [ varname for (varname, var) in configvars().items() if var[0] ==
self.__class__ ]
+
+
class ConfigDomainCore(ConfigDomain):
needs_sync = True
@@ -366,6 +387,10 @@ class ConfigDomainCore(ConfigDomain):
return check_mk_local_automation(config.wato_activation_method)
+ def default_globals(self):
+ return check_mk_local_automation("get-configuration", [],
self._get_global_config_var_names())
+
+
class ConfigDomainGUI(ConfigDomain):
needs_sync = True
@@ -380,6 +405,10 @@ class ConfigDomainGUI(ConfigDomain):
pass
+ def default_globals(self):
+ return config.default_config
+
+
class ConfigDomainEventConsole(ConfigDomain):
needs_sync = True