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 a7dbf94ba8a9d0c9df769f27f7f18478583f28cb Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Tue Mar 31 10:58:05 2015 +0200 notifications: bilan de toutes les notif --- app/module_loader.py | 52 +++++++++++++++++------------- app/mum.py | 34 +++++++++++-------- static/js/controllers/headCtrl.js | 3 ++ static/js/controllers/hostPageCtrl.js | 4 +-- static/js/controllers/notificationsCtrl.js | 33 ++++++++++++++++++- static/js/controllers/settingsCtrl.js | 3 ++ static/js/mumApp.js | 4 +-- views/hostpage.html | 5 ++- views/notifications.html | 41 +++++++++++++++++++++++ 9 files changed, 137 insertions(+), 42 deletions(-) diff --git a/app/module_loader.py b/app/module_loader.py index bfde9ca..33ff089 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -168,27 +168,28 @@ class ModuleLoader: print "Error : internal monitoring module " + mod_name + " could not have been loaded. " # Now for external modules: - sys.path.insert(0, self.conf['external_modules_location']) # Adding the external diretory into pythonpath - for importer, mod_name, ispkg in pkgutil.iter_modules([self.conf['external_modules_location']]): - if mod_name not in sys.modules: - try: - loaded_mod = __import__(mod_name, fromlist=[mod_name]) - class_name = getattr(loaded_mod, "get_class_name")() - mod_inst = getattr(loaded_mod, class_name)(None, None, None) - infos_mod = {} - infos_mod['imported'] = loaded_mod - infos_mod['class_name'] = getattr(mod_inst, 'get_name')() - infos_mod['compatible_os'] = getattr(mod_inst, 'get_compatible_os')() - for os in infos_mod['compatible_os']: - if os not in self.compatible_os_list: - self.compatible_os_list.append(os) - infos_mod['block'] = getattr(mod_inst, 'get_block')() - infos_mod['unit'] = getattr(mod_inst, 'get_unit')() - infos_mod['external'] = True - self.loaded_mod_moni[mod_name] = infos_mod - except AttributeError: - print "Error : external monitoring module " + mod_name + " could not have been loaded. " - print "Please verify that every necessary methods have been implemented." + if self.conf['external_modules_location'] is not None: + sys.path.insert(0, self.conf['external_modules_location']) # Adding the external diretory into pythonpath + for importer, mod_name, ispkg in pkgutil.iter_modules([self.conf['external_modules_location']]): + if mod_name not in sys.modules: + try: + loaded_mod = __import__(mod_name, fromlist=[mod_name]) + class_name = getattr(loaded_mod, "get_class_name")() + mod_inst = getattr(loaded_mod, class_name)(None, None, None) + infos_mod = {} + infos_mod['imported'] = loaded_mod + infos_mod['class_name'] = getattr(mod_inst, 'get_name')() + infos_mod['compatible_os'] = getattr(mod_inst, 'get_compatible_os')() + for os in infos_mod['compatible_os']: + if os not in self.compatible_os_list: + self.compatible_os_list.append(os) + infos_mod['block'] = getattr(mod_inst, 'get_block')() + infos_mod['unit'] = getattr(mod_inst, 'get_unit')() + infos_mod['external'] = True + self.loaded_mod_moni[mod_name] = infos_mod + except AttributeError: + print "Error : external monitoring module " + mod_name + " could not have been loaded. " + print "Please verify that every necessary methods have been implemented." def run_one_monitoring_module(self, mod_name, addr_host, conn, db): """ @@ -411,4 +412,11 @@ class ModuleLoader: def get_host_info(self, addr_host): host_info = self.db.get_host_informations(addr_host) host_info['compatible_os_list'] = self.compatible_os_list - return host_info \ No newline at end of file + return host_info + + def get_all_subscriptions(self): + 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 diff --git a/app/mum.py b/app/mum.py index ed5add2..eaf1e25 100755 --- a/app/mum.py +++ b/app/mum.py @@ -128,7 +128,7 @@ def receive(ws): start_first_detection(msg["NMAP_SCAN_DEMAND"], ml, ws) elif code == "LAUNCH_FULL_DETECTION": # asked from hostpage ml.run_all_detection_modules(msg["LAUNCH_FULL_DETECTION"]) - ws.send(json_dumps({"SUCCESS_MODULE": "Full detection"})) + ws.send(json.dumps({"SUCCESS_MODULE": "Full detection"})) elif code == "GET_HOSTS": # asked from head controller db = ml.get_db() ws.send(json.dumps({"RES_GET_HOSTS": db.get_hosts()})) @@ -142,11 +142,13 @@ def receive(ws): }}) ws.send(msg) elif code == "GET_LOADED_CONN_MOD": # asked from hostpage, at the connection configuration - ws.send(json_dumps({"RES_GET_LOADED_CONN_MOD": ml.get_info_mod_conn()})) + ws.send(json.dumps({"RES_GET_LOADED_CONN_MOD": ml.get_info_mod_conn()})) elif code == "GET_LOADED_MONI_MOD": # asked from hostpage, at the block activation conf - ws.send(json_dumps({"RES_GET_LOADED_MONI_MOD": ml.get_info_mod_monitoring()})) + ws.send(json.dumps({"RES_GET_LOADED_MONI_MOD": ml.get_info_mod_monitoring()})) elif code == "GET_LOADED_NOTIF_MOD": # asekd from notification parameters page - ws.send(json_dumps({"RES_GET_LOADED_NOTIF_MOD": ml.get_info_mod_notification()})) + ws.send(json.dumps({"RES_GET_LOADED_NOTIF_MOD": ml.get_info_mod_notification()})) + elif code == "GET_ALL_SUBSCRIPTIONS": # asekd from notification parameters page + ws.send(json.dumps({"RES_GET_ALL_SUBSCRIPTIONS": ml.get_all_subscriptions()})) elif code == "SET_MOD_ACTIVATION": # asked from hostpage, at the block activation conf ml.update_activated_modules(msg["SET_MOD_ACTIVATION"]) elif code == "TEST_CONN": @@ -163,7 +165,7 @@ def receive(ws): args = msg["CHECK_NOW"] ml.run_one_monitoring_module(args['mod_name'], args['addr_host'], None, None) elif code == "GET_KEYS_LIST": # asked from hostpage, at the connection configuration - ws.send(json_dumps({"KEYS_LIST": ml.get_public_keys_list()})) + ws.send(json.dumps({"KEYS_LIST": ml.get_public_keys_list()})) else: break except WebSocketError: # Should be WebSocketError when closing the connection @@ -187,16 +189,20 @@ if __name__ == '__main__': global wsc # creating the parser for the command line arguments - parser = argparse.ArgumentParser() - parser.add_argument("conf_loc", help="the location of the configuration file (can be relative)") - parser.add_argument("--server_port", type=int, help="the port of the service. REQUIRED") - parser.add_argument("--server_addr", help="the address of the service. REQUIRED") - parser.add_argument("--db_location", help="the location of the shelve database. REQUIRED") - parser.add_argument("--external_modules_location", help="the location of the external monitoring modules. REQUIRED") + parser = argparse.ArgumentParser(description="Mum (Machines Under Monotoring) is a web-oriented and modulable " + "monitoring service.", + epilog="The following fields must be specified on the configuration file or by " + "arguments in order to launch the service: server_port, server_addr, " + "db_location.") + parser.add_argument("conf_loc", help="the location of the configuration file (can be relative from the launcher)") + parser.add_argument("--server_port", type=int, help="the port of the service.") + parser.add_argument("--server_addr", help="the address of the service.") + parser.add_argument("--db_location", help="the location of the shelve database.") + parser.add_argument("--external_modules_location", help="the location of the external monitoring modules.") parser.add_argument("--keys_location", help="the location of the directory containing the SSH keys.") - parser.add_argument("--smtp_server", help="the name of the SMTP server to send e-mail notifications") - parser.add_argument("--smtp_port", help="the port of the SMTP server") - parser.add_argument("--smtp_address", help="the e-mail address of the sender for the e-mail notifications") + parser.add_argument("--smtp_server", help="name of the SMTP server to send e-mail notifications") + parser.add_argument("--smtp_port", help="port number of the SMTP server") + parser.add_argument("--smtp_address", help="e-mail address of the sender for e-mail notifications") args = parser.parse_args() # creating the default conf structure from the configuration file diff --git a/static/js/controllers/headCtrl.js b/static/js/controllers/headCtrl.js index f70426a..eea029c 100644 --- a/static/js/controllers/headCtrl.js +++ b/static/js/controllers/headCtrl.js @@ -50,6 +50,9 @@ mumApp.controller('headCtrl', function($scope, $rootScope, toastr, $interval, $r 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_CALL_FUNC_DB": // Get a result after calling a funcion on the db $rootScope.$broadcast("resCall", obj[key]); break; diff --git a/static/js/controllers/hostPageCtrl.js b/static/js/controllers/hostPageCtrl.js index 90963f2..809517b 100644 --- a/static/js/controllers/hostPageCtrl.js +++ b/static/js/controllers/hostPageCtrl.js @@ -36,7 +36,7 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $route, $routePar } */ $scope.update_os_name = function(){ - args = {}; + var args = {}; args['addr_host'] = $scope.addr_host; args['new_os_name'] = $scope.model.new_os; $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'update_os_name', 'args': args}})); @@ -106,7 +106,7 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $route, $routePar }; $scope.remove_host = function(){ - args = {}; + var args = {}; args['addr_host'] = $scope.addr_host; $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'remove_host', 'args': args}})); } diff --git a/static/js/controllers/notificationsCtrl.js b/static/js/controllers/notificationsCtrl.js index 71764f2..e9330b6 100644 --- a/static/js/controllers/notificationsCtrl.js +++ b/static/js/controllers/notificationsCtrl.js @@ -19,9 +19,18 @@ mumApp.controller('notificationsCtrl', function($scope, $rootScope, $modal, $rou $scope.subtitle = ""; + $scope.all_subscriptions = {}; // {user1: {'hosts': {addr_host: {'major': {}, 'minor': {}}}, 'groups': {...}}, ... } + $scope.notif_mods = {}; // {notif_mod :{param1:val1, param2:val2, ...}} - $rootScope.$broadcast("sendViaWs", JSON.stringify({"GET_LOADED_NOTIF_MOD": ""})); + $rootScope.$broadcast("sendViaWs", JSON.stringify({"GET_ALL_SUBSCRIPTIONS": ""})); + + $scope.$on("resGetAllSubscriptions", function (event, args) { + $scope.$apply(function(){ + $scope.all_subscriptions = args; + }); + $rootScope.$broadcast("sendViaWs", JSON.stringify({"GET_LOADED_NOTIF_MOD": ""})); + }); $scope.$on("resGetLoadedNotifMod", function (event, args) { $scope.$apply(function(){ @@ -47,6 +56,28 @@ mumApp.controller('notificationsCtrl', function($scope, $rootScope, $modal, $rou return res; }; + $scope.is_activated = function(struct){ // {modname:{"priority":int,"activated":bool}, ...} + res = false; + if(struct != {}){ + for(mod in struct){ + if(struct[mod].activated){ + res = true; + } + } + } + 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.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"} diff --git a/static/js/controllers/settingsCtrl.js b/static/js/controllers/settingsCtrl.js new file mode 100644 index 0000000..f548909 --- /dev/null +++ b/static/js/controllers/settingsCtrl.js @@ -0,0 +1,3 @@ +mumApp.controller('settingsCtrl', function($scope, $rootScope) { + +}); \ No newline at end of file diff --git a/static/js/mumApp.js b/static/js/mumApp.js index 15d9897..5151687 100644 --- a/static/js/mumApp.js +++ b/static/js/mumApp.js @@ -39,8 +39,8 @@ mumApp.config(function($routeProvider){ controller : 'scanCtrl' }) .when('/settings',{ - templateUrl : 'settings.html' - //controller : 'mainController' + templateUrl : 'settings.html', + controller : 'settingsCtrl' }) .when('/signin',{ templateUrl : 'signin.html' diff --git a/views/hostpage.html b/views/hostpage.html index ef15943..189dc14 100644 --- a/views/hostpage.html +++ b/views/hostpage.html @@ -1,7 +1,10 @@ <div class="col-md-offset-2 main"> <h1 class="page-header">Current state of {{addr_host}} <small>{{items.hostname}}</small></h1> - <button type="button" class="btn btn-primary btn-xs" ng-click="open_modal_block()">Activate/Deactivate</button> + <button type="button" class="btn btn-primary btn-xs" + ng-click="open_modal_block()" + popover="Activate or deactivate monitoring modules by block." + popover-trigger="mouseenter">Activate/Deactivate</button> <button type="button" class="btn btn-primary btn-xs" ng-click="open_modal_conn()">Connection settings</button> <button type="button" class="btn btn-info btn-xs" ng-click="launch_detection()">Launch a full detection</button> <button type="button" class="btn btn-danger btn-xs" ng-click="remove_host()">Remove this host</button> diff --git a/views/notifications.html b/views/notifications.html index 181a7eb..1d6a182 100644 --- a/views/notifications.html +++ b/views/notifications.html @@ -1,6 +1,47 @@ <div class="col-md-offset-2 main"> <h1 class="page-header">Who to notify? <small>{{subtitle}}</small></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> + <!--<table class="table table-hover" ng-repeat="(username, user) in all_subscriptions"> + + <thead> + <tr> + <th>Host</th> + <th>Notification service</th> + <th>Minor</th> + <th>Major</th> + </tr> + </thead> + <tbody> + <tr ng-repeat-start="(addr_host, host) in all_subscriptions.user.hosts"> + <td>{{addr_host}}</td> + </tr> + <tr ng-repeat-end + ng-repeat="(notif_mod_name, notif_mod) in host.minor"> + <td></td> + <td>{{notif_mod_name}}</td> + <td> + {{notif_mod.gzkf}} + {{notif_mod.priority}} + </td> + <td> + {{user_subscriptions.hosts[addr_host].major[notif_mod_name].priority}} + </td> + </tr> + </tbody> + </table>--> <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>.