This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository mum. See http://git.chorem.org/mum.git commit 1a2e74b611d6c31a622915bf81a763e8cf1e0483 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Fri Mar 20 16:15:07 2015 +0100 notifications page : correction du code pour l'affichage des données de notification --- app/modules/storage_modules/shelve_db.py | 102 ++++++++++++++++++++++------- static/js/controllers/notificationsCtrl.js | 37 +++++++---- views/notifications.html | 3 +- 3 files changed, 106 insertions(+), 36 deletions(-) diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index 78e0c9a..15b9482 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -80,6 +80,8 @@ class shelve_db: self.db["hosts"][addr_host]["status"] = {} # Create structure for archiving data self.db["hosts"][addr_host]["archive"] = {} + except Exception as e: + print e.__str__() finally: self.close_db() @@ -226,6 +228,8 @@ class shelve_db: res = None try: res = self.db['hosts'][args['addr_host']]['conf']['connections'] + except Exception as e: + print e.__str__() finally: self.close_db() return json.dumps(res) @@ -255,6 +259,8 @@ class shelve_db: dict['time'] = datetime.now() dict['freq'] = self.db['hosts'][addr_host]['conf']['monitoring'][mod]['check_frequency'] res.append(dict) + except Exception as e: + print e.__str__() finally: self.close_db() return res @@ -269,6 +275,8 @@ class shelve_db: try: for addr_host in self.db['hosts']: res.append(addr_host) + except Exception as e: + print e.__str__() finally: self.close_db() return res @@ -410,6 +418,8 @@ class shelve_db: for host in self.db['groups'][group_id]['hosts']: if self.db['groups'][group_id]['hosts'][host]['addr'] == addr_host: del self.db['groups'][group_id]['hosts'][host] + except Exception as e: + print e.__str__() finally: self.close_db() @@ -423,6 +433,8 @@ class shelve_db: self.open_db() try: self.db["hosts"][addr_host]["detected"][name_part] = json_res_str + except Exception as e: + print e.__str__() finally: self.close_db() @@ -440,6 +452,8 @@ class shelve_db: self.open_db() try: self.db["hosts"][addr_host]["conf"]["custom_info"] = txt + except Exception as e: + print e.__str__() finally: self.close_db() @@ -462,6 +476,8 @@ class shelve_db: self.open_db() try: self.db["hosts"][addr_host]["conf"]["interventions"].append(intervention) + except Exception as e: + print e.__str__() finally: self.close_db() @@ -512,6 +528,8 @@ class shelve_db: # if not, we have to remove it from the monitoring list self.db["hosts"][addr_host]["conf"]["monitoring"][mod_name]["activated"] = False self.rem_to_monitoring_list(args['addr_host'], mod_name) + except Exception as e: + print e.__str__() finally: self.close_db() @@ -562,6 +580,8 @@ class shelve_db: self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['minor_limit'] = args['minor_limit'] self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['major_limit'] = args['major_limit'] self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['check_frequency'] = args['freq'] + except Exception as e: + print e.__str__() finally: self.close_db() @@ -580,6 +600,8 @@ class shelve_db: try: for mod in args['priorities']: self.db['hosts'][addr_host]['conf']['connections'][mod]['priority'] = args['priorities'][mod] + except Exception as e: + print e.__str__() finally: self.close_db() @@ -598,6 +620,8 @@ class shelve_db: for param in args['current_config'][modname]: self.db['hosts'][addr_host]['conf']['connections'][modname][param] = \ args['current_config']['ssh'][param] + except Exception as e: + print e.__str__() finally: self.close_db() @@ -618,6 +642,8 @@ class shelve_db: dict_conn['priority'] = self.db['hosts'][addr_host]['conf']['connections'][conn]['priority'] dict_conn['args'] = self.db['hosts'][addr_host]['conf']['connections'][conn] res.append(dict_conn) + except Exception as e: + print e.__str__() finally: self.close_db() return res @@ -693,6 +719,8 @@ class shelve_db: self.db['hosts'][addr_host]['archive'][mod_name] = \ self.update_stats(self.db['hosts'][addr_host]['archive'][mod_name], val) """ + except Exception as e: + print e.__str__() finally: self.close_db() #return failure @@ -740,6 +768,8 @@ class shelve_db: if group not in self.db['hosts'][host]['conf']['groups']: self.db['groups'][group]['hosts'].append(host) self.db['hosts'][host]['conf']['groups'].append(group) + except Exception as e: + print e.__str__() finally: self.close_db() @@ -762,6 +792,8 @@ class shelve_db: # deletion of the group if empty if len(self.db['groups'][group]['hosts']) == 0: del self.db['groups'][group] + except Exception as e: + print e.__str__() finally: self.close_db() @@ -777,6 +809,8 @@ class shelve_db: try: for user in users: self.db['groups'][group]['subscribers'][user] = {} + except Exception as e: + print e.__str__() finally: self.close_db() @@ -785,24 +819,27 @@ class shelve_db: Updates the subscription to a following user from a host. :param args: { 'group': string, - 'username': string, 'subscription': - {'minor': [ + username:{ + {'minor': { notif_mod: priority }, ... - ], - 'major': [ + },{ + 'major': { notif_mod: priority }, ... - ]} + } + } } :return: """ group = args['group'] - username = args['username'] self.open_db() try: - self.db['groups'][group]['subscribers'][username] = args['subscription'] + for username in args['subscription']: + self.db['groups'][group]['subscribers'][username] = args['subscription'][username] + except Exception as e: + print e.__str__() finally: self.close_db() @@ -817,6 +854,8 @@ class shelve_db: self.open_db() try: del self.db['groups'][group]['subscribers'][username] + except Exception as e: + print e.__str__() finally: self.close_db() @@ -827,20 +866,22 @@ class shelve_db: { 'group': string } :return: a dictionary containing : { username: - {'minor': [ + {'minor': { notif_mod: priority }, ... - ], - 'major': [ + },{ + 'major': { notif_mod: priority }, ... - ]}} + }}} """ group = args['group'] res = [] self.open_db() try: res = self.db['groups'][group]['subscribers'] + except Exception as e: + print e.__str__() finally: self.close_db() return json.dumps(res) @@ -859,6 +900,8 @@ class shelve_db: self.db['users'][username]['preferences']['minor_notifications'] = {} self.db['users'][username]['preferences']['major_notifications'] = {} self.db['users'][username]['account'] = {} + except Exception as e: + print e.__str__() finally: self.close_db() @@ -873,6 +916,8 @@ class shelve_db: try: for user in self.db['users']: res.append(user) + except Exception as e: + print e.__str__() finally: self.close_db() return json.dumps(res) @@ -897,6 +942,8 @@ class shelve_db: for group in self.db['groups']: if username in self.db['groups'][group]['subscribers']: del self.db['groups'][group]['subscribers'][username] + except Exception as e: + print e.__str__() finally: self.close_db() @@ -912,6 +959,8 @@ class shelve_db: try: for user in users: self.db['hosts'][addr_host]['conf']['subscribers'][user] = {} + except Exception as e: + print e.__str__() finally: self.close_db() @@ -919,25 +968,28 @@ class shelve_db: """ Updates the subscription to a following user from a host. :param args: - { 'addr_host': string, - 'username': string, + { 'group': string, 'subscription': - {'minor': [ + username:{ + {'minor': { notif_mod: priority }, ... - ], - 'major': [ + },{ + 'major': { notif_mod: priority }, ... - ]} + } + } } :return: """ addr_host = args['addr_host'] - username = args['username'] self.open_db() try: - self.db['hosts'][addr_host]['conf']['subscribers'][username] = args['subscription'] + for username in args['subscription']: + self.db['hosts'][addr_host]['conf']['subscribers'][username] = args['subscription'][username] + except Exception as e: + print e.__str__() finally: self.close_db() @@ -952,6 +1004,8 @@ class shelve_db: self.open_db() try: del self.db['hosts'][addr_host]['conf']['subscribers'][username] + except Exception as e: + print e.__str__() finally: self.close_db() @@ -962,20 +1016,22 @@ class shelve_db: { 'addr_host': string } :return: a dictionary containing : { username: - {'minor': [ + {'minor': { notif_mod: priority }, ... - ], - 'major': [ + , + 'major': { notif_mod: priority }, ... - ]}} + }}} """ addr_host = args['addr_host'] res = {} self.open_db() try: res = self.db['hosts'][addr_host]['conf']['subscribers'] + except Exception as e: + print e.__str__() finally: self.close_db() return json.dumps(res) \ No newline at end of file diff --git a/static/js/controllers/notificationsCtrl.js b/static/js/controllers/notificationsCtrl.js index 1e19332..36a9a62 100644 --- a/static/js/controllers/notificationsCtrl.js +++ b/static/js/controllers/notificationsCtrl.js @@ -42,10 +42,10 @@ mumApp.controller('notificationsCtrl', function($scope, $rootScope, $modal, Data return res; }; - $scope.selected_grp = ""; - $scope.selected_host = ""; + $scope.selected_grp = ""; // string + $scope.selected_host = ""; // {"status":"success","group":["all","g1"],"addr":"127.0.0.1","danger":[],"last_check":"2015-03-20 15:32:19.897431","warning":[],"name":"localhost"} - $scope.option_selected = ""; + $scope.option_selected = ""; // 'grp' OR 'host' $scope.get_group_subscribers = function(){ if($scope.selected_grp != ""){ @@ -62,26 +62,30 @@ mumApp.controller('notificationsCtrl', function($scope, $rootScope, $modal, Data } $scope.$on("resCall", function (event, args) { /* args= { username: - {'minor': [ + {'minor': { { notif_mod: priority }, ... - ], - 'major': [ + }, + 'major': { { notif_mod: priority }, ... - ]}} */ + }}} */ $scope.$apply(function(){ var sd = {}; for(user in args){ sd[user] = {}; sd[user]['minor'] = {}; sd[user]['major'] = {}; - for(var i=0 ; i<args[user].length ; i++){ - sd[user]['minor'][args[user]['minor'][i]['notif_mod']] = {'activated': true, 'priority':args[user]['minor'][i]['priority']}; - sd[user]['major'][args[user]['major'][i]['notif_mod']] = {'activated': true, 'priority':args[user]['major'][i]['priority']}; + for(notif_mod in args[user]['minor']){ + sd[user]['minor'][notif_mod] = + {'activated': args[user]['minor'][notif_mod]['activated'], + 'priority':args[user]['minor'][notif_mod]['priority']}; + sd[user]['major'][notif_mod] = + {'activated': args[user]['major'][notif_mod]['activated'], + 'priority':args[user]['major'][notif_mod]['priority']}; } for(notif_mod in $scope.notif_mods){ - if(!sd[user].hasOwnProperty(notif_mod)){ + if(!sd[user]['minor'].hasOwnProperty(notif_mod)){ sd[user]['minor'][notif_mod] = {'activated': false, 'priority': null}; sd[user]['major'][notif_mod] = {'activated': false, 'priority': null}; } @@ -97,7 +101,16 @@ mumApp.controller('notificationsCtrl', function($scope, $rootScope, $modal, Data } $scope.save = function(){ - + var args = {}; + args['subscription'] = $scope.subscriber_data; + if($scope.option_selected == 'grp'){ + args['group'] = $scope.selected_grp; + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'update_subscription_to_group', 'args': args}})); + } + else{ + args['addr_host'] = $scope.selected_host.addr; + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'update_subscription_to_host', 'args': args}})); + } } $scope.open_modal_add_subscriber = function (mod_name) { diff --git a/views/notifications.html b/views/notifications.html index 0f73cce..01efedf 100644 --- a/views/notifications.html +++ b/views/notifications.html @@ -2,8 +2,9 @@ <div class="col-md-offset-2 main"> <h1 class="page-header">Who to notify?</h1> <!--<h2 class="sub-header">They will be applied on each new host you will add.</h2>--> + {{selected_host}}<br/> {{subscriber_data}}<br/> - {{notif_mods}} + {{notif_mods}}<br/> <form> <div class="row"> <div class="col-lg-6"> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.