branch develop updated (ca647b1 -> 4f1bea8)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository mum. See http://git.chorem.org/mum.git from ca647b1 corrigé un bug lors de la suppresion d'un hôte new 4f1bea8 detection modules refactorés The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 4f1bea8f1259645eac3ca8d38cf307f765d1775e Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Apr 2 17:29:39 2015 +0200 detection modules refactorés Summary of changes: app/module_loader.py | 14 ++--- app/modules/detection_modules/drive_detection.py | 65 ++++++++-------------- app/modules/detection_modules/kernel_detection.py | 29 +++------- app/modules/detection_modules/os_detection.py | 45 +++++---------- .../{detection_modules => }/nmap_detection.py | 0 app/modules/storage_modules/shelve_db.py | 5 +- 6 files changed, 54 insertions(+), 104 deletions(-) rename app/modules/{detection_modules => }/nmap_detection.py (100%) -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 4f1bea8f1259645eac3ca8d38cf307f765d1775e Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Apr 2 17:29:39 2015 +0200 detection modules refactorés --- app/module_loader.py | 14 ++--- app/modules/detection_modules/drive_detection.py | 65 ++++++++-------------- app/modules/detection_modules/kernel_detection.py | 29 +++------- app/modules/detection_modules/os_detection.py | 45 +++++---------- .../{detection_modules => }/nmap_detection.py | 0 app/modules/storage_modules/shelve_db.py | 5 +- 6 files changed, 54 insertions(+), 104 deletions(-) diff --git a/app/module_loader.py b/app/module_loader.py index 1ed2863..1328a59 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -60,7 +60,7 @@ class ModuleLoader: :param ws: a websocket connection :return: a list containing the IP adresses checked """ - nmap_mod = __import__("modules.detection_modules.nmap_detection", fromlist=modules.detection_modules) + nmap_mod = __import__("modules.nmap_detection", fromlist=modules) nmap_mod_instance = getattr(nmap_mod, "nmap_detection")(opt, db, ws, list_mod_conn, dict_mod_monitoring, modules.HostNotFoundException) try: @@ -105,15 +105,12 @@ class ModuleLoader: 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/"]): - if mod_name not in sys.modules and not mod_name == 'nmap_detection': + if mod_name not in sys.modules: 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')() + infos_mod['compatible_os'] = getattr(loaded_mod, 'compatible_os') for os in infos_mod['compatible_os']: if os not in self.compatible_os_list: self.compatible_os_list.append(os) @@ -130,10 +127,9 @@ class ModuleLoader: 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_detect[mod_name]['imported'], - self.loaded_mod_detect[mod_name]['class_name'])(conn, db) try: - mod_inst.run_detection() + getattr(self.loaded_mod_detect[mod_name]['imported'], + 'run_detection')(conn, db) except modules.ModuleNotCompatibleException.ModuleNotCompatibleException as mnce: print mnce.__str__() except modules.CommandNotFoundException.CommandNotFoundException as cnfe: diff --git a/app/modules/detection_modules/drive_detection.py b/app/modules/detection_modules/drive_detection.py index b246bde..fe69896 100644 --- a/app/modules/detection_modules/drive_detection.py +++ b/app/modules/detection_modules/drive_detection.py @@ -1,51 +1,34 @@ __author__ = 'aguilbaud' import json +compatible_os = ['linux', 'unix'] -def get_class_name(): - return "DriveDetection" - -class DriveDetection: +def run_detection(conn, db): """ 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'] - - def get_name(self): - return self.name - - def get_compatible_os(self): - return self.compatible_os - - # Informations sur les partitions - def run_detection(self): - cmd = "lsblk -r --output=NAME,SIZE,TYPE,MOUNTPOINT" - stdout = self.conn.exec_command(cmd) - dict_total = {} - i = 1 - ignore = True - for line in stdout.splitlines(): - # On ignore la premiere ligne qui ne contient pas de valeurs - if ignore: - ignore = False + cmd = "lsblk -r --output=NAME,SIZE,TYPE,MOUNTPOINT" + stdout = conn.exec_command(cmd) + dict_total = {} + i = 1 + ignore = True + for line in stdout.splitlines(): + # On ignore la premiere ligne qui ne contient pas de valeurs + if ignore: + ignore = False + else: + dict_drive = {} + tab_elem = line.split() + dict_drive["name"] = tab_elem[0] + dict_drive["size"] = tab_elem[1] + dict_drive["type"] = tab_elem[2] + if len(tab_elem) > 3: + dict_drive["mountpoint"] = tab_elem[3] else: - dict_drive = {} - tab_elem = line.split() - dict_drive["name"] = tab_elem[0] - dict_drive["size"] = tab_elem[1] - dict_drive["type"] = tab_elem[2] - if len(tab_elem) > 3: - dict_drive["mountpoint"] = tab_elem[3] - else: - dict_drive["mountpoint"] = "none" - # meilleur nom pour chaque attribut ? - dict_total[dict_drive["name"]] = dict_drive - i += 1 - self.db.save_detection(self.conn.get_addr_host(), "drive_detection", json.dumps(dict_total)) \ No newline at end of file + dict_drive["mountpoint"] = "none" + # meilleur nom pour chaque attribut ? + dict_total[dict_drive["name"]] = dict_drive + i += 1 + db.save_detection(conn.get_addr_host(), "drive_detection", json.dumps(dict_total)) \ No newline at end of file diff --git a/app/modules/detection_modules/kernel_detection.py b/app/modules/detection_modules/kernel_detection.py index b7d26bd..868d657 100644 --- a/app/modules/detection_modules/kernel_detection.py +++ b/app/modules/detection_modules/kernel_detection.py @@ -1,27 +1,12 @@ __author__ = 'aguilbaud' import json +compatible_os = ['linux', 'unix'] -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" - stdout = self.conn.exec_command(cmd) - dict_total = {} - dict_total["kernel"] = stdout.split('#')[0] - self.db.save_detection(self.conn.get_addr_host(), "kernel_detection", json.dumps(dict_total)) \ No newline at end of file +def run_detection(conn, db): + cmd = "cat /proc/version" + stdout = conn.exec_command(cmd) + dict_total = {} + dict_total["kernel"] = stdout.split('#')[0] + db.save_detection(conn.get_addr_host(), "kernel_detection", json.dumps(dict_total)) \ No newline at end of file diff --git a/app/modules/detection_modules/os_detection.py b/app/modules/detection_modules/os_detection.py index 20492a4..420594f 100644 --- a/app/modules/detection_modules/os_detection.py +++ b/app/modules/detection_modules/os_detection.py @@ -2,34 +2,19 @@ __author__ = 'aguilbaud' import json -def get_class_name(): - return "OSDetection" +compatible_os = ['linux', 'unix'] - -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 = {} - cmd = "cat /etc/os-release" - stdout = self.conn.exec_command(cmd) - for line in stdout.splitlines(): - tab_elem = line.split("=") - # pour retirer les "" sur tous les champs qui en possedent - tab_right = tab_elem[1].split('"') - if len(tab_right) == 1: - dict_total[str.lower(tab_elem[0])] = tab_right[0] - else: - dict_total[str.lower(tab_elem[0])] = tab_right[1] - # encore une fois, on recupere tout le contenu de la commande, p-e qu'il est possible d'enlever le superflu - self.db.save_detection(self.conn.get_addr_host(), "os_detection", json.dumps(dict_total)) \ No newline at end of file +def run_detection(conn, db): + dict_total = {} + cmd = "cat /etc/os-release" + stdout = conn.exec_command(cmd) + for line in stdout.splitlines(): + tab_elem = line.split("=") + # pour retirer les "" sur tous les champs qui en possedent + tab_right = tab_elem[1].split('"') + if len(tab_right) == 1: + dict_total[str.lower(tab_elem[0])] = tab_right[0] + else: + dict_total[str.lower(tab_elem[0])] = tab_right[1] + # encore une fois, on recupere tout le contenu de la commande, p-e qu'il est possible d'enlever le superflu + db.save_detection(conn.get_addr_host(), "os_detection", json.dumps(dict_total)) \ No newline at end of file diff --git a/app/modules/detection_modules/nmap_detection.py b/app/modules/nmap_detection.py similarity index 100% rename from app/modules/detection_modules/nmap_detection.py rename to app/modules/nmap_detection.py diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index a6c465a..36bae67 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -517,8 +517,9 @@ class shelve_db: for mod_name in args['activated']: # first case : the monitoring module have never been activated for this host if mod_name not in self.db["hosts"][addr_host]["conf"]["monitoring"]: - self.db["hosts"][addr_host]["conf"]["monitoring"][mod_name] = {} - self.generate_unique_conf(dict_mod_info, addr_host, mod_name, args['activated'][mod_name]) + # we copy the global configuration of this module on the host configuration + self.db["hosts"][addr_host]["conf"]["monitoring"][mod_name] = self.db['global_conf'][mod_name] + self.db["hosts"][addr_host]["conf"]["monitoring"][mod_name]['activated'] = args['activated'][mod_name] elif not self.db["hosts"][addr_host]["conf"]["monitoring"][mod_name]["activated"] == \ args['activated'][mod_name]: # second case, the configuration module have changed -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm