branch develop updated (6300cc0 -> 879347f)
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 6300cc0 run_all_detection_modules OK run_all_monitoring_modules OK get_hosts now at the opening of websocket new 1db4361 comments added new 53d9e06 Ajout de "mum.db" au .gitignore new 377543e Files commented added new 879347f Merge branch 'develop' of https://git.chorem.org/mum into develop The 4 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 879347f73a0d67a89bb69e0ae3322bd121efb385 Merge: 377543e 6300cc0 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Fri Feb 20 10:09:05 2015 +0100 Merge branch 'develop' of https://git.chorem.org/mum into develop Conflicts: app/module_loader.py app/modules/monitoring_modules/__init__.py commit 377543eae3380458096c6318dc554bde6f247b16 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Fri Feb 20 10:02:45 2015 +0100 Files commented added commit 53d9e064b71e6bd52cdb8cf300f564f02cebe615 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Fri Feb 20 10:02:11 2015 +0100 Ajout de "mum.db" au .gitignore commit 1db4361179c52bbbdf65244a04683471e66f8a8c Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Fri Feb 20 09:41:03 2015 +0100 comments added Summary of changes: .gitignore | 3 +- app/app.pyc | Bin 0 -> 4800 bytes app/module_loader.py | 31 ++++++++- app/module_loader.pyc | Bin 0 -> 1848 bytes app/modules/__init__.pyc | Bin 0 -> 165 bytes app/modules/connection_modules/__init__.pyc | Bin 0 -> 215 bytes app/modules/connection_modules/ssh.pyc | Bin 0 -> 1330 bytes app/modules/detection_modules/__init__.pyc | Bin 0 -> 191 bytes app/modules/detection_modules/nmap_detection.pyc | Bin 0 -> 4355 bytes app/modules/detection_modules/unix/__init__.pyc | Bin 0 -> 275 bytes .../detection_modules/unix/cpu_detection.py | 18 ++++++ .../detection_modules/unix/drive_detection.pyc | Bin 0 -> 1445 bytes .../detection_modules/unix/network_detection.py | 18 ++++++ app/modules/monitoring_modules/__init__.py | 4 +- app/modules/storage_modules/__init__.pyc | Bin 0 -> 218 bytes app/modules/storage_modules/shelve_db.py | 71 +++++++++++++++++++-- app/modules/storage_modules/shelve_db.pyc | Bin 0 -> 4335 bytes 17 files changed, 137 insertions(+), 8 deletions(-) create mode 100644 app/app.pyc create mode 100644 app/module_loader.pyc create mode 100644 app/modules/__init__.pyc create mode 100644 app/modules/connection_modules/__init__.pyc create mode 100644 app/modules/connection_modules/ssh.pyc create mode 100644 app/modules/detection_modules/__init__.pyc create mode 100644 app/modules/detection_modules/nmap_detection.pyc create mode 100644 app/modules/detection_modules/unix/__init__.pyc create mode 100644 app/modules/detection_modules/unix/cpu_detection.py create mode 100644 app/modules/detection_modules/unix/drive_detection.pyc create mode 100644 app/modules/detection_modules/unix/network_detection.py create mode 100644 app/modules/storage_modules/__init__.pyc create mode 100644 app/modules/storage_modules/shelve_db.pyc -- 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 1db4361179c52bbbdf65244a04683471e66f8a8c Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Fri Feb 20 09:41:03 2015 +0100 comments added --- app/module_loader.py | 29 +++++++++ app/modules/detection_modules/__init__.py | 1 + .../detection_modules/unix/cpu_detection.py | 18 ++++++ .../detection_modules/unix/network_detection.py | 18 ++++++ app/modules/storage_modules/shelve_db.py | 71 ++++++++++++++++++++-- 5 files changed, 133 insertions(+), 4 deletions(-) diff --git a/app/module_loader.py b/app/module_loader.py index ccde508..9f6ad2a 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -4,8 +4,15 @@ import modules.detection_modules.unix import modules.connection_modules import modules.storage_modules +""" +Loads dynamically modules from packages connection_modules, detection_modules, monitoring_modules, storage_modules. +""" def load_db(): + """ + 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)() @@ -13,18 +20,40 @@ def load_db(): def run_nmap_detection(ip_range, db, ws): + """ + Instanciates the nmap_detection module from detection_modules, and runs the detection. + :param ip_range: addresses to execute the nmap detection + :param db: an instance of a database module + :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_instance = getattr(nmap_mod, "nmap_detection")(db, ws) return nmap_mod_instance.check_ip_range(ip_range) def load_conn(conn_name, addr_host, key_location): # /home/aguilbaud/.ssh/id_rsa + """ + Instanciates and creates a connection with a connection module. + :param conn_name: the name of the detection module + :param addr_host: the IP adress of the host we want to create a connection + :param key_location: the location of the public key + :return: the instance of connection module created + """ conn = __import__("modules.connection_modules." + conn_name, fromlist=modules.connection_modules) conn_instance = getattr(conn, conn_name)(addr_host, key_location) return conn_instance def run_all_detection_modules(os, conn, db): + """ + 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 + """ + for mod_name in "modules.detection_modules." + 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 diff --git a/app/modules/detection_modules/__init__.py b/app/modules/detection_modules/__init__.py index fcb43f2..9735bce 100644 --- a/app/modules/detection_modules/__init__.py +++ b/app/modules/detection_modules/__init__.py @@ -1 +1,2 @@ __author__ = 'aguilbaud' +__all__ = ['unix'] \ 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 new file mode 100644 index 0000000..d578583 --- /dev/null +++ b/app/modules/detection_modules/unix/cpu_detection.py @@ -0,0 +1,18 @@ +__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 new file mode 100644 index 0000000..9143464 --- /dev/null +++ b/app/modules/detection_modules/unix/network_detection.py @@ -0,0 +1,18 @@ +__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/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index 7cc71dd..74282b7 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -9,11 +9,18 @@ import os.path 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): self.db = None def open_db(self): + """ + Open the shelve database from the file mum.db. + If the file donesn't exists, it will be created and the first structure will also be initialized. + """ if not os.path.isfile("mum.db"): # init of the database at the first opening self.db = shelve.open("mum.db", writeback=True) try: @@ -26,8 +33,10 @@ class shelve_db: else: self.db = shelve.open("mum.db", writeback=True) - # Closes the database def close_db(self): + """ + Closes the database + """ self.db.close() self.db = None @@ -36,6 +45,14 @@ class shelve_db: # It also preconfigure with the default configuration, add the host to the group "all" and # creates empty structures for the monitoring and archive data. def add_host(self,addr_host, nmap_res): + """ + Called by the nmap_detection module. + Add and save a new host after its first nmap detection + It also preconfigure with the default configuration, add the host to the group "all" and + creates empty structures for the monitoring and archive data. + :param addr_host: the IP adress of the host to add + :param nmap_res: a string containing the json reslult of the nmap detection of this host + """ self.open_db() addr_host = str(addr_host) # Shelve doesn't support Unicode try: @@ -62,6 +79,34 @@ class shelve_db: # These are used by the front-end # If no hosts have been added, the function will return an empty list def get_hosts(self): + """ + Returns the essential data about all hosts under monitoring + These are used by the front-end + Called by the app.py, after one client demand. + :return: a list containing the essential data in json, about all hosts under monitoring on the form: + [ + { + "addr":"192.168.74.1", + "name":"www.example.com", + "status":val, //"success" ou "warning" ou "danger" ou "" + "group":[ // au moins 1 groupe "all" + { + "name":"all" + }, + { + "name":"mygroup1" + } + ], + "last_check":val //heure UNIX + "subscribers":{ + "uid":val, + "priority":val + } + }, + ... + ] + If no hosts have been added, the function will return an empty dict. + """ self.open_db() res = [] try: @@ -88,14 +133,27 @@ class shelve_db: return json.dumps(res) def save_detection(self, addr_host, name_part, json_res_str): + """ + Called by a detection module in order to save his detection on the database. + :param addr_host: the IP adress of the host detected + :param name_part: the name of the detection_module which have done the detection + :param json_res_str: a string containing the results of the detection in json + """ self.open_db() try: self.db["hosts"][addr_host]["detected"][name_part] = json_res_str finally: self.close_db() - # Add a new check of a host from a specific module def add_check(self, addr_host, name_part, val): + """ + Called by a monitoring module. + Add a new check of a host from a specific module. + Add the previous entry of monitoring to the archive and call update_stats to update the statistics. + :param addr_host: the IP adress of the host checked + :param name_part: the name of the monitoring_module which have done the check + :param val: the value observed + """ self.open_db() new_val = {"date": datetime.now()} try: @@ -114,8 +172,13 @@ class shelve_db: finally: self.close_db() - # Updates calulated statistics once a new value is received def update_stats(self, stats, val): + """ + Updates calulated statistics once a new value is received. + :param stats: a dictionary taken from the database and corresponding to the statistics stored + :param val: the new value + :return: the statistics dictionary updated + """ stats['nb_check'] += 1 stats['total'] += val if stats['min'] > val: -- 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 53d9e064b71e6bd52cdb8cf300f564f02cebe615 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Fri Feb 20 10:02:11 2015 +0100 Ajout de "mum.db" au .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6bc525c..6cae0cc 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ venv node_modules *~ .idea -res.xml \ No newline at end of file +res.xml +mum.db -- 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 377543eae3380458096c6318dc554bde6f247b16 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Fri Feb 20 10:02:45 2015 +0100 Files commented added --- app/app.pyc | Bin 0 -> 4800 bytes app/module_loader.pyc | Bin 0 -> 1848 bytes app/modules/__init__.pyc | Bin 0 -> 165 bytes app/modules/connection_modules/__init__.pyc | Bin 0 -> 215 bytes app/modules/connection_modules/ssh.pyc | Bin 0 -> 1330 bytes app/modules/detection_modules/__init__.pyc | Bin 0 -> 191 bytes app/modules/detection_modules/nmap_detection.pyc | Bin 0 -> 4355 bytes app/modules/detection_modules/unix/__init__.pyc | Bin 0 -> 275 bytes app/modules/detection_modules/unix/drive_detection.pyc | Bin 0 -> 1445 bytes app/modules/monitoring_modules/__init__.py | 1 + app/modules/storage_modules/__init__.pyc | Bin 0 -> 218 bytes app/modules/storage_modules/shelve_db.pyc | Bin 0 -> 4335 bytes 12 files changed, 1 insertion(+) diff --git a/app/app.pyc b/app/app.pyc new file mode 100644 index 0000000..fefccc5 Binary files /dev/null and b/app/app.pyc differ diff --git a/app/module_loader.pyc b/app/module_loader.pyc new file mode 100644 index 0000000..ded0e3d Binary files /dev/null and b/app/module_loader.pyc differ diff --git a/app/modules/__init__.pyc b/app/modules/__init__.pyc new file mode 100644 index 0000000..28b0138 Binary files /dev/null and b/app/modules/__init__.pyc differ diff --git a/app/modules/connection_modules/__init__.pyc b/app/modules/connection_modules/__init__.pyc new file mode 100644 index 0000000..0deeda4 Binary files /dev/null and b/app/modules/connection_modules/__init__.pyc differ diff --git a/app/modules/connection_modules/ssh.pyc b/app/modules/connection_modules/ssh.pyc new file mode 100644 index 0000000..9523306 Binary files /dev/null and b/app/modules/connection_modules/ssh.pyc differ diff --git a/app/modules/detection_modules/__init__.pyc b/app/modules/detection_modules/__init__.pyc new file mode 100644 index 0000000..26328a7 Binary files /dev/null and b/app/modules/detection_modules/__init__.pyc differ diff --git a/app/modules/detection_modules/nmap_detection.pyc b/app/modules/detection_modules/nmap_detection.pyc new file mode 100644 index 0000000..9ce7190 Binary files /dev/null and b/app/modules/detection_modules/nmap_detection.pyc differ diff --git a/app/modules/detection_modules/unix/__init__.pyc b/app/modules/detection_modules/unix/__init__.pyc new file mode 100644 index 0000000..fba9039 Binary files /dev/null and b/app/modules/detection_modules/unix/__init__.pyc differ diff --git a/app/modules/detection_modules/unix/drive_detection.pyc b/app/modules/detection_modules/unix/drive_detection.pyc new file mode 100644 index 0000000..3a2740d Binary files /dev/null and b/app/modules/detection_modules/unix/drive_detection.pyc differ diff --git a/app/modules/monitoring_modules/__init__.py b/app/modules/monitoring_modules/__init__.py new file mode 100644 index 0000000..fcb43f2 --- /dev/null +++ b/app/modules/monitoring_modules/__init__.py @@ -0,0 +1 @@ +__author__ = 'aguilbaud' diff --git a/app/modules/storage_modules/__init__.pyc b/app/modules/storage_modules/__init__.pyc new file mode 100644 index 0000000..df03010 Binary files /dev/null and b/app/modules/storage_modules/__init__.pyc differ diff --git a/app/modules/storage_modules/shelve_db.pyc b/app/modules/storage_modules/shelve_db.pyc new file mode 100644 index 0000000..e5f0cd3 Binary files /dev/null and b/app/modules/storage_modules/shelve_db.pyc differ -- 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 879347f73a0d67a89bb69e0ae3322bd121efb385 Merge: 377543e 6300cc0 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Fri Feb 20 10:09:05 2015 +0100 Merge branch 'develop' of https://git.chorem.org/mum into develop Conflicts: app/module_loader.py app/modules/monitoring_modules/__init__.py app/module_loader.py | 22 +++++++++++++++++----- app/modules/detection_modules/nmap_detection.py | 6 ++++-- .../detection_modules/unix/kernel_detection.py | 1 + app/modules/monitoring_modules/__init__.py | 1 + app/modules/monitoring_modules/unix/__init__.py | 1 + .../monitoring_modules/unix/updated_packages.py | 19 +++++++++++++++++++ static/js/controllers/table_ctrl.js | 10 +++++----- views/dashboard.html | 1 - 8 files changed, 48 insertions(+), 13 deletions(-) diff --cc app/module_loader.py index 9f6ad2a,d12d3d7..c336695 --- a/app/module_loader.py +++ b/app/module_loader.py @@@ -1,18 -1,12 +1,19 @@@ __author__ = 'aguilbaud' - import modules.detection_modules - import modules.detection_modules.unix + import modules import modules.connection_modules + import modules.detection_modules + import modules.monitoring_modules import modules.storage_modules +""" +Loads dynamically modules from packages connection_modules, detection_modules, monitoring_modules, storage_modules. +""" def load_db(): + """ + 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)() @@@ -46,15 -26,18 +47,26 @@@ def load_conn(conn_name, addr_host, key def run_all_detection_modules(os, conn, db): + """ + 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 + """ - - for mod_name in "modules.detection_modules." + os + ".__all__": + __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 - mod_instance.run_detection() + mod_instance.run_detection() + + ++ + def run_all_monitoring_modules(os, conn, db): + __import__("modules.monitoring_modules." + os) + 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) # on appelle le constructeur - #mod_instance.check() ++ #mod_instance.check() diff --cc app/modules/monitoring_modules/__init__.py index fcb43f2,64f86cc..9735bce --- a/app/modules/monitoring_modules/__init__.py +++ b/app/modules/monitoring_modules/__init__.py @@@ -1,1 -1,2 +1,2 @@@ -__author__ = 'alexis' -__all__=['unix'] +__author__ = 'aguilbaud' ++__all__ = ['unix'] -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm