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 926d024f06d07060fec949d4d039219b9b67cb44 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Mar 12 11:21:13 2015 +0100 OK pour connexion et lancement des modules avec cette connexion --- app/app.py | 2 +- app/module_loader.py | 18 ++++++++++++++---- app/modules/connection_modules/ssh.py | 11 ++++++++--- app/modules/monitoring_modules/disk.py | 2 +- app/modules/storage_modules/shelve_db.py | 19 +++++++++++-------- 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/app/app.py b/app/app.py index 3057687..f712f68 100755 --- a/app/app.py +++ b/app/app.py @@ -171,6 +171,6 @@ if __name__ == '__main__': ml.load_all_monitoring_modules() ml.load_all_connection_modules() wsc = WebSocketContainer(ml.get_db()) - #process_monitoring.init(ml, wsc) + process_monitoring.init(ml, wsc) port = int(os.environ.get('PORT', 1337)) run(host='0.0.0.0', port=port, debug=True, server=GeventWebSocketServer) \ No newline at end of file diff --git a/app/module_loader.py b/app/module_loader.py index 49eb291..10da678 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -31,18 +31,18 @@ class ModuleLoader: self.db_loc = dict_conf['db_location'] self.external_mod_loc = dict_conf['external_modules_location'] self.public_keys_loc = dict_conf['public_keys_location'] - self.db = self.load_db(add_func, rem_func) + self.db = self.load_db(add_func, rem_func, self.public_keys_loc) self.loaded_mod_moni = {} # See load_all_monitoring_modules self.loaded_mod_conn = {} # See load_all_connection_modules - def load_db(self, add_func, rem_func): + def load_db(self, add_func, rem_func, key_loc): """ Creates an instance of the class shelve_db from storage_modules. :return: an instance of the shelve_db class """ db_name = "shelve_db" db = __import__("modules.storage_modules." + db_name, fromlist=modules.storage_modules) - db_instance = getattr(db, db_name)(self.db_loc, add_func, rem_func) + db_instance = getattr(db, db_name)(self.db_loc, add_func, rem_func, key_loc) return db_instance def get_db(self): @@ -73,6 +73,15 @@ class ModuleLoader: def create_connection(self, addr_host): avaliable_conn = self.db.get_conf_conn(addr_host) + mod_inst = None + if not avaliable_conn == []: + conn = avaliable_conn.pop() + mod_inst = getattr(self.loaded_mod_conn[conn['conn_mod_name']]['imported'], + self.loaded_mod_conn[conn['conn_mod_name']]['class_name'])(addr_host, + conn['args'], + self.public_keys_loc, + modules.CommandNotFoundException) + return mod_inst def run_all_detection_modules(self, os, conn, db, ws): """ @@ -155,6 +164,7 @@ class ModuleLoader: self.loaded_mod_moni[mod_name]['class_name'])(db, addr_host) mod_inst.check() else: + conn = self.create_connection(addr_host) mod_inst = getattr(self.loaded_mod_moni[mod_name]['imported'], self.loaded_mod_moni[mod_name]['class_name'])(conn, db, modules.ModuleNotCompatibleException) @@ -215,7 +225,7 @@ class ModuleLoader: try: loaded_mod = __import__("modules.connection_modules." + mod_name, fromlist=[mod_name]) class_name = getattr(loaded_mod, "get_class_name")() - mod_inst = getattr(loaded_mod, class_name)(None, None, None) + mod_inst = getattr(loaded_mod, class_name)(None, None, None, None) infos_mod = {} infos_mod['imported'] = loaded_mod infos_mod['class_name'] = getattr(mod_inst, 'get_name')() diff --git a/app/modules/connection_modules/ssh.py b/app/modules/connection_modules/ssh.py index b407dc8..8806756 100644 --- a/app/modules/connection_modules/ssh.py +++ b/app/modules/connection_modules/ssh.py @@ -6,16 +6,21 @@ def get_class_name(): class SSH: - def __init__(self, addr_host, params, cnfe): + def __init__(self, addr_host, params, key_loc, cnfe): self.parameters = {"username": "string", "public_key": "file", "port": "int"} self.name = get_class_name() self.addr_host = addr_host self.CommandNotFoundException = cnfe if params is not None: - key = paramiko.RSAKey.from_private_key_file(params['public_key']) + key_path = str(key_loc) + str(params['public_key']) + print key_path + key = paramiko.RSAKey.from_private_key_file(key_path) self.ssh = paramiko.SSHClient() self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - self.ssh.connect(addr_host, username=params['username'], pkey=key, port=params['port']) + self.ssh.connect(addr_host, + username=params['username'], + pkey=key, + port=params['port']) def get_name(self): return self.name diff --git a/app/modules/monitoring_modules/disk.py b/app/modules/monitoring_modules/disk.py index 33ceec1..15c734c 100644 --- a/app/modules/monitoring_modules/disk.py +++ b/app/modules/monitoring_modules/disk.py @@ -51,4 +51,4 @@ class Disk: ) raise exception_inst res_check = int(disk_used) - self.db.add_check(self.conn.get_addr_host(), self.name, res_check) \ No newline at end of file + self.db.add_check(self.conn.get_addr_host(), 'disk', res_check) \ 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 1757bc1..ce7bf7a 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -13,11 +13,12 @@ class shelve_db: Storage module for the persistant objects in Python : Shelve. Every function in need to access the database have to be moved in this class. """ - def __init__(self, db_loc, add_func, rem_func): + def __init__(self, db_loc, add_func, rem_func, key_loc): self.db = None self.db_loc = db_loc self.add_to_monitoring_list = add_func self.rem_to_monitoring_list = rem_func + self.key_loc = key_loc def open_db(self): """ @@ -596,12 +597,12 @@ class shelve_db: args['current_config']['ssh'][param] finally: self.close_db() - """ + def get_conf_conn(self, addr_host): ''' Get the configured connections by priority of a host. :param addr_host: The IP address of the host. - :return: A list containing): + :return: A list containing: [{'conn_mod_name': val, 'priority': val, 'args': {arg1: val, ...}}] ''' res = [] @@ -612,10 +613,12 @@ class shelve_db: dict_conn = {} dict_conn['conn_mod_name'] = conn dict_conn['priority'] = self.db['hosts'][addr_host]['conf']['connections'][conn]['priority'] - dict_conn['args'] = + dict_conn['args'] = self.db['hosts'][addr_host]['conf']['connections'][conn] + res.append(dict_conn) finally: self.close_db() - """ + return res + def add_check(self, addr_host, mod_name, val): """ Called by a monitoring module. @@ -628,6 +631,9 @@ class shelve_db: self.open_db() new_val = {"date": str(datetime.now()), "value" : val} try: + if mod_name not in self.db['hosts'][addr_host]["monitoring"]: + # creating the monitoring structure for this module if not exists + self.db['hosts'][addr_host]["monitoring"][mod_name] = {} if type(val) == type(True): # if boolean if self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['minor_limit'] and not val: @@ -648,9 +654,6 @@ class shelve_db: new_val['state'] = 'danger' else: new_val['state'] = 'success' - if mod_name not in self.db['hosts'][addr_host]["monitoring"]: - # creating the monitoring structure for this module if not exists - self.db['hosts'][addr_host]["monitoring"][mod_name] = {} previous_val = self.db['hosts'][addr_host]["monitoring"][mod_name] self.db['hosts'][addr_host]['monitoring'][mod_name] = new_val # updating the global state of the host -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.