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 ce0339efd7a35d377b6d1c2df1c279d2c1ae9e7d Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Apr 2 10:24:21 2015 +0200 global_conf: affichage des modules par block et changement de conf possible --- app/modules/storage_modules/shelve_db.py | 43 ++++++- app/process_monitoring.py | 8 +- static/js/controllers/groupCtrl.js | 4 +- static/js/controllers/hostPageCtrl.js | 10 +- static/js/controllers/settingsCtrl.js | 106 +++++++++++++++- views/index.html | 1 + views/settings.html | 200 +++++++++++-------------------- 7 files changed, 227 insertions(+), 145 deletions(-) diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index 710abbf..a6c465a 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -47,7 +47,7 @@ class shelve_db: def init_global_conf(self, loaded_mod_moni): """ - This method is executed once at each launch of the application (see ModuleLoader constructor). + This method is executed once at each launch of the application. It creates an entrey on db['global_conf'] for each loaded monitoring module. If an entry exists for a non loaded module, it will be removed. :param loaded_mod_moni: a dictionary containing : @@ -84,8 +84,8 @@ class shelve_db: mod_conf['minor_limit'] = 95 mod_conf['major_limit'] = 100 elif unit == 'bool': - mod_conf['minor_limit'] = True - mod_conf['major_limit'] = False + mod_conf['minor_limit'] = False + mod_conf['major_limit'] = True else: mod_conf['minor_limit'] = 8 mod_conf['major_limit'] = 10 @@ -98,6 +98,43 @@ class shelve_db: finally: self.close_db() + def get_global_settings(self, args): + """ + Asked from the global settings configuration page. + :param args: null (for dynamic call) + :return: the content of db['global_conf'] + """ + res = {} + self.open_db() + try: + res = self.db['global_conf'] + except Exception: + print traceback.format_exc() + finally: + self.close_db() + return res + + def set_global_settings(self, args): + """ + Asked from the global settings configuration page. Updates the default configuration of a monitoring module. + :param args: A dictionnary containing : + { + 'mod_name': str, + 'minor_limit': val, + 'major_limit': val, + 'freq': int + } + """ + self.open_db() + try: + self.db['global_conf'][args['mod_name']]['minor_limit'] = args['minor_limit'] + self.db['global_conf'][args['mod_name']]['major_limit'] = args['major_limit'] + self.db['global_conf'][args['mod_name']]['check_frequency'] = args['freq'] + except Exception: + print traceback.format_exc() + finally: + self.close_db() + def add_host(self, addr_host, nmap_res, list_mod_conn, dict_mod_info): """ Called by the nmap_detection module. diff --git a/app/process_monitoring.py b/app/process_monitoring.py index bfe6076..42faa61 100644 --- a/app/process_monitoring.py +++ b/app/process_monitoring.py @@ -81,14 +81,20 @@ def add_to_waiting_list(dict_mod): def remove_to_waiting_list(addr_host, modname): global waiting_list - for i in range(len(waiting_list)): + i = 0 + while i < len(waiting_list): + print 'size: ' + str(len(waiting_list)) + print 'i: ' + str(i) if waiting_list[i]['addr'] == addr_host: if modname is None: # it was asked to remove all entries of this host waiting_list.pop(i) + i -= 1 elif waiting_list[i]['mod_name'] == modname: # we remove only the necessary module from the list waiting_list.pop(i) + i -= 1 + i += 1 def update_mod_on_waiting_list(new_conf): diff --git a/static/js/controllers/groupCtrl.js b/static/js/controllers/groupCtrl.js index eae2023..fb2e031 100644 --- a/static/js/controllers/groupCtrl.js +++ b/static/js/controllers/groupCtrl.js @@ -66,7 +66,7 @@ mumApp.controller('groupCtrl', function($scope, $rootScope, $filter, $route, $ro } } } - } + }; $scope.checkAll = function(bool){ $scope.selectedAll = bool; @@ -93,7 +93,7 @@ mumApp.controller('groupCtrl', function($scope, $rootScope, $filter, $route, $ro $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'remove_host_list_to_group','args': args}})); $route.reload(); - } + }; $scope.open_modal_group = function () { var modalInstance = $modal.open({ diff --git a/static/js/controllers/hostPageCtrl.js b/static/js/controllers/hostPageCtrl.js index 809517b..7f1a9eb 100644 --- a/static/js/controllers/hostPageCtrl.js +++ b/static/js/controllers/hostPageCtrl.js @@ -40,7 +40,7 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $route, $routePar 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}})); - } + }; $scope.$on("resCall", function (event, args) { if(args.func == 'update_os_name'){ @@ -75,7 +75,7 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $route, $routePar $scope.launch_detection = function(){ $rootScope.$broadcast("sendViaWs", JSON.stringify({"LAUNCH_FULL_DETECTION": $scope.addr_host})); - } + }; // receiving the host informations $scope.$on("hostInfos", function (event, args) { @@ -109,7 +109,7 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $route, $routePar var args = {}; args['addr_host'] = $scope.addr_host; $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'remove_host', 'args': args}})); - } + }; // creation of modals $scope.open_modal_conf = function (mod_name) { @@ -291,7 +291,7 @@ mumApp.controller('ModalConnInstanceCtrl', function ($scope, $rootScope, $modalI } }*/ return res; - } + }; $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'get_conn_param','args': {'addr_host': $scope.conn_args['addr_host']}}})); @@ -316,7 +316,7 @@ mumApp.controller('ModalConnInstanceCtrl', function ($scope, $rootScope, $modalI args['addr_host'] = $scope.conn_args["addr_host"]; args['conn_mod_name'] = connModName; $rootScope.$broadcast("sendViaWs", JSON.stringify({"TEST_CONN": args})); - } + }; $scope.ok = function () { var args = {}; diff --git a/static/js/controllers/settingsCtrl.js b/static/js/controllers/settingsCtrl.js index f548909..6e06a8f 100644 --- a/static/js/controllers/settingsCtrl.js +++ b/static/js/controllers/settingsCtrl.js @@ -1,3 +1,107 @@ -mumApp.controller('settingsCtrl', function($scope, $rootScope) { +mumApp.controller('settingsCtrl', function($scope, $rootScope, $modal) { + $scope.settings = {}; // { mod_name: {'check_frequency': 60, 'minor_limit': True, 'activated': False, 'major_limit': False, 'block': 'software', 'unit': 'bool'}} + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'get_global_settings','args': null}})); + + $scope.$on("resCall", function (event, args) { + if(args.func == 'get_global_settings'){ + $scope.$apply(function(){ + $scope.settings = args.res; + }); + } + }); + + $scope.all_blocks = function(){ + var res = []; + for(mod in $scope.settings){ + if(res.indexOf($scope.settings[mod]['block']) < 0){ // if the block is not in the res tab + res[res.length] = $scope.settings[mod].block; + } + } + return res; + }; + + $scope.all_mod_by_block = function(block){ + var res = {}; + for(mod in $scope.settings){ + if($scope.settings[mod]['block'] == block){ + res[mod] = $scope.settings[mod]; + } + } + return res; + }; + + $scope.open_modal_global_conf = function (mod_name) { + var modalInstance = $modal.open({ + templateUrl: 'modal_global_conf_label.html', + controller: 'ModalGlobalConfInstanceCtrl', + resolve: { + global_conf_args: function(){ + return {'conf_mod': $scope.settings[mod_name], 'mod_name': mod_name}; + } + } + }); + }; +}); + +mumApp.controller('ModalGlobalConfInstanceCtrl', function ($scope, $rootScope, $modalInstance, $route, global_conf_args) { + $scope.global_conf_args = global_conf_args; /* { 'mod_name': str, + 'conf_mod': {'check_frequency': 60, 'minor_limit': True, 'activated': False, 'major_limit': False, 'block': 'software', 'unit': 'bool'}} + } + */ + // init fields + $scope.freq_days = Math.floor(global_conf_args.conf_mod.check_frequency / 86400); + $scope.freq_hours = Math.floor((global_conf_args.conf_mod.check_frequency - $scope.freq_days * 86400) / 3600); + $scope.freq_minutes = Math.floor((global_conf_args.conf_mod.check_frequency - ($scope.freq_days * 86400) - ($scope.freq_hours * 3600)) / 60) + + $scope.minor_limit_percent = 0; + $scope.major_limit_percent = 0; + + $scope.minor_limit_unit = 0; + $scope.major_limit_unit = 0; + + $scope.limit_bool = 'minor'; + + if($scope.global_conf_args.conf_mod.unit == 'bool'){ + if($scope.global_conf_args.conf_mod.major_limit){ + $scope.limit_bool = 'major'; + } + } + else if($scope.global_conf_args.conf_mod.unit == '%'){ + $scope.minor_limit_percent = $scope.global_conf_args.conf_mod.minor_limit; + $scope.major_limit_percent = $scope.global_conf_args.conf_mod.major_limit; + } + else{ + $scope.minor_limit_unit = $scope.global_conf_args.conf_mod.minor_limit; + $scope.major_limit_unit = $scope.global_conf_args.conf_mod.major_limit; + } + + // after validation + $scope.ok = function () { + var args = {}; + args.mod_name = $scope.global_conf_args.mod_name; + args.freq = 86400 * $scope.freq_days + 3600 * $scope.freq_hours + 60 * $scope.freq_minutes; + if($scope.global_conf_args.conf_mod.unit == 'bool'){ + args.minor_limit = ($scope.limit_bool == 'minor'); + args.major_limit = ($scope.limit_bool == 'major'); + } + else if($scope.global_conf_args.conf_mod.unit == '%'){ + args.minor_limit = $scope.minor_limit_percent; + args.major_limit = $scope.major_limit_percent; + } + else{ + args.minor_limit = $scope.minor_limit_unit; + args.major_limit = $scope.major_limit_unit; + } + + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'set_global_settings','args': args}})); + + $modalInstance.close(); + + $route.reload(); + }; + + $scope.cancel = function () { + $modalInstance.close(); + }; }); \ No newline at end of file diff --git a/views/index.html b/views/index.html index 13335ff..d6d5448 100644 --- a/views/index.html +++ b/views/index.html @@ -34,6 +34,7 @@ <script src="static/js/controllers/notificationsCtrl.js"></script> <script src="static/js/controllers/profileCtrl.js"></script> <script src="static/js/controllers/scanCtrl.js"></script> + <script src="static/js/controllers/settingsCtrl.js"></script> <script src="static/js/controllers/usersCtrl.js"></script> diff --git a/views/settings.html b/views/settings.html index bfcd86a..d910116 100644 --- a/views/settings.html +++ b/views/settings.html @@ -1,145 +1,79 @@ <div class="col-md-offset-2 main"> <h1 class="page-header">Configure the default settings</h1> - <!--<h2 class="sub-header">They will be applied on each new host you will add.</h2>--> - <form> - <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> - <div class="panel panel-default"> - <div class="panel-heading" role="tab" id="headingOne"> - <h4 class="panel-title"> - <a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="false" aria-controls="collapseOne"> - Hardware - </a> - </h4> - </div> - <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne"> - <div class="panel-body"> - <h3>CPU</h3> - <div class="row"> - <div class="col-xs-2"> - <label for="cpu_freq">Frequency check</label> - <input type="text" class="form-control" id="cpu_freq" placeholder="d:hh:mm"> - </div> - <div class="col-xs-4"> - <label for="cpu_val1">Minor notification at {{cpu_warn}}% of charge</label> - <input type="range" name="cpu_warn" min="0" max="99" id="cpu_val1" ng-model="cpu_warn"> - </div> - <div class="col-xs-4"> - <label for="cpu_val2">Major notification at {{cpu_danger}}% of charge</label> - <input type="range" name="cpu_danger" min="{{cpu_warn}}" max="100" id="cpu_val2" ng-model="cpu_danger"> - </div> - </div> - <h3>Drive</h3> - <div class="row"> - <div class="col-xs-2"> - <label for="drive_freq">Frequency check</label> - <input type="text" class="form-control" id="drive_freq" placeholder="d:hh:mm"> - </div> - <div class="col-xs-4"> - <label for="drive_val1">Minor notification at {{drive_warn}}% of charge</label> - <input type="range" name="cpu_warn" min="0" max="99" id="drive_val1" ng-model="drive_warn"> - </div> - <div class="col-xs-4"> - <label for="drive_val2">Major notification at {{drive_danger}}% of charge</label> - <input type="range" name="drive_danger" min="{{drive_warn}}" max="100" id="drive_val2" ng-model="drive_danger"> - </div> - </div> - </div> - </div> - </div> - <div class="panel panel-default"> - <div class="panel-heading" role="tab" id="headingTwo"> - <h4 class="panel-title"> - <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="true" aria-controls="collapseTwo"> - Network - </a> - </h4> - </div> - <div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo"> - <div class="panel-body"> - <h3>HTTP</h3> - <div class="row"> - <div class="col-xs-2"> - <label for="http_freq">Frequency check</label> - <input type="text" class="form-control" id="http_freq" placeholder="d:hh:mm"> - </div> - <div class="col-xs-3"> - <label for="http_crit_1">If down, send a </label> - <div class="radio"> - <label> - <input type="radio" name="http_crit" id="http_crit_1" value="warning" checked> - minor notification - </label> - </div> - <div class="radio"> - <label> - <input type="radio" name="http_crit" id="http_crit_2" value="danger"> - major notification - </label> - </div> - </div> - </div> + {{settings}} + <accordion close-others="false"> + <accordion-group heading="{{block}}" ng-repeat="block in all_blocks()"> + <div class="row" ng-repeat="(modname, mod) in settings" + ng-show="mod.block == block"> + <a ng-click="open_modal_global_conf(modname)">{{modname}}</a> + </div> + </accordion-group> + </accordion> + </div> - <h3>SMTP</h3> - <div class="row"> - <div class="col-xs-2"> - <label for="smtp_freq">Frequency check</label> - <input type="text" class="form-control" id="smtp_freq" placeholder="d:hh:mm"> - </div> - <div class="col-xs-3"> - <label for="smtp_crit_1">If down, send a </label> - <div class="radio"> - <label> - <input type="radio" name="smtp_crit" id="smtp_crit_1" value="warning" checked> - minor notification - </label> - </div> - <div class="radio"> - <label> - <input type="radio" name="smtp_crit" id="smtp_crit_2" value="danger"> - major notification - </label> - </div> - </div> - </div> + <script type="text/ng-template" id="modal_global_conf_label.html"> + <div class="modal-header"> + <h3 class="modal-title">Configure {{global_conf_args.mod_name}}</h3> + </div> + <div class="modal-body"> + <form> + <div class="form-group"> + <p>The parameters here will be automatically applied for each host you will add in the future.</p> + <label for="freq">Frequency check: each</label> + <div class="row" id="freq"> + <div class="col-xs-2"> + <input type="number" min="0" class="form-control" + ng-model="freq_days"> days + </div> + <div class="col-xs-2"> + <input type="number" min="0" max="23" class="form-control" + ng-model="freq_hours"> hours + </div> + <div class="col-xs-2"> + <input type="number" min="0" max="59" class="form-control" + ng-model="freq_minutes"> minutes </div> - - </div> - </div> - - <div class="panel panel-default"> - <div class="panel-heading" role="tab" id="headingThree"> - <h4 class="panel-title"> - <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="true" aria-controls="collapseThree"> - Software - </a> - </h4> + <div ng-show="global_conf_args.conf_mod.unit == '%'"> + <label for="minor_%">Minor notification at {{minor_limit_percent}}% of charge</label> + <input type="range" min="0" max="99" id="minor_%" + ng-model="minor_limit_percent"> + <label for="major_%">Major notification at {{major_limit_percent}}% of charge</label> + <input type="range" min="{{minor_limit_percent}}" max="100" id="major_%" + ng-model="major_limit_percent"> </div> - <div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree"> - <div class="panel-body"> - <h3>Packages updated</h3> - <div class="row"> - <div class="col-xs-2"> - <label for="pack_freq">Frequency check</label> - <input type="text" class="form-control" id="pack_freq" placeholder="d:hh:mm"> - </div> - <div class="col-xs-4"> - <label for="min_pack">Minor notif at (non updated)</label> - <input type="number" class="form-control" id="min_pack" min="0" placeholder="5"> - </div> - <div class="col-xs-4"> - <label for="maj_pack">Major notif at (non updated)</label> - <input type="number" class="form-control" id="maj_pack" min="0" placeholder="20"> - </div> - </div> + <div ng-show="global_conf_args.conf_mod.unit == 'bool'"> + <label for="minor_bool">If down, send a </label> + <div class="radio"> + <label> + <input type="radio" id="minor_bool" value="minor" ng-model="limit_bool"> + minor notification + </label> + </div> + <div class="radio"> + <label> + <input type="radio" id="major_bool" value="major" ng-model="limit_bool"> + major notification + </label> </div> </div> + <div ng-show="global_conf_args.conf_mod.unit != '%' && global_conf_args.conf_mod.unit != 'bool'"> + <label for="minor_unit">Minor notif at {{minor_limit_unit}}</label> + <input type="number" class="form-control" id="minor_unit" min="0" + ng-model="minor_limit_unit"> + <label for="maj_pack">Major notif at {{major_limit_unit}}</label> + <input type="number" class="form-control" id="maj_pack" min="0" + ng-model="major_limit_unit"> + </div> </div> - </div> - <button type="button" class="btn btn-default">Discard changes</button> - <button type="button" class="btn btn-primary">Save changes</button> - </form> + </form> + </div> + <div class="modal-footer"> + <button type="button" class="btn btn-default" data-dismiss="modal" + ng-click="cancel()">Close</button> + <button type="button" class="btn btn-primary" ng-click="ok()">Save changes</button> + </div> - </div> \ No newline at end of file + </script> \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.