Module: check_mk
Branch: master
Commit: aa9cab51223a2a7ddc0dc099a4afc6cd29fbc970
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=aa9cab51223a2a…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Dec 12 16:56:53 2016 +0100
Notification rules: Use standard store functions for persistance
Change-Id: I1f5f49f12f0477f7b395f8bbc6a2e3fd3cdbaf8d
---
web/htdocs/wato.py | 34 ++++++++++++++--------------------
1 file changed, 14 insertions(+), 20 deletions(-)
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index f2dccaa..47ea763 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -6840,30 +6840,24 @@ class CheckTypeGroupSelection(ElementSelection):
def load_notification_rules():
filename = wato_root_dir + "notifications.mk"
- if not os.path.exists(filename):
- return []
+ notification_rules = store.load_from_mk_file(filename,
+ "notification_rules", [])
+
+ # Convert to new plugin configuration format
+ for rule in notification_rules:
+ if "notify_method" in rule:
+ method = rule["notify_method"]
+ plugin = rule["notify_plugin"]
+ del rule["notify_method"]
+ rule["notify_plugin"] = ( plugin, method )
+
+ return notification_rules
- try:
- vars = { "notification_rules" : [] }
- execfile(filename, vars, vars)
- notification_rules = vars["notification_rules"]
- # Convert to new plugin configuration format
- for rule in notification_rules:
- if "notify_method" in rule:
- method = rule["notify_method"]
- plugin = rule["notify_plugin"]
- del rule["notify_method"]
- rule["notify_plugin"] = ( plugin, method )
- return notification_rules
- except Exception, e:
- if config.debug:
- raise MKGeneralException(_("Cannot read configuration file %s: %s")
%
- (filename, e))
- return []
def save_notification_rules(rules):
make_nagios_directory(wato_root_dir)
- file(wato_root_dir + "notifications.mk",
"w").write("notification_rules += %s\n" % pprint.pformat(rules))
+ store.save_to_mk_file(wato_root_dir + "notifications.mk",
+ "notification_rules", rules)
def FolderChoice(**kwargs):