Module: check_mk
Branch: master
Commit: aaaa35414b3e83c40f2f501acf9e6438100da929
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=aaaa35414b3e83…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sat Feb 25 20:13:50 2012 +0100
New valuespec MultiSelect
---
web/htdocs/htmllib.py | 11 +++++++++++
web/htdocs/index.py | 10 +++++++++-
web/htdocs/valuespec.py | 27 +++++++++++++++++++++++++++
3 files changed, 47 insertions(+), 1 deletions(-)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index e1789c0..c3e8c33 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -865,6 +865,17 @@ class html:
else:
return val.decode("utf-8")
+ # Return all values of a variable that possible occurs more
+ # than once in the URL. note: req.listvars does contain those
+ # variable only, if the really occur more than once.
+ def list_var(self, varname):
+ if varname in self.req.listvars:
+ return self.req.listvars[varname]
+ elif varname in self.req.vars:
+ return [self.req.vars[varname]]
+ else:
+ return []
+
def set_var(self, varname, value):
if value == None:
self.del_var(varname)
diff --git a/web/htdocs/index.py b/web/htdocs/index.py
index 8aadb0b..7079202 100644
--- a/web/htdocs/index.py
+++ b/web/htdocs/index.py
@@ -58,11 +58,19 @@ if defaults.omd_root:
def read_get_vars(req):
req.vars = {}
+ req.listvars = {} # for variables with more than one occurrance
fields = util.FieldStorage(req, keep_blank_values = 1)
for field in fields.list:
varname = field.name
value = field.value
- req.vars[varname] = value
+ # Multiple occurrance of a variable? Store in extra list dict
+ if varname in req.vars:
+ if varname in req.listvars:
+ req.listvars[varname].append(value)
+ else:
+ req.listvars[varname] = [ req.vars[varname], value ]
+ else:
+ req.vars[varname] = value
def read_cookies(req):
req.cookies = Cookie.get_cookies(req)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 23608c5..b6c54cb 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -885,6 +885,33 @@ class ListChoice(ValueSpec):
raise MKUserError(varprefix, _("%s is not an allowed value") % v)
+# A alternative way of editing list choices
+class MultiSelect(ListChoice):
+ def __init__(self, **kwargs):
+ ListChoice.__init__(self, **kwargs)
+
+ def render_input(self, varprefix, value):
+ self.load_elements()
+ html.write("<select multiple name='%s'>" % varprefix)
+ for nr, (key, title) in enumerate(self._elements):
+ if key in value:
+ sel = " selected"
+ else:
+ sel = ""
+ html.write('<option value="%s"%s>%s</option>\n' % (key, sel, title))
+ html.write("</select>")
+
+ def from_html_vars(self, varprefix):
+ self.load_elements()
+ value = []
+ hv = html.list_var(varprefix)
+ for key, title in self._elements:
+ if key in hv:
+ value.append(key)
+ return value
+
+
+
# A type-save dropdown choice with one extra field that
# opens a further value spec for entering an alternative
Module: check_mk
Branch: master
Commit: 4530277e128cd6de75a7619fb1bdaf6f9b94dcce
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4530277e128cd6…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sat Feb 25 12:18:26 2012 +0100
Only create contacts in Nagios that are group members
---
ChangeLog | 2 ++
modules/check_mk.py | 4 +++-
web/htdocs/wato.py | 12 ++++++++----
3 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index dd84683..a4790ed 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -31,6 +31,8 @@
* FIX: honor permissions for "bulk cleanup" and "bulk edit"
* FIX: honor write permissions and source folder when moving hosts
* FIX: honor permissions on hosts also on bulk inventory
+ * Only create contacts in Nagios if they are member of at
+ least one contact group.
Checks & Agents:
* hpux_if: fix missing default parameter errors
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 0d3b12c..b022c49 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -1891,7 +1891,9 @@ def create_nagios_config_contacts(outfile):
outfile.write(" %s_notification_period\t%s\n" % (what, contact.get("notification_period", "24X7")))
outfile.write(" %s_notification_commands\tcheck-mk-notify\n" % what)
- # Refer only to those contact groups that actually have objects assigned to
+ # Refer only to those contact groups that actually have objects assigned to. Otherwise
+ # we will run into problems since Nagios does not allow contact groups that
+ # are not assigned to at least one host or service?
cgrs = [ cgr for cgr in contact.get("contactgroups", []) if cgr in contactgroups_to_define ]
# Use dummy group if none is set. Nagios will not start otherwise
if not cgrs:
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 1795a19..468e62b 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -7106,10 +7106,14 @@ def save_users(profiles):
non_contact_keys = [ "roles", "password", "locked", "automation_secret", "language" ]
multisite_keys = [ "roles", "language" ]
- # Remove multisite keys in contacts
- contacts = dict([ (id, split_dict(user, non_contact_keys, False))
- for (id, user)
- in profiles.items() ])
+ # Remove multisite keys in contacts. And use only such entries
+ # that have any contact groups assigned to.
+ contacts = dict(
+ e for e in
+ [ (id, split_dict(user, non_contact_keys, False))
+ for (id, user)
+ in profiles.items() ]
+ if e[1].get("contactgroups"))
# Only allow explicit defined attributes to be written to multisite config
users = {}
Module: check_mk
Branch: master
Commit: a9c50c8576c93ba2cd39692f5e27609c35961ec0
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a9c50c8576c93b…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Feb 24 14:14:28 2012 +0100
Fixed shortly introduced problem during reading saved roles
---
web/htdocs/wato.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 1795a19..5f81ce4 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -7474,7 +7474,7 @@ def load_roles():
try:
vars = { "roles" : roles }
- exec(filename, vars, vars)
+ execfile(filename, vars, vars)
# Reflect the data in the roles dict kept in the config module Needed
# for instant changes in current page while saving modified roles.
# Otherwise the hooks would work with old data when using helper