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 e90937d482b0f16f55e538c52eddc1dd8dcaaf1a Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Apr 1 16:00:43 2015 +0200 champ 'global_conf' maintenant présent dans la bdd. le contenu est initialisé au lancement de l'appli selon les modules chargés --- app/modules/monitoring_modules/ping.py | 4 +- app/modules/storage_modules/shelve_db.py | 167 +++++++++++-------------------- app/mum.py | 1 + 3 files changed, 62 insertions(+), 110 deletions(-) diff --git a/app/modules/monitoring_modules/ping.py b/app/modules/monitoring_modules/ping.py index 6fbea01..053310f 100644 --- a/app/modules/monitoring_modules/ping.py +++ b/app/modules/monitoring_modules/ping.py @@ -3,8 +3,8 @@ __author__ = 'aguilbaud' import pexpect -compatible_os = [] -block = "" +compatible_os = ["all"] +block = "network" unit = "bool" diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index 42aac7a..710abbf 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -32,6 +32,7 @@ class shelve_db: self.db["hosts"] = {} self.db["users"] = {} self.db["groups"] = {} + self.db["global_conf"] = {} except: print "Database initilalization error" else: @@ -44,6 +45,59 @@ class shelve_db: self.db.close() self.db = None + def init_global_conf(self, loaded_mod_moni): + """ + This method is executed once at each launch of the application (see ModuleLoader constructor). + 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 : + { + mod_name: + { + 'class_name': string, => the name of the class to instanciate + 'compatible_os': [string1, string2, ...], => a list containing the compatibles os + 'unit': string, => the unit type of return ('%', 'bool' or other) + 'block': string, => the monitoring block of the module + 'external': bool => indicates if this modules comes from external directory + } + } + """ + self.open_db() + try: + for mod in loaded_mod_moni: + if mod not in self.db['global_conf']: # adding a entry for every module loaded for the first time + mod_conf = {} + mod_conf['block'] = loaded_mod_moni[mod]['block'] + mod_conf['activated'] = mod == 'ping' # we want the ping module to be activated by default + mod_conf['check_frequency'] = 60 + """ + mod_conf['nb_minute'] = 30 + mod_conf['nb_hour'] = 12 + mod_conf['nb_day'] = 15 + mod_conf['nb_week'] = 2 + mod_conf['nb_month'] = 6 + mod_conf['nb_year'] = None + """ + unit = loaded_mod_moni[mod]['unit'] + mod_conf['unit'] = unit + if unit == '%': + mod_conf['minor_limit'] = 95 + mod_conf['major_limit'] = 100 + elif unit == 'bool': + mod_conf['minor_limit'] = True + mod_conf['major_limit'] = False + else: + mod_conf['minor_limit'] = 8 + mod_conf['major_limit'] = 10 + self.db['global_conf'][mod] = mod_conf + for mod in self.db['global_conf']: # removing entries of modules that are non loaded anymore + if mod not in loaded_mod_moni: + del self.db['global_conf'][mod] + 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. @@ -68,9 +122,11 @@ class shelve_db: self.db["hosts"][addr_host]["conf"] = {} nmap_res_data = json.loads(nmap_res) self.db["hosts"][addr_host]["conf"]["connections"] = self.init_conn(nmap_res_data, list_mod_conn) - self.db["hosts"][addr_host]["conf"]["monitoring"] = self.generate_global_conf(dict_mod_info, - addr_host, - nmap_res_data['os']) + os_host = nmap_res_data['os'] + self.db["hosts"][addr_host]["conf"]["monitoring"] = {} + 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"]["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"] = "" @@ -110,111 +166,6 @@ class shelve_db: dict_conn[port["portname"]][param] = None return dict_conn - def generate_global_conf(self, dict_mod_info, addr_host, os_host): - """ - Configures automatically the monitoring for a host for each of the monitoring modules avaliable, in - function of the unit of the result of the monitoring module. - By default, only the ping monitoring is activated, while the connection is not configured and tje os not - detected - :param dict_mod_info: dictionary containing informations about all notification modules, in the form: - { - mod_name: - { - 'class_name': string, => the name of the class to instanciate - 'compatible_os': [string1, string2, ...], => a list containing the compatibles os - 'unit': string, => the unit type of return ('%', 'bool' or other) - 'block': string, => the monitoring block of the module - 'external': bool => indicates if this modules comes from external directory - } - } - :return a list containing the default parameters for each monitoring module (at least ping) - """ - res = {} - # creating the configuration for all modules compatibles - if not self.db["hosts"][addr_host]["conf"]["connections"] == {} and not os_host == 'unknown': - for mod in dict_mod_info: - if os_host in dict_mod_info[mod]['compatible_os']: - mod_conf = {} - mod_conf['block'] = dict_mod_info[mod]['block'] - mod_conf['activated'] = False - mod_conf['check_frequency'] = 60 - mod_conf['nb_minute'] = 30 - mod_conf['nb_hour'] = 12 - mod_conf['nb_day'] = 15 - mod_conf['nb_week'] = 2 - mod_conf['nb_month'] = 6 - mod_conf['nb_year'] = None - unit = dict_mod_info[mod]['unit'] - mod_conf['unit'] = unit - if unit == '%': - mod_conf['minor_limit'] = 80 - mod_conf['major_limit'] = 95 - elif unit == 'bool': - mod_conf['minor_limit'] = True - mod_conf['major_limit'] = False - else: - mod_conf['minor_limit'] = 8 - mod_conf['major_limit'] = 10 - res[mod] = mod_conf - # configure for ping monitoring in any case - ping_conf = {} - ping_conf['block'] = 'network' - ping_conf['activated'] = True - ping_conf['check_frequency'] = 60 - ping_conf['nb_minute'] = 30 - ping_conf['nb_hour'] = 12 - ping_conf['nb_day'] = 15 - ping_conf['nb_week'] = 2 - ping_conf['nb_month'] = 6 - ping_conf['nb_year'] = None - ping_conf['unit'] = 'bool' - ping_conf['minor_limit'] = False - ping_conf['major_limit'] = True - res['ping'] = ping_conf - return res - - def generate_unique_conf(self, dict_mod_info, addr_host, mod_name, activated): - """ - Configures automatically the monitoring for a host for each of the monitoring modules avaliable, in - function of the unit of the result of the monitoring module. - By default, only the ping monitoring is activated, while the connection is not configured and tje os not - detected - :param dict_mod_info: dictionary containing informations about all notification modules, in the form: - { - mod_name: - { - 'class_name': string, => the name of the class to instanciate - 'compatible_os': [string1, string2, ...], => a list containing the compatibles os - 'unit': string, => the unit type of return ('%', 'bool' or other) - 'block': string, => the monitoring block of the module - 'external': bool => indicates if this modules comes from external directory - } - } - :return a list containing the default parameters for each monitoring module (at least ping) - """ - mod_conf = {} - mod_conf['block'] = dict_mod_info[mod_name]['block'] - mod_conf['activated'] = activated - mod_conf['check_frequency'] = 60 - mod_conf['nb_minute'] = 30 - mod_conf['nb_hour'] = 12 - mod_conf['nb_day'] = 15 - mod_conf['nb_week'] = 2 - mod_conf['nb_month'] = 6 - mod_conf['nb_year'] = None - unit = dict_mod_info[mod_name]['unit'] - mod_conf['unit'] = unit - if unit == '%': - mod_conf['minor_limit'] = 95 - mod_conf['major_limit'] = 100 - elif unit == 'bool': - mod_conf['minor_limit'] = True - mod_conf['major_limit'] = False - else: - mod_conf['minor_limit'] = 8 - mod_conf['major_limit'] = 10 - self.db["hosts"][addr_host]["conf"]["monitoring"][mod_name] = mod_conf - def get_conn_param(self, args): """ Returns the connection parameters of an host. diff --git a/app/mum.py b/app/mum.py index eaf1e25..fee7382 100755 --- a/app/mum.py +++ b/app/mum.py @@ -224,6 +224,7 @@ if __name__ == '__main__': ml.load_all_connection_modules() ml.load_all_detection_modules() ml.load_all_notification_modules() + ml.get_db().init_global_conf(ml.get_monitoring_modules_list()) wsc = WebSocketContainer(ml.get_db()) #dict_notif = ml.db.add_check('127.0.0.1', "ping", False) #ml.run_notification_modules(dict_notif) -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.