Module: check_mk
Branch: master
Commit: 253c075d8917e03901b1a821ee4b2141fc993e4b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=253c075d8917e0…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Wed Jul 24 16:16:24 2013 +0200
* Add: Require unique alias names in between the following elements:
Host/Service/Contact Groups, Timeperiods and Roles
---
ChangeLog | 2 ++
web/htdocs/wato.py | 39 ++++++++++++++++++++++++++++++++++++---
2 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index d19de41..b92bf12 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -106,6 +106,8 @@
* Custom user attributes can now be managed using WATO
* FIX: do validation of check items in rule editor
* FIX: More consistent handling of folderpath select in rule editor
+ * Add: Require unique alias names in between the following elements:
+ Host/Service/Contact Groups, Timeperiods and Roles
Notifications:
* Flexible Notification can now filter service levels
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 9b610f4..c5cf0e6 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -5860,9 +5860,11 @@ def mode_edit_group(phase, what):
alias = html.var_utf8("alias").strip()
if not alias:
raise MKUserError("alias", _("Please specify an alias
name."))
- for key, value in groups.items():
- if alias == value and name != key:
- raise MKUserError("alias", _("This alias is already
used in the group %s .") % key)
+
+ unique, info = is_alias_used(what, name, alias)
+ if not unique:
+ raise MKUserError("alias", info)
+
if new:
name = html.var("name").strip()
if len(name) == 0:
@@ -6204,6 +6206,10 @@ def mode_edit_timeperiod(phase):
if not alias:
raise MKUserError("alias", _("Please specify an alias name
for your timeperiod."))
+ unique, info = is_alias_used("timeperiods", name, alias)
+ if not unique:
+ raise MKUserError("alias", info)
+
timeperiod.clear()
# extract time ranges of weekdays
@@ -8642,6 +8648,11 @@ def mode_edit_role(phase):
if phase == "action":
alias = html.var_utf8("alias")
+
+ unique, info = is_alias_used("roles", id, alias)
+ if not unique:
+ raise MKUserError("alias", info)
+
new_id = html.var("id")
if len(new_id) == 0:
raise MKUserError("id", _("Please specify an ID for the new
role."))
@@ -13556,6 +13567,28 @@ def may_see_hosts():
return config.may("wato.use") and \
(config.may("wato.seeall") or config.may("wato.hosts"))
+def is_alias_used(my_group, my_name, aliasname):
+ # Host / Service / Contact groups
+ all_groups = userdb.load_group_information()
+ for groupname, group in all_groups.items():
+ for key, value in group.items():
+ if value == aliasname and (my_group != groupname or my_name != key):
+ return False, _("This alias is already used in the %s group %s
.") % (groupname, key)
+
+ # Timeperiods
+ timeperiods = load_timeperiods()
+ for key, value in timeperiods.items():
+ if value.get("alias") == aliasname and (my_group !=
"timeperiod" or my_name != key):
+ return False, _("This alias is already used in timeperiod %s.") %
key
+
+ # Roles
+ roles = userdb.load_roles()
+ for key, value in roles.items():
+ if value.get("alias") == aliasname and (my_group != "roles"
or my_name != key):
+ return False, _("This alias is already used in the role %s.") %
key
+
+ return True, None
+
#.
# .-Plugins--------------------------------------------------------------.
# | ____ _ _ |