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 112abc7116b6ee0060d8e3bbd76ada3d1c192bee Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Apr 15 17:50:02 2015 +0200 wen state available for hosts: idle. Monitoring can be idle on hostpage --- app/module_loader.py | 13 +++++++++ app/modules/storage_modules/shelve_db.py | 47 ++++++++++++++++++++++++++++---- app/mum.py | 6 ++++ app/process_monitoring.py | 3 +- static/js/controllers/dashboardCtrl.js | 2 +- static/js/controllers/headCtrl.js | 5 +++- static/js/controllers/hostPageCtrl.js | 17 ++++++++++++ views/dashboard.html | 1 + views/hostpage.html | 14 ++++++++-- views/index.html | 1 + 10 files changed, 97 insertions(+), 12 deletions(-) diff --git a/app/module_loader.py b/app/module_loader.py index d375330..72e265a 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -466,6 +466,19 @@ class ModuleLoader: """ return getattr(self.db, dict_instr['func'])(dict_instr['args']) + def set_idling_state(self, addr_host): + """ + + :param addr_host: + :return: + """ + dict_instr = self.db.set_monitoring_activation(addr_host) + if "rem" in dict_instr: + process_monitoring.remove_to_waiting_list(addr_host, None) + elif dict_instr['add'] != []: + for instr in dict_instr['add']: + process_monitoring.add_to_waiting_list(instr) + def update_activated_modules(self, args): """ Save on the database, the new configuration concerning the activation/deactivation diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index b1cfa7f..4c24929 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -175,6 +175,9 @@ class shelve_db: for mod in dict_mod_info: if os_host in dict_mod_info[mod]['compatible_os'] or 'all' in dict_mod_info[mod]['compatible_os']: self.db["hosts"][addr_host]["conf"]["monitoring"][mod] = self.db['global_conf'][mod] + self.db['hosts'][addr_host]['conf']['idling'] = {} # For reactivation after an idle state + self.db['hosts'][addr_host]['conf']['idling']['modules'] = [] + self.db['hosts'][addr_host]['conf']['idling']['status'] = "" self.db["hosts"][addr_host]["conf"]["groups"] = ["all"] # Every host is in group "all" self.db["hosts"][addr_host]["conf"]["subscribers"] = {} # Add current user automatically ? self.db["hosts"][addr_host]["conf"]["custom_info"] = "" @@ -252,7 +255,6 @@ class shelve_db: :return: structured informations about monitoring in form : [{ '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) @@ -265,7 +267,6 @@ class shelve_db: if self.db['hosts'][addr_host]['conf']['monitoring'][mod]['activated']: dict_moni = {} dict_moni['addr'] = addr_host - dict_moni['os'] = json.loads(self.db['hosts'][addr_host]['detected']['nmap'])['os'] dict_moni['mod_name'] = mod if mod in self.db['hosts'][addr_host]['monitoring']: # the service have benn restarted, the next check will occure at last_check + check_freq @@ -389,6 +390,7 @@ class shelve_db: mod_name: bool }, "custom_infos":string + "status": string } """ self.open_db() @@ -410,6 +412,7 @@ class shelve_db: res['activated_monitoring'][mod] = self.db['hosts'][addr_host]['conf']['monitoring'][mod]['activated'] res['custom_infos'] = self.db['hosts'][addr_host]['conf']['custom_info'] res['interventions'] = self.db['hosts'][addr_host]['conf']['interventions'] + res['status'] = self.db['hosts'][addr_host]['status']['state'] except Exception: print traceback.format_exc() finally: @@ -521,6 +524,42 @@ class shelve_db: finally: self.close_db() + def set_monitoring_activation(self, addr_host): + """ + Called from the hostpage. Put the monitoring of a host on a idlling state, or activates back its monitoring. + :param addr_host: the IP addres of the host to idle the monitoring or resume it + """ + res_instr = {} + res_instr['add'] = [] + self.open_db() + try: + if self.db['hosts'][addr_host]['status']['state'] != "idling": + # the monitoring was activated, we put it on idle state + for mod in self.db['hosts'][addr_host]['conf']['monitoring']: + if self.db['hosts'][addr_host]['conf']['monitoring'][mod]['activated']: + self.db['hosts'][addr_host]['conf']['monitoring'][mod]['activated'] = False + self.db['hosts'][addr_host]['conf']['idling']['modules'].append(mod) + self.db['hosts'][addr_host]['conf']['idling']['status'] = self.db['hosts'][addr_host]['status']['state'] + self.db['hosts'][addr_host]['status']['state'] = "idling" + res_instr['rem'] = None + else: + # the monitoring was in an indle state, we activate it again + for mod in self.db['hosts'][addr_host]['conf']['idling']['modules']: + self.db['hosts'][addr_host]['conf']['monitoring'][mod]['activated'] = True + add_instr = {} + add_instr['addr'] = addr_host + add_instr['mod_name'] = mod + add_instr['time'] = datetime.now() + add_instr['freq'] = self.db['hosts'][addr_host]['conf']['monitoring'][mod]['check_frequency'] + res_instr['add'].append(add_instr) + self.db['hosts'][addr_host]['conf']['idling']['modules'] = [] + self.db['hosts'][addr_host]['status']['state'] = self.db['hosts'][addr_host]['conf']['idling']['status'] + except Exception: + print traceback.format_exc() + finally: + self.close_db() + return res_instr + def config_mod_activation(self, args): """ Activates or desactivates monitoring modules for a given host @@ -533,7 +572,7 @@ class shelve_db: } :return: a dictionary containing the instructions to send to the process monitoring in the form: { - 'add': [{'addr': str, 'os': str, 'mod_name': str, 'time': datetime, 'freq': int}, ...] + 'add': [{'addr': str, 'mod_name': str, 'time': datetime, 'freq': int}, ...] 'rem': [{'addr': str, 'mod_name': str}, ... ] } """ @@ -552,7 +591,6 @@ class shelve_db: # we now add an instruction on the monitoring list add_instr = {} add_instr['addr'] = addr_host - add_instr['os'] = json.loads(self.db['hosts'][addr_host]['detected']['nmap'])['os'] add_instr['mod_name'] = mod_name add_instr['time'] = datetime.now() add_instr['freq'] = self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['check_frequency'] @@ -565,7 +603,6 @@ class shelve_db: self.db["hosts"][addr_host]["conf"]["monitoring"][mod_name]["activated"] = True add_instr = {} add_instr['addr'] = addr_host - add_instr['os'] = json.loads(self.db['hosts'][addr_host]['detected']['nmap'])['os'] add_instr['mod_name'] = mod_name add_instr['time'] = datetime.now() add_instr['freq'] = self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['check_frequency'] diff --git a/app/mum.py b/app/mum.py index 0395b30..a4a43e7 100755 --- a/app/mum.py +++ b/app/mum.py @@ -150,6 +150,12 @@ def receive(ws): 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_IDLE_STATE": + ml.set_idling_state(msg["SET_IDLE_STATE"]) + dict_host_info = ml.get_host_info(msg["SET_IDLE_STATE"]) + dict_host_info['loaded_moni_mod'] = ml.get_info_mod_monitoring() + ws.send(json.dumps({"RES_INFO_HOST": dict_host_info})) + ws.send(json.dumps({"RES_GET_HOSTS": ml.get_db().get_hosts()})) 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": diff --git a/app/process_monitoring.py b/app/process_monitoring.py index 8c72086..9085da7 100644 --- a/app/process_monitoring.py +++ b/app/process_monitoring.py @@ -24,7 +24,6 @@ class ProcessMonitoring(threading.Thread): in the 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) @@ -67,7 +66,7 @@ def add_to_waiting_list(dict_mod): """ Adds an element to the waiting queue and keep it ordered by crescent launching times. :param dict_mod: a dictionary containing: - {'addr': str, 'os': str, 'mod_name': str, 'time': datetime, 'freq': int} + {'addr': str, 'mod_name': str, 'time': datetime, 'freq': int} """ global waiting_list if waiting_list == []: diff --git a/static/js/controllers/dashboardCtrl.js b/static/js/controllers/dashboardCtrl.js index 07df506..6b5ffc9 100644 --- a/static/js/controllers/dashboardCtrl.js +++ b/static/js/controllers/dashboardCtrl.js @@ -40,7 +40,7 @@ mumApp.controller('dashboardCtrl', function($scope, $filter, $routeParams, DataH $scope.name_filter = ''; if($routeParams.param == null){ - $scope.status_filter = ["success", "warning", "danger"]; + $scope.status_filter = ["success", "warning", "danger", "idling", ""]; } else{ $scope.status_filter = [$routeParams.param]; diff --git a/static/js/controllers/headCtrl.js b/static/js/controllers/headCtrl.js index 4e63e29..f162fd2 100644 --- a/static/js/controllers/headCtrl.js +++ b/static/js/controllers/headCtrl.js @@ -115,7 +115,7 @@ mumApp.controller('headCtrl', function($scope, $rootScope, toastr, $interval, $r * Return a vector with the number of hosts with a status of : success, warning, danger */ $scope.stateNumber = function(){ - var res = [0,0,0]; + var res = [0,0,0,0]; for(var i = 0; i<$scope.items.length; i++){ if($scope.items[i].status === "success"){ res[0]++; @@ -126,6 +126,9 @@ mumApp.controller('headCtrl', function($scope, $rootScope, toastr, $interval, $r if($scope.items[i].status === "danger"){ res[2]++; } + if($scope.items[i].status === "idling"){ + res[3]++; + } } return res; }; diff --git a/static/js/controllers/hostPageCtrl.js b/static/js/controllers/hostPageCtrl.js index 2717d01..041632d 100644 --- a/static/js/controllers/hostPageCtrl.js +++ b/static/js/controllers/hostPageCtrl.js @@ -19,6 +19,7 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $route, $routePar } } "hostname":val, + "status": string, "monitoring": { modname: @@ -60,6 +61,17 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $route, $routePar return res; } + $scope.get_idle_state = function(){ + res = ""; + if($scope.items.status == "idling"){ + res = "danger"; + } + else{ + res = "success"; + } + return res + } + $scope.$on("resCall", function (event, args) { if(args.func == 'update_os_name'){ $route.reload(); @@ -81,6 +93,10 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $route, $routePar $rootScope.$broadcast("sendViaWs", JSON.stringify({"CHECK_NOW": args})); }; + $scope.set_idle_state = function(){ + $rootScope.$broadcast("sendViaWs", JSON.stringify({"SET_IDLE_STATE": $scope.addr_host})); + } + $scope.get_addr_host = function(){ return($scope.addr_host); }; @@ -100,6 +116,7 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $route, $routePar } else{ // we takes only monitoring updates $scope.items.monitoring = args.monitoring; + $scope.items.status = args.status; } }); }); diff --git a/views/dashboard.html b/views/dashboard.html index 4e964cb..b50abb6 100644 --- a/views/dashboard.html +++ b/views/dashboard.html @@ -18,6 +18,7 @@ <option>success</option> <option>warning</option> <option>danger</option> + <option>idling</option> </select> </div> <div class="col-xs-2"> diff --git a/views/hostpage.html b/views/hostpage.html index 269e193..b56c6c0 100644 --- a/views/hostpage.html +++ b/views/hostpage.html @@ -1,14 +1,22 @@ <div class="col-md-offset-2 main"> - <h1 class="page-header">Current state of {{addr_host}} <small>{{items.hostname}}</small></h1> + <h1 class="page-header">Current state of {{addr_host}} <small>{{items.hostname}}</small> + <button type="button" + class="btn btn-{{get_idle_state()}}" + aria-label="Button activation" + ng-click="set_idle_state()"> + <span class="glyphicon glyphicon-off" aria-hidden="true"></span> + </button></h1> <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> + popover-trigger="mouseenter" + ng-disabled="items.status == 'idling'">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> - <table class="table table-condensed table-hover"> + <table class="table table-condensed table-hover" + ng-show="items.status != 'idling'"> <thead> <tr> diff --git a/views/index.html b/views/index.html index d6d5448..c4c02a9 100644 --- a/views/index.html +++ b/views/index.html @@ -60,6 +60,7 @@ <p class="navbar-text navbar-left"><a href="#dashboard/success" style="color:green">OK : {{stateNumber()[0]}}</a></p> <p class="navbar-text navbar-left"><a href="#dashboard/warning" style="color:orange">Warning : {{stateNumber()[1]}}</a></p> <p class="navbar-text navbar-left"><a href="#dashboard/danger" style="color:red">KO : {{stateNumber()[2]}}</a></p> + <p class="navbar-text navbar-left"><a href="#dashboard/idling" style="color:grey">Idling : {{stateNumber()[3]}}</a></p> </div> <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav navbar-right"> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.