branch develop updated (dea769f -> 1a2e74b)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository mum. See http://git.chorem.org/mum.git from dea769f chargement dynamique des modules de notification new 6099878 notifications page : affichage du tableau correspondant aux données de notification concerannt 1 utilisateur sur 1 groupe/hote et modification possible de ces données via formulaire new 1a2e74b notifications page : correction du code pour l'affichage des données de notification The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: 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 commit 6099878d2c0586712e5329779aaf74816cef5000 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Fri Mar 20 15:20:31 2015 +0100 notifications page : affichage du tableau correspondant aux données de notification concerannt 1 utilisateur sur 1 groupe/hote et modification possible de ces données via formulaire Summary of changes: app/modules/storage_modules/shelve_db.py | 252 +++++++++++++++++++---------- static/js/controllers/notificationsCtrl.js | 63 +++++++- views/notifications.html | 121 ++------------ 3 files changed, 236 insertions(+), 200 deletions(-) -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 6099878d2c0586712e5329779aaf74816cef5000 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Fri Mar 20 15:20:31 2015 +0100 notifications page : affichage du tableau correspondant aux données de notification concerannt 1 utilisateur sur 1 groupe/hote et modification possible de ces données via formulaire --- app/modules/storage_modules/shelve_db.py | 188 ++++++++++++++++------------- static/js/controllers/notificationsCtrl.js | 44 ++++++- views/notifications.html | 118 ++---------------- 3 files changed, 158 insertions(+), 192 deletions(-) diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index 69c6c65..78e0c9a 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -117,11 +117,11 @@ class shelve_db: { mod_name: { - 'class_name': val, => the name of the class to instanciate - 'compatible_os': [val1, val2, ...], => a list containing the compatibles os - 'unit': val, => the unit type of return ('%', 'bool' or other) - 'block': val, => the monitoring block of the module - 'external': bool => indicates if this modules comes from external directory + 'class_name': string, => the name of the class to instanciate + 'compatible_os': [string1, string2, ...], => a list containing the compatibles os + 'unit': string, => the unit type of return ('%', 'bool' or other) + 'block': string, => the monitoring block of the module + 'external': bool => indicates if this modules comes from external directory } } :return a list containing the default parameters for each monitoring module (at least ping) @@ -180,11 +180,11 @@ class shelve_db: { mod_name: { - 'class_name': val, => the name of the class to instanciate - 'compatible_os': [val1, val2, ...], => a list containing the compatibles os - 'unit': val, => the unit type of return ('%', 'bool' or other) - 'block': val, => the monitoring block of the module - 'external': bool => indicates if this modules comes from external directory + 'class_name': string, => the name of the class to instanciate + 'compatible_os': [string1, string2, ...], => a list containing the compatibles os + 'unit': string, => the unit type of return ('%', 'bool' or other) + 'block': string, => the monitoring block of the module + 'external': bool => indicates if this modules comes from external directory } } :return a list containing the default parameters for each monitoring module (at least ping) @@ -216,10 +216,10 @@ class shelve_db: """ Returns the connection parameters of an host. :param args: A dictionnary containing : - {'addr_host': val} + {'addr_host': string} :return: The connection parameters in the form: mod_name: { - {param1: val1, param2: val2, ...} + {param1: string1, param2: string2, ...} } """ self.open_db() @@ -236,11 +236,11 @@ class shelve_db: :param addr_host: the address IP of the host :return: structured informations about monitoring in form : [{ - 'addr' : val, => the IP address of the host - 'os', val, => the operating system of the host - 'mod_name', val, => the name of the monitoring module - 'time', val, => the time at when to launch the monitoring module - 'freq', val => the frequency check (in seconds) + 'addr' : string, => the IP address of the host + 'os', string, => the operating system of the host + 'mod_name', string, => the name of the monitoring module + 'time', datetime, => the time at when to launch the monitoring module + 'freq', int => the frequency check (in seconds) }, ...] """ self.open_db() @@ -283,12 +283,12 @@ class shelve_db: { "addr":"192.168.74.1", "name":"www.example.com", - "status":val, //"success" or "warning" or "danger" or "" + "status":string, //"success" or "warning" or "danger" or "" "group":[ "all", ...], - "last_check":val //UNIX time + "last_check":datetime "subscribers":{ - "uid":val, - "priority":val + "uid":string, + "priority":int } "warning": [mod_name, ...] "danger": [mod_name, ...] @@ -345,24 +345,24 @@ class shelve_db: { modname: { - key:val, + key:string, ... } } - "hostname":val, + "hostname":string, "monitoring": { modname: { - "date":val, - "state":val, - "value":val + "date":datetime, + "state":string, + "value":string } }, 'activated_monitoring':{ mod_name: bool }, - "custom_infos":val + "custom_infos":string } """ self.open_db() @@ -395,7 +395,7 @@ class shelve_db: Removes a host from the database. All the monitoring intructions concerning this host will be deleted. Finally, if the host is part of a group, it will be also removed from these groups. :param args: A dictionary containing: - {'addr_host': val} + {'addr_host': string} """ addr_host = args['addr_host'] self.open_db() @@ -431,8 +431,8 @@ class shelve_db: Updates the custom informations stored on the host's configuration :param args: a structure containing the values : { - 'addr_host': val, - 'txt': val + 'addr_host': string, + 'txt': string } """ addr_host = args['addr_host'] @@ -448,10 +448,10 @@ class shelve_db: Add a new intervention, stored on the host's configuration :param args: a structure containing the values : { - 'addr_host': val, => the IP adress of the host - 'user' : val, => the username responsible of the intervention - 'date' : val, => the intervention's date - 'details' : val => a string explaining the intervetion + 'addr_host': string, => the IP adress of the host + 'user' : string, => the username responsible of the intervention + 'date' : string, => the intervention's date + 'details' : string => a string explaining the intervetion } """ addr_host = args['addr_host'] @@ -470,7 +470,7 @@ class shelve_db: Activates or desactivates monitoring modules for a given host :param args: a dictionary containing : { - 'addr_host': val, + 'addr_host': string, 'activated':{ mod_name: bool } @@ -479,10 +479,10 @@ class shelve_db: { mod_name: { - 'class_name': val, => the name of the class to instanciate - 'compatible_os': [val1, val2, ...], => a list containing the compatibles os - 'unit': val, => the unit type of return ('%', 'bool' or other) - 'block': val, => the monitoring block of the module + 'class_name': string, => the name of the class to instanciate + 'compatible_os': [string1, string2, ...], => a list containing the compatibles os + 'unit': string, => the unit type of return ('%', 'bool' or other) + 'block': string, => the monitoring block of the module 'external': bool => indicates if this modules comes from external directory } } @@ -519,13 +519,13 @@ class shelve_db: """ Returns a structure containing informations about the settings of a monitoring module for a given host. :param args: a list containing the arguments : - {'addr_host': val, 'mod_name':val] + {'addr_host': string, 'mod_name':string] :return: a structure containing : { - 'unit' : val, // the unit of the value - 'minor_limit' : val, - 'major_limit' : val, - 'freq' : val + 'unit' : string, // the unit of the value + 'minor_limit' : int, + 'major_limit' : int, + 'freq' : int // in seconds } """ addr_host = args['addr_host'] @@ -548,11 +548,11 @@ class shelve_db: Save a new configuration for a monitoring module and for a specific host. :param args: a structure containing the values : { - 'addr_host': val, - 'mod_name': val, - 'freq' : val, - 'minor_limit' : val, - 'major_limit' : val + 'addr_host': string, + 'mod_name': string, + 'freq' : int, + 'minor_limit' : int, + 'major_limit' : int } """ addr_host = args['addr_host'] @@ -569,9 +569,9 @@ class shelve_db: """ Save the priorities of connections modules for a host. :param args: A dictionary containing: - {'addr_host' : val, + {'addr_host' : string, 'priorities':{ - mod_name: val + mod_name: string } } """ @@ -587,8 +587,8 @@ class shelve_db: """ Save the connection configuration of a host. :param args: A dictionary containting: - {'addr_host': val, - 'modname': val, + {'addr_host': string, + 'modname': string, 'current_config': val} """ addr_host = args['addr_host'] @@ -606,7 +606,7 @@ class shelve_db: Get the configured connections by priority of a host. :param addr_host: The IP address of the host. :return: A list containing: - [{'conn_mod_name': val, 'priority': val, 'args': {arg1: val, ...}}] + [{'conn_mod_name': string, 'priority': int, 'args': {arg1: val, ...}}] """ res = [] self.open_db() @@ -723,8 +723,8 @@ class shelve_db: Add given hosts to a group. If the group doesn't exists on the database, it will be created. :param args: a dictionary containing : { - 'host_list': val, # a list of IP adresses - 'group'; val # the group name + 'host_list': list<string>, # a list of IP adresses + 'group'; string # the group name } """ group = args['group'] @@ -748,8 +748,8 @@ class shelve_db: Remove given hosts to a group. If the group is empty afterwards, il will be also deleted. :param args: a dictionary containing : { - 'host_list': val, # a list of IP adresses - 'group'; val # the group name + 'host_list': list<string>, # a list of IP adresses + 'group'; string # the group name } """ group = args['group'] @@ -769,7 +769,7 @@ class shelve_db: """ Add a list of users to the group notifications structure. :param args: a dictionary containing : - { 'users': list<string>, 'group': val } + { 'users': list<string>, 'group': string } """ users = args['users'] group = args['group'] @@ -784,12 +784,17 @@ class shelve_db: """ Updates the subscription to a following user from a host. :param args: - { 'group': val, - 'username': val, - 'subscription: [ - { notif_mod: priority }, - ... - ] + { 'group': string, + 'username': string, + 'subscription': + {'minor': [ + { notif_mod: priority }, + ... + ], + 'major': [ + { notif_mod: priority }, + ... + ]} } :return: """ @@ -805,7 +810,7 @@ class shelve_db: """ Unsubscribes an user for a host notifications. :param args: a dictionary containing : - { 'username': val, 'group': val } + { 'username': string, 'group': string } """ username = args['username'] group = args['group'] @@ -819,9 +824,17 @@ class shelve_db: """ :param args: A dictionary containing : - { 'group': val } - :return: a list containing : - [{ 'username': val, 'priority': val }, ... ] + { 'group': string } + :return: a dictionary containing : + { username: + {'minor': [ + { notif_mod: priority }, + ... + ], + 'major': [ + { notif_mod: priority }, + ... + ]}} """ group = args['group'] res = [] @@ -836,7 +849,7 @@ class shelve_db: """ Create a basic empty structure on the database for a new user. :param args: a dictionary containing : - { 'username': val } + { 'username': string } """ username = args['username'] self.open_db() @@ -869,7 +882,7 @@ class shelve_db: Removes a user from the database. If the user is registered to a host or a group, it is also deleted from these lists :param args: a dictionary containing : - { 'username': val } + { 'username': string } """ username = args['username'] self.open_db() @@ -891,7 +904,7 @@ class shelve_db: """ Add a list of users to the host notifications structure. :param args: a dictionary containing : - { 'users': list<string>, 'addr_host': val } + { 'users': list<string>, 'addr_host': string } """ users = args['users'] addr_host = args['addr_host'] @@ -906,12 +919,17 @@ class shelve_db: """ Updates the subscription to a following user from a host. :param args: - { 'addr_host': val, - 'username': val, - 'subscription: [ - { notif_mod: priority }, - ... - ] + { 'addr_host': string, + 'username': string, + 'subscription': + {'minor': [ + { notif_mod: priority }, + ... + ], + 'major': [ + { notif_mod: priority }, + ... + ]} } :return: """ @@ -927,7 +945,7 @@ class shelve_db: """ Unsubscribes an user for host notifications. :param args: a dictionary containing : - { 'username': val, 'addr_host': val } + { 'username': string, 'addr_host': string } """ username = args['username'] addr_host = args['addr_host'] @@ -941,9 +959,17 @@ class shelve_db: """ Get informations about the subscribers to a host. :param args: A dictionary containing : - { 'addr_host': val } + { 'addr_host': string } :return: a dictionary containing : - { username: [{ 'notif_mod': val, 'priority': val }, ... ]} + { username: + {'minor': [ + { notif_mod: priority }, + ... + ], + 'major': [ + { notif_mod: priority }, + ... + ]}} """ addr_host = args['addr_host'] res = {} diff --git a/static/js/controllers/notificationsCtrl.js b/static/js/controllers/notificationsCtrl.js index 38fcfe0..1e19332 100644 --- a/static/js/controllers/notificationsCtrl.js +++ b/static/js/controllers/notificationsCtrl.js @@ -17,7 +17,7 @@ mumApp.controller('notificationsCtrl', function($scope, $rootScope, $modal, Data ] */ - $scope.notif_mods = {}; + $scope.notif_mods = {}; // {notif_mod :{param1:val1, param2:val2, ...}} $rootScope.$broadcast("sendViaWs", JSON.stringify({"GET_LOADED_NOTIF_MOD": ""})); @@ -27,7 +27,10 @@ mumApp.controller('notificationsCtrl', function($scope, $rootScope, $modal, Data }); }); - $scope.subscriber_data = {}; + $scope.subscriber_data = {}; /* {username:{"minor":{mod_notif:{"activated":bool,"priority":int}, ...}, + "major":{mod_notif:{"activated":bool,"priority":int}}}} */ + + $scope.subscriber_data_unchanged = {}; // used to discard changes $scope.allGroups = function(){ var res = [] @@ -58,12 +61,45 @@ mumApp.controller('notificationsCtrl', function($scope, $rootScope, $modal, Data } } - $scope.$on("resCall", function (event, args) { + $scope.$on("resCall", function (event, args) { /* args= { username: + {'minor': [ + { notif_mod: priority }, + ... + ], + 'major': [ + { notif_mod: priority }, + ... + ]}} */ $scope.$apply(function(){ - $scope.subscriber_data = args; + 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 $scope.notif_mods){ + if(!sd[user].hasOwnProperty(notif_mod)){ + sd[user]['minor'][notif_mod] = {'activated': false, 'priority': null}; + sd[user]['major'][notif_mod] = {'activated': false, 'priority': null}; + } + } + } + $scope.subscriber_data = sd; + $scope.subscriber_data_unchanged = sd; }); }); + $scope.discard = function(){ + $scope.subscriber_data = $scope.subscriber_data_unchanged; + } + + $scope.save = function(){ + + } + $scope.open_modal_add_subscriber = function (mod_name) { var modalInstance = $modal.open({ templateUrl: 'modal_add_subscriber_label.html', diff --git a/views/notifications.html b/views/notifications.html index 9647ed8..0f73cce 100644 --- a/views/notifications.html +++ b/views/notifications.html @@ -54,126 +54,30 @@ </tr> </thead> <tbody> - <tr> - <td rowspan="3">G.G.</td> - <td>Browser</td> - <td> - <div class="input-group"> - <span class="input-group-addon"> - <input type="checkbox" aria-label="jcbrowsermincheck"> - </span> - <input type="number" min="1" class="form-control" aria-label="jcbrowserminnb" placeholder="1"> - </div> - </td> - <td> - <div class="input-group"> - <span class="input-group-addon"> - <input type="checkbox" aria-label="jcbrowsermajcheck"> - </span> - <input type="number" min="1" class="form-control" aria-label="jcbrowsermajnb" placeholder="1"> - </div> - </td> - </tr> - <tr> - <td>E-mail</td> - <td> - <div class="input-group"> - <span class="input-group-addon"> - <input type="checkbox" aria-label="jcmailmincheck"> - </span> - <input type="number" min="1" class="form-control" aria-label="jcmailminnb" placeholder="1"> - </div> - </td> - <td> - <div class="input-group"> - <span class="input-group-addon"> - <input type="checkbox" aria-label="jcmailmajcheck"> - </span> - <input type="number" min="1" class="form-control" aria-label="jcmailmajnb" placeholder="1"> - </div> - </td> - </tr> - <tr> - <td>SMS</td> - <td> - <div class="input-group"> - <span class="input-group-addon"> - <input type="checkbox" aria-label="jcsmsmincheck"> - </span> - <input type="number" min="1" class="form-control" aria-label="jcsmsminnb" placeholder="1"> - </div> - </td> - <td> - <div class="input-group"> - <span class="input-group-addon"> - <input type="checkbox" aria-label="jcsmsmajcheck"> - </span> - <input type="number" min="1" class="form-control" aria-label="jcsmsmajnb" placeholder="1"> - </div> - </td> - </tr> - <tr> - <td rowspan="3">J.C.</td> - <td>Browser</td> - <td> - <div class="input-group"> - <span class="input-group-addon"> - <input type="checkbox" aria-label="ggbrowserminchecj"> - </span> - <input type="number" min="1" class="form-control" aria-label="ggbrowserminnb" placeholder="1"> - </div> - </td> - <td> - <div class="input-group"> - <span class="input-group-addon"> - <input type="checkbox" aria-label="ggbrowsermajcheck"> - </span> - <input type="number" min="1" class="form-control" aria-label="ggbrowsermajnb" placeholder="1"> - </div> - </td> - </tr> - <tr> - <td>E-mail</td> - <td> - <div class="input-group"> - <span class="input-group-addon"> - <input type="checkbox" aria-label="ggmailmincheck"> - </span> - <input type="number" min="1" class="form-control" aria-label="ggmailminnb" placeholder="1"> - </div> - </td> - <td> - <div class="input-group"> - <span class="input-group-addon"> - <input type="checkbox" aria-label="ggmailmajcheck"> - </span> - <input type="number" min="1" class="form-control" aria-label="ggmailmajnb" placeholder="1"> - </div> - </td> - </tr> - <tr> - <td>SMS</td> - <td> + <tr ng-repeat="(username, user) in subscriber_data"> + <td>{{username}}</td> + <td ng-repeat="(mod_name, mod_param) in user.minor">{{mod_name}}</td> + <td ng-repeat="(mod_name, mod_param) in user.minor"> <div class="input-group"> <span class="input-group-addon"> - <input type="checkbox" aria-label="ggsmsmincheck"> + <input type="checkbox" ng-model="mod_param.activated"> </span> - <input type="number" min="1" class="form-control" aria-label="ggsmsminnb" placeholder="1"> + <input type="number" min="1" class="form-control" ng-model="mod_param.priority"> </div> </td> - <td> + <td ng-repeat="(mod_name, mod_param) in user.major"> <div class="input-group"> <span class="input-group-addon"> - <input type="checkbox" aria-label="ggsmsmajcheck"> + <input type="checkbox" ng-model="mod_param.activated"> </span> - <input type="number" min="1" class="form-control" aria-label="ggsmsmajnb" placeholder="1"> + <input type="number" min="1" class="form-control" ng-model="mod_param.priority"> </div> </td> </tr> </tbody> </table> - <button type="button" class="btn btn-default">Discard changes</button> - <button type="button" class="btn btn-primary">Save changes</button> + <button type="button" class="btn btn-default" ng-click="discard()">Discard changes</button> + <button type="button" class="btn btn-primary" ng-click="save()">Save changes</button> </div> </div> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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>.
participants (1)
-
chorem.org scm