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 159f40f0e12016c1e799f4dc3d21dd2b03367485 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Jul 8 16:47:50 2015 +0200 param attribute loaded from modules; string and int values can be configured on hostpage. --- app/module_loader.py | 138 ++++++++++++++++++------------- app/modules/monitoring_modules/ping.py | 6 +- app/modules/storage_modules/shelve_db.py | 7 +- static/js/controllers/hostPageCtrl.js | 27 +++++- views/hostpage.html | 29 +++++-- 5 files changed, 137 insertions(+), 70 deletions(-) diff --git a/app/module_loader.py b/app/module_loader.py index e6b0234..797f494 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -296,6 +296,14 @@ class ModuleLoader: self.loaded_mod_moni[part]['compatible_conn'].append(getattr(loaded_mod, 'connection')) self.loaded_mod_moni[part]['compatible_conn'] = \ list(set(self.loaded_mod_moni[part]['compatible_conn'])) + try: + self.loaded_mod_moni[part]['param'] = getattr(loaded_mod, 'param') + except AttributeError: + self.loaded_mod_moni[part]['param'] = {} + try: + self.loaded_mod_moni[part]['default'] = getattr(loaded_mod, 'default') + except AttributeError: + self.loaded_mod_moni[part]['default'] = {} except AttributeError: self.logger.warning("Error : internal monitoring module " + mod_name + " could not have been loaded.") self.logger.debug(traceback.format_exc()) @@ -343,65 +351,75 @@ class ModuleLoader: :param part_name: the name of the part to check :param addr_host: the IP address of the host """ - if part_name in self.loaded_mod_moni[part_name]['modules'] and \ - getattr(self.loaded_mod_moni[part_name]['modules'][part_name]['imported'], 'connection') == "": - # the module which check this part doesn't need a connection - port_list = self.db.get_nmap_result(addr_host)['openports'] - try: - res_check = getattr(self.loaded_mod_moni[part_name]['modules'][part_name]['imported'], - 'check')(addr_host, - port_list, - modules.CommandNotFoundException) - dict_notif = self.db.add_check(addr_host, part_name, res_check) - self.run_notification_modules(dict_notif) - except modules.CommandNotFoundException.CommandNotFoundException: - msg = "No port " + part_name + " on " + addr_host + ". This part checking have been deactivated." - self.logger.warning(msg) - self.wsc.notify_module_deactivation(msg) - process_monitoring.remove_to_waiting_list(addr_host, part_name) - dict_deactivation_request = {} - dict_deactivation_request['addr_host'] = addr_host - dict_deactivation_request['activated'] = {part_name: False} - self.db.config_mod_activation(dict_deactivation_request) - else: - # to check this part, it is necessary to create a connection with the host... - # getting all availiable connections for this part to check - conf_conn = self.db.get_conf_conn(addr_host) - check_done = False - i = 0 - while i < len(conf_conn) and not check_done: - # for each connection that have been configurated for this host (by priority) - for mod in self.loaded_mod_moni[part_name]['modules']: - # for each monitoring module, being from this part, activated for this host - loaded_mod = self.loaded_mod_moni[part_name]['modules'][mod]['imported'] - if getattr(loaded_mod, 'connection') == conf_conn[i]['conn_mod_name']: - subpart_list = self.db.get_subpart(addr_host, part_name) - # if this monitoring module is compatible for the current connection - try: - conn_inst = self.create_connection(addr_host, conf_conn[i]) - res_check = getattr(loaded_mod, - 'check')(conn_inst, - modules.ModuleNotCompatibleException, - subpart_list) - dict_notif = self.db.add_check(conn_inst.get_addr_host(), part_name, res_check) - self.run_notification_modules(dict_notif) - check_done = True - except Exception: - self.logger.warning("The connection could not have been established with " + conf_conn[i]['conn_mod_name']\ - + " on " + addr_host) - self.logger.debug(traceback.format_exc()) - self.logger.warning("Now trying on next avaliable connection...") - i += 1 - if not check_done: - msg = "No necessary connection have been properly configured for " + part_name + " on " + addr_host + \ - ". Therefore it has been deactivated." - self.logger.warning(msg) - self.wsc.notify_module_deactivation(msg) - process_monitoring.remove_to_waiting_list(addr_host, part_name) - dict_deactivation_request = {} - dict_deactivation_request['addr_host'] = addr_host - dict_deactivation_request['activated'] = {part_name: False} - self.db.config_mod_activation(dict_deactivation_request) + try: + if part_name in self.loaded_mod_moni[part_name]['modules'] and \ + getattr(self.loaded_mod_moni[part_name]['modules'][part_name]['imported'], 'connection') == "": + # the module which check this part doesn't need a connection + port_list = self.db.get_nmap_result(addr_host)['openports'] + try: + res_check = getattr(self.loaded_mod_moni[part_name]['modules'][part_name]['imported'], + 'check')(addr_host, + port_list, + modules.CommandNotFoundException) + dict_notif = self.db.add_check(addr_host, part_name, res_check) + self.run_notification_modules(dict_notif) + except modules.CommandNotFoundException.CommandNotFoundException: + msg = "No port " + part_name + " on " + addr_host + ". This part checking have been deactivated." + self.logger.warning(msg) + self.wsc.notify_module_deactivation(msg) + process_monitoring.remove_to_waiting_list(addr_host, part_name) + dict_deactivation_request = {} + dict_deactivation_request['addr_host'] = addr_host + dict_deactivation_request['activated'] = {part_name: False} + self.db.config_mod_activation(dict_deactivation_request) + else: + # to check this part, it is necessary to create a connection with the host... + # getting all availiable connections for this part to check + conf_conn = self.db.get_conf_conn(addr_host) + check_done = False + i = 0 + while i < len(conf_conn) and not check_done: + # for each connection that have been configurated for this host (by priority) + for mod in self.loaded_mod_moni[part_name]['modules']: + # for each monitoring module, being from this part, activated for this host + loaded_mod = self.loaded_mod_moni[part_name]['modules'][mod]['imported'] + if getattr(loaded_mod, 'connection') == conf_conn[i]['conn_mod_name']: + subpart_list = self.db.get_subpart(addr_host, part_name) + # if this monitoring module is compatible for the current connection + try: + conn_inst = self.create_connection(addr_host, conf_conn[i]) + res_check = getattr(loaded_mod, + 'check')(conn_inst, + modules.ModuleNotCompatibleException, + subpart_list) + dict_notif = self.db.add_check(conn_inst.get_addr_host(), part_name, res_check) + self.run_notification_modules(dict_notif) + check_done = True + except Exception: + self.logger.warning("The connection could not have been established with " + conf_conn[i]['conn_mod_name']\ + + " on " + addr_host) + self.logger.debug(traceback.format_exc()) + self.logger.warning("Now trying on next avaliable connection...") + i += 1 + if not check_done: + msg = "No necessary connection have been properly configured for " + part_name + " on " + addr_host + \ + ". Therefore it has been deactivated." + self.logger.warning(msg) + self.wsc.notify_module_deactivation(msg) + process_monitoring.remove_to_waiting_list(addr_host, part_name) + dict_deactivation_request = {} + dict_deactivation_request['addr_host'] = addr_host + dict_deactivation_request['activated'] = {part_name: False} + self.db.config_mod_activation(dict_deactivation_request) + except KeyError: + msg = "The module " + part_name + " has not been loaded. Desactivation for " + addr_host + self.logger.warning(msg) + self.wsc.notify_module_deactivation(msg) + process_monitoring.remove_to_waiting_list(addr_host, part_name) + dict_deactivation_request = {} + dict_deactivation_request['addr_host'] = addr_host + dict_deactivation_request['activated'] = {part_name: False} + self.db.config_mod_activation(dict_deactivation_request) def get_monitoring_modules_list(self): """ @@ -442,6 +460,8 @@ class ModuleLoader: res[part] = {} res[part]['compatible_os'] = self.loaded_mod_moni[part]['compatible_os'] res[part]['compatible_conn'] = self.loaded_mod_moni[part]['compatible_conn'] + res[part]['default'] = self.loaded_mod_moni[part]['default'] + res[part]['param'] = self.loaded_mod_moni[part]['param'] mod_sample = self.loaded_mod_moni[part]['modules'].keys()[0] loaded_mod_sample = self.loaded_mod_moni[part]['modules'][mod_sample]['imported'] res[part]['unit'] = getattr(loaded_mod_sample, 'unit') diff --git a/app/modules/monitoring_modules/ping.py b/app/modules/monitoring_modules/ping.py index f00d625..a21d714 100644 --- a/app/modules/monitoring_modules/ping.py +++ b/app/modules/monitoring_modules/ping.py @@ -20,7 +20,6 @@ __author__ = 'aguilbaud' import pexpect - compatible_os = ["all"] block = "network" part = "Ping" @@ -28,11 +27,14 @@ name = part unit = "bool" connection = "" +default = { + "check_frequency": 420 +} def check(addr_host, port_list, cnfe): res_check = False try: - child = pexpect.spawn('ping '+ addr_host + ' -c 1') + child = pexpect.spawn('ping ' + addr_host + ' -c 1', env={'LANG': 'C'}) while child.isalive(): child.expect('packets transmitted, ') child.expect(' received') diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index 8d2e75b..43cb394 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -187,8 +187,8 @@ class shelve_db: else: mod_conf['minor_limit'] = 8 mod_conf['major_limit'] = 10 - if 'param' in loaded_mod_moni: - mod_conf['param'] = loaded_mod_moni['param'] + if 'param' in loaded_mod_moni[mod]: + mod_conf['param'] = loaded_mod_moni[mod]['param'] mod_conf['subscribers'] = {} self.db['global_conf'][mod] = mod_conf # removing entries of modules that are no loaded anymore @@ -851,6 +851,8 @@ class shelve_db: res['freq'] = self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['check_frequency'] for period in ['min', 'hour', 'day', 'week', 'month', 'year']: res['nb_' + period] = self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['nb_' + period] + if 'param' in self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]: + res['param'] = self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['param'] except Exception: self.logger.error(traceback.format_exc()) finally: @@ -881,6 +883,7 @@ class shelve_db: self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['nb_' + period] = None else: self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['nb_' + period] = args['nb_' + period] + self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['param'] = args['param'] except Exception: self.logger.error(traceback.format_exc()) finally: diff --git a/static/js/controllers/hostPageCtrl.js b/static/js/controllers/hostPageCtrl.js index 295dfb9..ca2a81e 100644 --- a/static/js/controllers/hostPageCtrl.js +++ b/static/js/controllers/hostPageCtrl.js @@ -386,14 +386,20 @@ mumApp.controller('ModalConfInstanceCtrl', function ($scope, $rootScope, $modalI $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'get_conf_mod', 'args': conf_args}})); - $scope.items = {} /* { + $scope.items = {}; /* { 'unit' : val, // the unit of the value 'minor_limit' : val, 'major_limit' : val, - 'freq' : val + 'freq' : val, + 'param': {param_name: + {'type': str, 'doc': str, 'value': val}, + ... + } } */ + $scope.param_struct = {}; + // init fields $scope.freq_days = 0; $scope.freq_hours = 0; @@ -442,10 +448,25 @@ mumApp.controller('ModalConfInstanceCtrl', function ($scope, $rootScope, $modalI $scope.arch_week = args.res.nb_week; $scope.arch_month = args.res.nb_month; $scope.arch_year = args.res.nb_year; + update_param_struct(); }, 0); } }); + var update_param_struct = function (){ + /* + Formats the custom parameters to have the type as a key. Permits to generate the form with ng-repeat. + */ + for (var param_name in $scope.items.param){ + var dict_param = $scope.items.param[param_name]; + dict_param.param_name = param_name; + if (!$scope.param_struct.hasOwnProperty(dict_param.type)){ + $scope.param_struct[dict_param.type] = []; + } + $scope.param_struct[dict_param.type].push(dict_param); + } + }; + // after validation $scope.ok = function () { var args = {}; @@ -471,6 +492,8 @@ mumApp.controller('ModalConfInstanceCtrl', function ($scope, $rootScope, $modalI args.nb_month = $scope.arch_month; args.nb_year = $scope.arch_year; + args.param = $scope.items.param; + $rootScope.$broadcast("sendViaWs", JSON.stringify({"SET_CONF_MOD": args})); $modalInstance.close(); diff --git a/views/hostpage.html b/views/hostpage.html index b67b034..eb49af9 100644 --- a/views/hostpage.html +++ b/views/hostpage.html @@ -278,7 +278,8 @@ </div> <div class="modal-body"> - + {{items}}<br/><br/><br/> + {{param_struct}} <form> <div class="form-group"> <label for="arch">Archives to keep (in check numbers). Keep empty for no limit.</label> @@ -381,6 +382,24 @@ </div> </form> + <h3>Custom parameters</h3> + + <div class="row" + ng-repeat="dict_param in param_struct.string"> + <p>{{items.param[dict_param.param_name].doc}}</p> + <div class="col-xs-3"> + <input type="text" ng-model="items.param[dict_param.param_name].value"/> + </div> + </div> + + <div class="row" + ng-repeat="dict_param in param_struct.int"> + <p>{{items.param[dict_param.param_name].doc}}</p> + <div class="col-xs-3"> + <input type="number" ng-model="items.param[dict_param.param_name].value"/> + </div> + </div> + </div> <div class="modal-footer"> @@ -475,7 +494,7 @@ Upload a new key: <span ng-bind="item.file.name"></span><br/> <button ng-click="item.upload(item, '\keys')">upload</button> </li> - </ul>--> + </ul> <div class="row"> <input type="radio" value="login"> Login/Password @@ -500,9 +519,9 @@ ng-model="private_key" ng-options="key as key for key in keys_list"></select> </div> - </div> + </div>--> + - <!-- <div class="row" ng-show="show_form('private_key')"> <div class="col-xs-3"> <label for="private_key">Select a private key</label> @@ -548,7 +567,7 @@ <label for="domain">Domain</label> <input type="text" id="domain" ng-model="username"/> </div> - </div>--> + </div> </div> <div class="modal-footer"> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.