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 e155b07b3c0504523ffbdaa96a52e7d8f47500a0 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Jun 8 12:43:21 2015 +0200 removed GET_ALL_SUBSCRIPTIONS websocket request + added get_groups functions on db + changed notifications summary page --- app/module_loader.py | 14 +------- app/modules/storage_modules/shelve_db.py | 20 +++++++++++ app/websocket_func.py | 5 --- static/js/controllers/headCtrl.js | 3 -- static/js/controllers/notificationsCtrl.js | 43 ++++++++-------------- views/notifications.html | 57 +++++++++++++++++++++++------- 6 files changed, 80 insertions(+), 62 deletions(-) diff --git a/app/module_loader.py b/app/module_loader.py index 2d9aa91..5a05c7a 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -623,16 +623,4 @@ class ModuleLoader: """ host_info = self.db.get_host_informations(addr_host) host_info['compatible_os_list'] = self.compatible_os_list - return host_info - - def get_all_subscriptions(self): - """ - Get, for every registered user, the subscriptions of these users. - :return: a dictionary containing: - {user1: {'hosts': {addr_host: {'major': {}, 'minor': {}}}, 'groups': {...}}, ... } - """ - res = {} - users = self.db.get_users(None) - for user in users: - res[user] = (self.db.get_user_subscriptions(user)) - return res \ No newline at end of file + return host_info \ No newline at end of file diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index 7db31ef..9bdb31a 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -420,6 +420,7 @@ class shelve_db: elif self.db["hosts"][host]["monitoring"][mod]["state"] == "danger": info_host["danger"].append(mod) info_host['nb_subscribers'] = len(self.db['hosts'][host]['conf']['subscribers'].keys()) + info_host['subscribers'] = self.db['hosts'][host]['conf']['subscribers'] res.append(info_host) except Exception: print traceback.format_exc() @@ -1205,6 +1206,25 @@ class shelve_db: finally: self.close_db() + def get_groups(self, args): + """ + Get all the groups informations + :param args: None (necessary for dynamic call via websocket) + :return: a dicionnary containing : + { grp_name: { 'hosts': [host1, ...], 'subscribers': + { usr: { 'minor': int, 'major': int }, ... + } } + """ + res = {} + self.open_db() + try: + res = self.db['groups'] + except Exception: + print traceback.format_exc() + finally: + self.close_db() + return res + def get_group_subscribers(self, args): """ Called from the notification page. diff --git a/app/websocket_func.py b/app/websocket_func.py index f97537b..f8a1d12 100644 --- a/app/websocket_func.py +++ b/app/websocket_func.py @@ -103,11 +103,6 @@ def GET_LOADED_NOTIF_MOD(msg, ws, ml): ws.send(json.dumps({"RES_GET_LOADED_NOTIF_MOD": ml.get_info_mod_notification()})) -# asekd from dashboard -def GET_ALL_SUBSCRIPTIONS(msg, ws, ml): - ws.send(json.dumps({"RES_GET_ALL_SUBSCRIPTIONS": ml.get_all_subscriptions()})) - - # asked from hostpage def SET_IDLE_STATE(msg, ws, ml): ml.set_idling_state(msg["SET_IDLE_STATE"]) diff --git a/static/js/controllers/headCtrl.js b/static/js/controllers/headCtrl.js index fb1701b..fe29e22 100644 --- a/static/js/controllers/headCtrl.js +++ b/static/js/controllers/headCtrl.js @@ -72,9 +72,6 @@ mumApp.controller('headCtrl', function ($scope, $rootScope, toastr, $interval, $ case "RES_GET_LOADED_NOTIF_MOD": $rootScope.$broadcast("resGetLoadedNotifMod", obj[key]); break; - case "RES_GET_ALL_SUBSCRIPTIONS": - $rootScope.$broadcast("resGetAllSubscriptions", obj[key]); - break; case "RES_GET_SCAN_OPTIONS": $rootScope.$broadcast("resGetScanOptions", obj[key]); break; diff --git a/static/js/controllers/notificationsCtrl.js b/static/js/controllers/notificationsCtrl.js index 5ccefa1..bcf5ccc 100644 --- a/static/js/controllers/notificationsCtrl.js +++ b/static/js/controllers/notificationsCtrl.js @@ -1,5 +1,5 @@ mumApp.controller('notificationsCtrl', function ($scope, $rootScope, $modal, $route, $timeout, DataHosts) { - $scope.items = DataHosts.Items; /* [ + $scope.hosts = DataHosts.Items; /* [ { "addr":"192.168.74.1", "name":"www.example.com", @@ -17,35 +17,22 @@ mumApp.controller('notificationsCtrl', function ($scope, $rootScope, $modal, $ro ] */ - $scope.all_subscriptions = {}; // {user1: {'hosts': {addr_host: {'major': {}, 'minor': {}}}, 'groups': {...}}, ... } + $scope.groups = {}; /* { grp_name: { 'hosts': [host1, ...], 'subscribers': + { usr: { 'minor': int, 'major': int }, ... + } } + */ - $rootScope.$broadcast("sendViaWs", JSON.stringify({"GET_ALL_SUBSCRIPTIONS": ""})); + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'get_groups','args': null}})); - $scope.$on("resGetAllSubscriptions", function (event, args) { - $timeout(function () { - $scope.all_subscriptions = args; - }, 0); - }); - - $scope.is_activated = function(struct) { // {modname:{"priority":int,"activated":bool}, ...} - res = false; - if (struct != {}) { - for (mod in struct) { - if (struct[mod].activated) { - res = true; - } - } + $scope.$on("resCall", function (event, args) { + if (args.func == 'get_groups') { + $timeout(function () { + $scope.groups = args.res; + }, 0); } - return res; - }; + }); - $scope.get_activated = function (struct) { // {modname:{"priority":int,"activated":bool}, ...} - res = []; - for (mod in struct) { - if (struct[mod].activated) { - res[res.length] = mod + " at " + struct[mod].priority; - } - } - return res; - }; + $scope.nb_sub = function(sub_obj){ + return Object.keys(sub_obj).length; + } }); \ No newline at end of file diff --git a/views/notifications.html b/views/notifications.html index 267006f..4f68d2f 100644 --- a/views/notifications.html +++ b/views/notifications.html @@ -1,16 +1,47 @@ <div class="col-md-offset-2 main"> <h1 class="page-header">Subscriptions summary</h1> - <h3 ng-repeat-start="(username, user) in all_subscriptions">{{username}}</h3> - <dl ng-repeat-end - ng-repeat-start="(addr_host, host) in user.hosts"> - <dt>{{addr_host}}</dt> - <dd ng-show="is_activated(host.major)">Major: {{get_activated(host.major)}}</dd> - <dd ng-show="is_activated(host.minor)">Minor: {{get_activated(host.minor)}}</dd> - </dl> - <dl ng-repeat-end - ng-repeat="(grp_name, grp) in user.groups"> - <dt>{{grp_name}}</dt> - <dd ng-show="is_activated(grp.major)">Major: {{get_activated(grp.major)}}</dd> - <dd ng-show="is_activated(grp.minor)">Minor: {{get_activated(grp.minor)}}</dd> - </dl> + + <div ng-repeat="host_obj in hosts"> + <h3>Host {{host_obj.addr}} <small>{{host_obj.name}}</small></h3> + <div ng-repeat="(username, subscriber) in host_obj.subscribers" + ng-show="nb_sub(host_obj.subscribers) > 0"> + {{username}} will be notified: + <ul> + <li ng-repeat="(minor_notif_name, minor_notif_obj) in subscriber.minor" + ng-show="minor_notif_obj.activated"> + with {{minor_notif_name}} after {{minor_notif_obj.priority}} minor notification(s). + </li> + <li ng-repeat="(major_notif_name, major_notif_obj) in subscriber.major" + ng-show="major_notif_obj.activated"> + with {{major_notif_name}} after {{major_notif_obj.priority}} major notification(s). + </li> + </ul> + </div> + <div ng-show="nb_sub(host_obj.subscribers) == 0"> + No subscriptions. + </div> + <hr/> + </div> + + <div ng-repeat="(group_name, group_obj) in groups"> + <h3>Group {{group_name}} <small>{{group_obj.hosts}}</small></h3> + <div ng-repeat="(username, subscriber) in group_obj.subscribers" + ng-show="nb_sub(group_obj.subscribers) > 0"> + {{username}} will be notified: + <ul> + <li ng-repeat="(minor_notif_name, minor_notif_obj) in subscriber.minor" + ng-show="minor_notif_obj.activated"> + with {{minor_notif_name}} after {{minor_notif_obj.priority}} minor notification(s). + </li> + <li ng-repeat="(major_notif_name, major_notif_obj) in subscriber.major" + ng-show="major_notif_obj.activated"> + with {{major_notif_name}} after {{major_notif_obj.priority}} major notification(s). + </li> + </ul> + </div> + <div ng-show="nb_sub(group_obj.subscribers) == 0"> + No subscriptions. + </div> + <hr/> + </div> </div> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.