Module: check_mk
Branch: master
Commit: 03dfe52ab98076557622fefaacc78bdc62aab939
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=03dfe52ab98076…
Author: Bastian Kuhn <bk(a)mathias-kettner.de>
Date: Thu Jan 9 15:54:52 2014 +0100
User Custom Attributes can now be exported to the core
The Wato User Management has a feature to create Custom Attributes for users.
This Attributes can now be used as custom macros for the monitoring core. The
"Edit User Attribute" Dialog now has the option: "Add as Custom
Macro".
---
.werks/114 | 10 ++++++++++
ChangeLog | 1 +
modules/check_mk.py | 3 +++
web/htdocs/userdb.py | 19 ++++++++++++++-----
web/htdocs/wato.py | 17 ++++++++++++-----
5 files changed, 40 insertions(+), 10 deletions(-)
diff --git a/.werks/114 b/.werks/114
new file mode 100644
index 0000000..1b3ae28
--- /dev/null
+++ b/.werks/114
@@ -0,0 +1,10 @@
+Title: User Custom Attributes can now be exported to the core
+Level: 1
+Component: wato
+Version: 1.2.5i1
+Date: 1389279133
+Class: feature
+
+The Wato User Management has a feature to create Custom Attributes for users.
+This Attributes can now be used as custom macros for the monitoring core. The
+"Edit User Attribute" Dialog now has the option: "Add as Custom
Macro".
diff --git a/ChangeLog b/ChangeLog
index e0ae4a9..2ef3822 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -118,6 +118,7 @@
* 0112 Explicit mapping of clustered services can now be done with WATO...
* 0437 Convert WATO rule for debug_log into simple Checkbox...
* 0428 Changed user profiles (e.g. pw changes) are now replicated in distributed
setups...
+ * 0114 User Custom Attributes can now be exported to the core...
* 0057 FIX: Fix exception in WATO host editor on custom tag without topic...
* 0241 FIX: Improved sorting of WATO folders in dropdown menu...
* 0019 FIX: Fixed wording in WATO rule for MSSQL check
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 0e1ca16..f740f61 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -2516,6 +2516,9 @@ def create_nagios_config_contacts(outfile):
outfile.write(" %s_notification_options\t%s\n" % (what,
",".join(list(no))))
outfile.write(" %s_notification_period\t%s\n" % (what,
contact.get("notification_period", "24X7")))
outfile.write(" %s_notification_commands\t%s\n" % (what,
contact.get("%s_notification_commands" % what, "check-mk-notify")))
+ # Add custom macros
+ for macro in [ m for m in contact.keys() if m.startswith('_') ]:
+ outfile.write(" %s\t%s\n" % ( macro, contact[macro] ))
outfile.write(" contactgroups\t\t\t%s\n" % ",
".join(cgrs))
outfile.write("}\n\n")
diff --git a/web/htdocs/userdb.py b/web/htdocs/userdb.py
index e584e43..9cba39d 100644
--- a/web/htdocs/userdb.py
+++ b/web/htdocs/userdb.py
@@ -166,12 +166,13 @@ multisite_dir = defaults.default_config_dir +
"/multisite.d/wato/"
# | |
# +----------------------------------------------------------------------+
-def declare_user_attribute(name, vs, user_editable = True, permission = None,
show_in_table = False, topic = None):
+def declare_user_attribute(name, vs, user_editable = True, permission = None,
show_in_table = False, topic = None, add_custom_macro = False):
user_attributes[name] = {
- 'valuespec': vs,
- 'user_editable': user_editable,
- 'show_in_table': show_in_table,
- 'topic': topic and topic or 'personal',
+ 'valuespec' : vs,
+ 'user_editable' : user_editable,
+ 'show_in_table' : show_in_table,
+ 'topic' : topic and topic or 'personal',
+ 'add_custom_macro' : add_custom_macro,
}
# Permission needed for editing this attribute
if permission:
@@ -354,6 +355,13 @@ def split_dict(d, keylist, positive):
def save_users(profiles):
custom_values = user_attributes.keys()
+
+ # Add custom macros
+ core_custom_macros = [ k for k,o in user_attributes.items() if
o.get('add_custom_macro') ]
+ for user in profiles.keys():
+ for macro in core_custom_macros:
+ if profiles[user].get(macro):
+ profiles[user]['_'+macro] = profiles[user][macro]
# Keys not to put into contact definitions for Check_MK
non_contact_keys = [
@@ -614,6 +622,7 @@ def declare_custom_user_attrs():
user_editable = attr['user_editable'],
show_in_table = attr.get('show_in_table', False),
topic = attr.get('topic', 'personal'),
+ add_custom_macro = attr.get('add_custom_macro', False )
)
#.
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 33fa821..b4bf921 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -14135,6 +14135,7 @@ def mode_edit_custom_attr(phase, what):
help = html.var_utf8('help').strip()
user_editable = html.get_checkbox('user_editable')
show_in_table = html.get_checkbox('show_in_table')
+ add_custom_macro = html.get_checkbox('add_custom_macro')
if new:
name = html.var("name", '').strip()
@@ -14161,11 +14162,12 @@ def mode_edit_custom_attr(phase, what):
else:
log_pending(SYNCRESTART, None, "edit-%sattr" % what,
_("Changed title of %s attribute %s") % (what, name))
attr.update({
- 'title' : title,
- 'topic' : topic,
- 'help' : help,
- 'user_editable' : user_editable,
- 'show_in_table' : show_in_table,
+ 'title' : title,
+ 'topic' : topic,
+ 'help' : help,
+ 'user_editable' : user_editable,
+ 'show_in_table' : show_in_table,
+ 'add_custom_macro' : add_custom_macro,
})
save_custom_attrs(all_attrs)
@@ -14217,6 +14219,11 @@ def mode_edit_custom_attr(phase, what):
'you can also make it visible in the overview tables.'))
html.checkbox('show_in_table', attr.get('show_in_table', False))
+ forms.section(_('Add as Custom Macro'))
+ html.help(_('The attribute can be added to the contact definiton in order '
+ 'to use it for notifications.'))
+ html.checkbox('add_custom_macro', attr.get('add_custom_macro',
False))
+
forms.end()
html.button("save", _("Save"))
html.hidden_fields()