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 b3798b16db5760adf26a21f849325c2345ec0a4e Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Feb 23 13:48:12 2015 +0100 exception messages error are sent by websocket if available --- app/app.py | 3 +-- app/module_loader.py | 24 ++++++++++++++++++++---- app/modules/connection_modules/ssh.py | 6 +++--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/app.py b/app/app.py index 522f56d..33fbdbd 100755 --- a/app/app.py +++ b/app/app.py @@ -39,7 +39,7 @@ class ThreadDetect(threading.Thread): # now launching full detection for ip in json.loads(scanned_ip): conn = module_loader.load_conn("ssh", ip, "aguilbaud", "/home/aguilbaud/.ssh/id_rsa") - module_loader.run_all_detection_modules(db.get_host_os(ip), conn, db) + module_loader.run_all_detection_modules(db.get_host_os(ip), conn, db, self.ws) @route('/') @@ -134,7 +134,6 @@ def receive(ws): break - # Lancement du serveur a l'adresse 0.0.0.0:1337 if __name__ == '__main__': port = int(os.environ.get('PORT', 1337)) diff --git a/app/module_loader.py b/app/module_loader.py index a782900..71f0268 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -7,6 +7,8 @@ import modules.storage_modules import modules.ModuleNotCompatibleException as moduleNotCompatibleException import modules.CommandNotFoundException as commandNotFoundException +import json + """ Loads dynamically modules from packages connection_modules, detection_modules, monitoring_modules, storage_modules. """ @@ -48,13 +50,14 @@ def load_conn(conn_name, addr_host, username, key_location): # /home/aguilbau return conn_instance -def run_all_detection_modules(os, conn, db): +def run_all_detection_modules(os, conn, db, ws): """ Instanciates and runs every detection_modules listed in the __init__.py file of the package corresponding to the operating system entered in parameters. :param os: the oprating system of the host :param conn: an instance of a connection module :param db: an instance of a storage module + :param ws: a websocket connection if the function have been called from a client. Is None otherwise """ __import__("modules.detection_modules." + os) pack_mod_os = __import__("modules.detection_modules." + os, fromlist=modules.detection_modules.__all__) @@ -65,18 +68,22 @@ def run_all_detection_modules(os, conn, db): mod_instance.run_detection() except commandNotFoundException as cnfe: print cnfe.__str__ + if ws is not None: + ws.send(json.dumps({"40": cnfe.__str__})) + -def run_all_monitoring_modules(os, conn, db): +def run_all_monitoring_modules(os, conn, db, ws): """ Instanciates and runs every monitoring_modules listed in the __init__.py file of the package corresponding to the operating system entered in parameters. :param os: the oprating system of the host :param conn: an instance of a connection module :param db: an instance of a storage module + :param ws: a websocket connection if the function have been called from a client. Is None otherwise """ __import__("modules.monitoring_modules." + os) - pack_mod_os = __import__("modules.monitoring_modules." + os, fromlist=modules.monitoring_modules.__all__) + pack_mod_os = __import__("modules.monitoring_modules." + os, fromlist=modules.monitoring_modules.__all__) for mod_name in pack_mod_os.__all__: mod = __import__ ("modules.monitoring_modules." + os + "." + mod_name, fromlist=modules.monitoring_modules.unix.__all__) # on charge le module mod_instance = getattr(mod, mod_name)(conn, db, moduleNotCompatibleException) # on appelle le constructeur @@ -84,11 +91,15 @@ def run_all_monitoring_modules(os, conn, db): mod_instance.check() except moduleNotCompatibleException as mnce: print mnce.__str__ + if ws is not None: + ws.send(json.dumps({"40": mnce.__str__})) except commandNotFoundException as cnfe: print cnfe.__str__ + if ws is not None: + ws.send(json.dumps({"40": cnfe.__str__})) -def run_one_monitoring_module(mod_name, os, conn, db): +def run_one_monitoring_module(mod_name, os, conn, db, ws): """ Instanciates and runs one monitoring_module of the package corresponding to the operating system entered in parameters. @@ -96,6 +107,7 @@ def run_one_monitoring_module(mod_name, os, conn, db): :param os: the oprating system of the host :param conn: an instance of a connection module :param db: an instance of a storage module + :param ws: a websocket connection if the function have been called from a client. Is None otherwise """ __import__("modules.monitoring_modules." + os) mod = __import__("modules.monitoring_modules." + os + "." + mod_name, fromlist=modules.monitoring_modules.unix.__all__) @@ -104,8 +116,12 @@ def run_one_monitoring_module(mod_name, os, conn, db): mod_instance.check() except moduleNotCompatibleException as mnce: print mnce.__str__ + if ws is not None: + ws.send(json.dumps({"40": mnce.__str__})) except commandNotFoundException as cnfe: print cnfe.__str__ + if ws is not None: + ws.send(json.dumps({"40": cnfe.__str__})) def get_info_mod_monitoring(os): diff --git a/app/modules/connection_modules/ssh.py b/app/modules/connection_modules/ssh.py index 7eaee28..74786cb 100644 --- a/app/modules/connection_modules/ssh.py +++ b/app/modules/connection_modules/ssh.py @@ -16,14 +16,14 @@ class ssh: def exec_command(self, cmd): stdin, stdout, stderr = self.ssh.exec_command(cmd) - res = stdout.read() + out = stdout.read() err = stderr.read() - if not err == "" and res == "": + if not err == "" and out == "": exception_inst = getattr(self.CommandNotFoundException, "CommandNotFoundException")( cmd, self.addr_host ) raise exception_inst - return res + return out def disconnect(self): self.ssh.close() \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.