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 5db3e57ddb62f176b5c5bc9734ec8009f4d2740f Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Mar 12 14:38:20 2015 +0100 les modules de détection sont chargés de la même manière que les autres --- app/app.py | 1 + app/module_loader.py | 73 ++++++++++++++-------- app/modules/detection_modules/__init__.py | 3 +- .../{unix => }/drive_detection.py | 22 +++++-- .../{unix => }/kernel_detection.py | 15 ++++- .../detection_modules/{unix => }/os_detection.py | 14 ++++- app/modules/detection_modules/unix/__init__.py | 2 - .../detection_modules/unix/cpu_detection.py | 18 ------ .../detection_modules/unix/network_detection.py | 18 ------ app/process_monitoring.py | 3 +- static/js/controllers/hostPageCtrl.js | 4 +- 11 files changed, 95 insertions(+), 78 deletions(-) diff --git a/app/app.py b/app/app.py index 3057687..c37b3c5 100755 --- a/app/app.py +++ b/app/app.py @@ -170,6 +170,7 @@ if __name__ == '__main__': ml = ModuleLoader(process_monitoring.add_to_waiting_list, process_monitoring.remove_to_waiting_list) ml.load_all_monitoring_modules() ml.load_all_connection_modules() + ml.load_all_detection_modules() wsc = WebSocketContainer(ml.get_db()) #process_monitoring.init(ml, wsc) port = int(os.environ.get('PORT', 1337)) diff --git a/app/module_loader.py b/app/module_loader.py index 10da678..3eca78e 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -33,6 +33,7 @@ class ModuleLoader: self.public_keys_loc = dict_conf['public_keys_location'] 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_detect = {} # See load_all_detection_modules self.loaded_mod_conn = {} # See load_all_connection_modules def load_db(self, add_func, rem_func, key_loc): @@ -83,26 +84,43 @@ class ModuleLoader: modules.CommandNotFoundException) return mod_inst - def run_all_detection_modules(self, os, conn, db, ws): + def load_all_detection_modules(self): """ - 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 + Instanciates and stores the informations about each monitoring modules avaliable on the loaded_mod_detect attribute + """ + for importer, mod_name, ispkg in pkgutil.iter_modules(["app/modules/detection_modules/"]): + print mod_name + if mod_name not in sys.modules and not mod_name == 'nmap_detection': + try: + loaded_mod = __import__("modules.detection_modules." + mod_name, fromlist=[mod_name]) + class_name = getattr(loaded_mod, "get_class_name")() + mod_inst = getattr(loaded_mod, class_name)(None, None) + infos_mod = {} + infos_mod['imported'] = loaded_mod + infos_mod['class_name'] = getattr(mod_inst, 'get_name')() + infos_mod['compatible_os'] = getattr(mod_inst, 'get_compatible_os')() + self.loaded_mod_detect[mod_name] = infos_mod + except AttributeError: + print "Error : internal detection module " + mod_name + " could not have been loaded. " + print self.loaded_mod_detect + + def run_all_detection_modules(self, addr_host): """ - __import__("modules.detection_modules." + os) - pack_mod_os = __import__("modules.detection_modules." + os, fromlist=modules.detection_modules.__all__) - for mod_name in pack_mod_os.__all__: - mod = __import__ ("modules.detection_modules." + os + "." + mod_name, fromlist=modules.detection_modules.unix.__all__) # on charge le module - mod_instance = getattr(mod, mod_name)(conn, db) # on appelle le constructeur - try: - mod_instance.run_detection() - except modules.CommandNotFoundException.CommandNotFoundException as cnfe: - print cnfe.__str__() - if ws is not None: - ws.send(json.dumps({"ERROR": cnfe.__str__()})) + Instanciates and runs the run_detection() method from each detection modules loaded on loaded_mod_detect + :param + """ + db = self.get_db() + conn = self.create_connection(addr_host) + if conn is not None: + for mod_name in self.loaded_mod_detect: + mod_inst = getattr(self.loaded_mod_moni[mod_name]['imported'], + self.loaded_mod_moni[mod_name]['class_name'])(conn, db) + try: + mod_inst.check() + except modules.ModuleNotCompatibleException.ModuleNotCompatibleException as mnce: + print mnce.__str__() + except modules.CommandNotFoundException.CommandNotFoundException as cnfe: + print cnfe.__str__() def load_all_monitoring_modules(self): """ @@ -165,15 +183,16 @@ class ModuleLoader: 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) - try: - mod_inst.check() - except modules.ModuleNotCompatibleException.ModuleNotCompatibleException as mnce: - print mnce.__str__() - except modules.CommandNotFoundException.CommandNotFoundException as cnfe: - print cnfe.__str__() + if conn is not None: + mod_inst = getattr(self.loaded_mod_moni[mod_name]['imported'], + self.loaded_mod_moni[mod_name]['class_name'])(conn, db, + modules.ModuleNotCompatibleException) + try: + mod_inst.check() + except modules.ModuleNotCompatibleException.ModuleNotCompatibleException as mnce: + print mnce.__str__() + except modules.CommandNotFoundException.CommandNotFoundException as cnfe: + print cnfe.__str__() def get_monitoring_modules_list(self): """ diff --git a/app/modules/detection_modules/__init__.py b/app/modules/detection_modules/__init__.py index 9735bce..6ed406e 100644 --- a/app/modules/detection_modules/__init__.py +++ b/app/modules/detection_modules/__init__.py @@ -1,2 +1 @@ -__author__ = 'aguilbaud' -__all__ = ['unix'] \ No newline at end of file +__author__ = 'aguilbaud' \ No newline at end of file diff --git a/app/modules/detection_modules/unix/drive_detection.py b/app/modules/detection_modules/drive_detection.py similarity index 79% rename from app/modules/detection_modules/unix/drive_detection.py rename to app/modules/detection_modules/drive_detection.py index 18d548e..b246bde 100644 --- a/app/modules/detection_modules/unix/drive_detection.py +++ b/app/modules/detection_modules/drive_detection.py @@ -2,15 +2,27 @@ __author__ = 'aguilbaud' import json -class drive_detection: +def get_class_name(): + return "DriveDetection" + + +class DriveDetection: + """ + Retourne les informations des partitions systeme sous la forme : + {"sr0": {"mountpoint": "none", "type": "rom", "name": "sr0", "size": "1024M"} + """ + def __init__(self, conn, db): self.conn = conn self.db = db + self.name = get_class_name() + self.compatible_os = ['linux', 'unix'] - ''' - Retourne les informations des partitions systeme sous la forme : - {"sr0": {"mountpoint": "none", "type": "rom", "name": "sr0", "size": "1024M"} - ''' + def get_name(self): + return self.name + + def get_compatible_os(self): + return self.compatible_os # Informations sur les partitions def run_detection(self): diff --git a/app/modules/detection_modules/unix/kernel_detection.py b/app/modules/detection_modules/kernel_detection.py similarity index 53% rename from app/modules/detection_modules/unix/kernel_detection.py rename to app/modules/detection_modules/kernel_detection.py index 037098a..b7d26bd 100644 --- a/app/modules/detection_modules/unix/kernel_detection.py +++ b/app/modules/detection_modules/kernel_detection.py @@ -1,10 +1,23 @@ __author__ = 'aguilbaud' import json -class kernel_detection: + +def get_class_name(): + return "KernelDetection" + + +class KernelDetection: def __init__(self, conn, db): self.conn = conn self.db = db + self.name = get_class_name() + self.compatible_os = ['linux', 'unix'] + + def get_name(self): + return self.name + + def get_compatible_os(self): + return self.compatible_os def run_detection(self): cmd = "cat /proc/version" diff --git a/app/modules/detection_modules/unix/os_detection.py b/app/modules/detection_modules/os_detection.py similarity index 73% rename from app/modules/detection_modules/unix/os_detection.py rename to app/modules/detection_modules/os_detection.py index 6126250..20492a4 100644 --- a/app/modules/detection_modules/unix/os_detection.py +++ b/app/modules/detection_modules/os_detection.py @@ -2,10 +2,22 @@ __author__ = 'aguilbaud' import json -class os_detection: +def get_class_name(): + return "OSDetection" + + +class OSDetection: def __init__(self, conn, db): self.conn = conn self.db = db + self.name = get_class_name() + self.compatible_os = ['linux', 'unix'] + + def get_name(self): + return self.name + + def get_compatible_os(self): + return self.compatible_os def run_detection(self): dict_total = {} diff --git a/app/modules/detection_modules/unix/__init__.py b/app/modules/detection_modules/unix/__init__.py deleted file mode 100644 index cb82579..0000000 --- a/app/modules/detection_modules/unix/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -__author__ = 'aguilbaud' -__all__ = ['drive_detection', 'kernel_detection', 'os_detection'] \ No newline at end of file diff --git a/app/modules/detection_modules/unix/cpu_detection.py b/app/modules/detection_modules/unix/cpu_detection.py deleted file mode 100644 index d578583..0000000 --- a/app/modules/detection_modules/unix/cpu_detection.py +++ /dev/null @@ -1,18 +0,0 @@ -__author__ = 'aguilbaud' -import json - - -class cpu_detection: - def __init__(self, conn, db): - self.conn = conn - self.db = db - - def run_detection(self): - dict_total = {} - cmd = "lshw -class cpu -json" - stdout = self.conn.exec_command(cmd) - all_res = json.loads(stdout) - for key in all_res: - if type(all_res[key]) != "dict": - dict_total[key] = all_res[key] - self.db.save_detection(self.conn.get_addr_host(), "cpu_detection", json.dumps(dict_total)) \ No newline at end of file diff --git a/app/modules/detection_modules/unix/network_detection.py b/app/modules/detection_modules/unix/network_detection.py deleted file mode 100644 index 9143464..0000000 --- a/app/modules/detection_modules/unix/network_detection.py +++ /dev/null @@ -1,18 +0,0 @@ -__author__ = 'aguilbaud' -import json - - -class cpu_detection: - def __init__(self, conn, db): - self.conn = conn - self.db = db - - def run_detection(self): - dict_total = {} - cmd = "lshw -class network -json" - stdout = self.conn.exec_command(cmd) - all_res = json.loads(stdout) - for key in all_res: - if type(all_res[key]) != "dict": - dict_total[key] = all_res[key] - self.db.save_detection(self.conn.get_addr_host(), "network_detection", json.dumps(dict_total)) \ No newline at end of file diff --git a/app/process_monitoring.py b/app/process_monitoring.py index a4e852d..ffc51a8 100644 --- a/app/process_monitoring.py +++ b/app/process_monitoring.py @@ -98,8 +98,7 @@ class RunMonitoring(threading.Thread): sys.stdout.flush() self.ml.run_one_monitoring_module(dict_mod['mod_name'], dict_mod['addr'], None, None) else: - print "Launching " + str(dict_mod['os']) + "." + \ - str(dict_mod['mod_name']) + " on " + str(dict_mod['addr']) + print "Launching " + str(dict_mod['mod_name']) + " on " + str(dict_mod['addr']) sys.stdout.flush() self.ml.run_one_monitoring_module(dict_mod['mod_name'], dict_mod['addr'], None, None) self.wsc.notify_state_change() \ No newline at end of file diff --git a/static/js/controllers/hostPageCtrl.js b/static/js/controllers/hostPageCtrl.js index 635d059..a009be5 100644 --- a/static/js/controllers/hostPageCtrl.js +++ b/static/js/controllers/hostPageCtrl.js @@ -58,14 +58,14 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $routeParams, $mo }); // monitoring data are updated - /*$scope.$on("hostsUpdate", function (event, args) { + $scope.$on("hostsUpdate", function (event, args) { $scope.$apply(function(){ for(i=0 ; i<args.length()) ; i++){ if(args[i][]) $scope.items['monitoring'] = args['monitoring']; } }); - });*/ + }); // save custom informations $scope.save_custom_infos = function(){ -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.