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 79ae47529d8fa6c2ea7b532395f8b0430a30e4ce Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Fri Jul 3 15:58:25 2015 +0200 migration struct on ml --- app/module_loader.py | 16 ++++++------- app/modules/monitoring_modules/process.py | 35 --------------------------- app/modules/storage_modules/shelve_db.py | 40 +++++++++++++++++++++++++++---- migration_rules.json | 8 +++++-- 4 files changed, 49 insertions(+), 50 deletions(-) diff --git a/app/module_loader.py b/app/module_loader.py index 4f4b2cb..90550f2 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -31,8 +31,8 @@ class ModuleLoader: self.conf = conf self.db = self.load_db() db_version = self.db.get_db_version() - if float(db_version) < mum_vesion: - self.migrate_db(db_version) + #if float(db_version) < mum_vesion: + # self.migrate_db(db_version) self.db.reset_tasks() self.loaded_mod_moni = {} # See load_all_monitoring_modules self.loaded_mod_detect = {} # See load_all_detection_modules @@ -60,7 +60,6 @@ class ModuleLoader: A backup of the previous database is also done. """ # backup creation - """ db_loc_tree = self.conf['db_location'].split('/') old_db_name = db_loc_tree[len(db_loc_tree) -1] db_loc_tree.pop(len(db_loc_tree) -1) @@ -71,12 +70,11 @@ class ModuleLoader: migration_rules = json.loads(migration_rules_file.read()) for version in migration_rules: if float(version) > current_db_version: - for add_instr in migration_rules[version]["add_field"]: - self.db.add_field(add_instr, migration_rules[version]["add_field"][add_instr]) - for rem_instr in migration_rules[version]["rem_field"]: - self.db.rem_field(rem_instr, migration_rules[version]["rem_field"][rem_instr]) - self.db.set_db_version(version) - """ + for new_val in migration_rules[version]["add_field"]: + self.db.add_field(new_val, migration_rules[version]["add_field"][new_val]) + for val_to_rem in migration_rules[version]["rem_field"]: + self.db.rem_field(val_to_rem, migration_rules[version]["rem_field"][val_to_rem]) + #self.db.set_db_version(version) return None def get_public_keys_loc(self): diff --git a/app/modules/monitoring_modules/process.py b/app/modules/monitoring_modules/process.py deleted file mode 100644 index ce092d4..0000000 --- a/app/modules/monitoring_modules/process.py +++ /dev/null @@ -1,35 +0,0 @@ -__author__ = 'aguilbaud' - -compatible_os = ['linux'] -block = "software" -part = "Process" -name = "Process SSH" -unit = "" -connection = "ssh" - -param = { - {"proc_name", {'type': 'string', 'value': '', 'doc': "The name of the process"}}, -} - -def check(conn, mnce, params): - cmd = "LANG=C ps -C " + params['proc_name'] + " -opid" - stdout = conn.exec_command(cmd) - - # output if process is running - """ - PID - 2993 - 2994 - 2995 - 2996 - 2997 - 2998 - """ - # output if process is not running - """ - PID - """ - - process_number_running = len(stdout.splitlines()) - 1 - - return process_number_running \ No newline at end of file diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index ea72a11..309b0c7 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -75,15 +75,46 @@ class shelve_db: self.logger.error(traceback.format_exc()) finally: self.close_db() - """ - def add_field(self, field, tab_loc): + def add_field(self, new_val_name, dict_instr): self.open_db() + path = dict_instr['path'] + new_val = dict_instr['new_val'] + path_tab = [] try: - for key in tab_loc: - if key == "*": + for i in range(len(path)): + if path[i] == '*': + + except Exception: + self.logger.error(traceback.format_exc()) + finally: + self.close_db() + + + def add_field_req(self, path_list, pos_path, path, field_to_add_name, field_to_add_val): + if pos_path < len(path): + current_key = str(path[pos_path]) + if current_key == '*': + print path + for key in self.get_nested_default(dict(self.db), path, None): + path[pos_path] = key + return self.add_field_req(path_list, pos_path + 1, path, field_to_add_name, field_to_add_val) + else: + return self.add_field_req(path_list, pos_path + 1, path, field_to_add_name, field_to_add_val) + else: + if pos_path == 0: + path_list.append('') + return path_list + else: + path_list.append(path) + return path_list """ + + @staticmethod + def get_nested_default(d, path, new_elem): + return reduce(lambda d, k: d.setdefault(k, new_elem), path, d) + def reset_tasks(self): self.open_db() try: @@ -460,6 +491,7 @@ class shelve_db: info_host['nb_subscribers'] = len(self.db['hosts'][host]['conf']['subscribers'].keys()) info_host['subscribers'] = self.db['hosts'][host]['conf']['subscribers'] info_host['display_name'] = self.db['hosts'][host]['conf']['display_name'] + info_host['nb_mod'] = len(self.db['hosts'][host]['monitoring'].keys()) res.append(info_host) except Exception: self.logger.error(traceback.format_exc()) diff --git a/migration_rules.json b/migration_rules.json index faac1bd..f398cfa 100644 --- a/migration_rules.json +++ b/migration_rules.json @@ -2,7 +2,11 @@ "0.2": { "add_field":{ - "test": ["hosts", "*"] - } + "test":{ + "path": ["hosts", "*"], + "new_val": {} + } + }, + "rem_field":{} } } \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.