branch develop updated (a3a9dcb -> a1175ea)
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 a3a9dcb the monitoring can now resume after launching again the server new c0814f3 new class : WebSocketContainer, which permit to refresh the frontend when a check occures + added 'warning' and 'danger' list of modules as information on get_hosts() => now is visible on dashboard new a1175ea optimization on process_monitoring The 2 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 a1175ea2326e3dea53dd9471076d64edb361ff0c Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Feb 26 15:42:54 2015 +0100 optimization on process_monitoring commit c0814f3675c4f6c2423a930ff47bd3f4b331aece Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Feb 26 15:23:52 2015 +0100 new class : WebSocketContainer, which permit to refresh the frontend when a check occures + added 'warning' and 'danger' list of modules as information on get_hosts() => now is visible on dashboard Summary of changes: app/app.py | 10 ++++++++-- app/{ => modules/notification_modules}/__init__.py | 0 .../notification_modules/websocket_container.py | 19 ++++++++++++++++++ app/modules/storage_modules/shelve_db.py | 9 +++++++++ app/process_monitoring.py | 23 +++++++++++++++------- views/dashboard.html | 3 ++- 6 files changed, 54 insertions(+), 10 deletions(-) copy app/{ => modules/notification_modules}/__init__.py (100%) create mode 100644 app/modules/notification_modules/websocket_container.py -- 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 c0814f3675c4f6c2423a930ff47bd3f4b331aece Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Feb 26 15:23:52 2015 +0100 new class : WebSocketContainer, which permit to refresh the frontend when a check occures + added 'warning' and 'danger' list of modules as information on get_hosts() => now is visible on dashboard --- app/app.py | 10 ++++++++-- app/modules/notification_modules/__init__.py | 1 + .../notification_modules/websocket_container.py | 19 +++++++++++++++++++ app/modules/storage_modules/shelve_db.py | 9 +++++++++ app/process_monitoring.py | 15 +++++++++------ views/dashboard.html | 3 ++- 6 files changed, 48 insertions(+), 9 deletions(-) diff --git a/app/app.py b/app/app.py index 8a51703..ea748f7 100755 --- a/app/app.py +++ b/app/app.py @@ -9,6 +9,7 @@ import json import threading import module_loader import process_monitoring +from modules.notification_modules.websocket_container import WebSocketContainer NMAP_SCAN_DEMAND = "10" DETECTION_DEMAND = "11" @@ -26,6 +27,7 @@ BROWSER_NOTIFICATION = "31" ERROR = "40" +wsc = WebSocketContainer # Pour lancer la detection nmap avec un nouveau thread class ThreadDetect(threading.Thread): @@ -123,6 +125,7 @@ def bower_files(filepath): # Creation d'une websocket pour permettre la communication avec le client @get('/websocket', apply=[websocket]) def receive(ws): + wsc.add_websocket(ws) while True: try: response = ws.receive() @@ -141,11 +144,14 @@ def receive(ws): else: break except: # Should be WebSocketError when closing the connection - pass + wsc.remove_websocket(ws) + break # Lancement du serveur a l'adresse 0.0.0.0:1337 if __name__ == '__main__': - process_monitoring.init(module_loader.load_db()) + global wsc + wsc = WebSocketContainer(module_loader.load_db()) + process_monitoring.init(module_loader.load_db(), 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/modules/notification_modules/__init__.py b/app/modules/notification_modules/__init__.py new file mode 100644 index 0000000..fcb43f2 --- /dev/null +++ b/app/modules/notification_modules/__init__.py @@ -0,0 +1 @@ +__author__ = 'aguilbaud' diff --git a/app/modules/notification_modules/websocket_container.py b/app/modules/notification_modules/websocket_container.py new file mode 100644 index 0000000..15c5c04 --- /dev/null +++ b/app/modules/notification_modules/websocket_container.py @@ -0,0 +1,19 @@ +__author__ = 'aguilbaud' + +import json + +class WebSocketContainer: + + def __init__(self, db): + self.ws_set = set() + self.db = db + + def add_websocket(self, ws): + self.ws_set.add(ws) + + def remove_websocket(self, ws): + self.ws_set.discard(ws) + + def notify_state_change(self): + for ws in self.ws_set: + ws.send(json.dumps({"22": self.db.get_hosts()})) \ 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 5d1bea7..bd26a76 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -207,6 +207,8 @@ class shelve_db: "uid":val, "priority":val } + "warning": [mod_name, ...] + "danger": [mod_name, ...] }, ... ] @@ -232,6 +234,13 @@ class shelve_db: info_host["last_check"] = self.db["hosts"][host]["status"]["date"] else: info_host["last_check"] = 0 + info_host["warning"] = [] + info_host["danger"] = [] + for mod in self.db["hosts"][host]["monitoring"]: + if self.db["hosts"][host]["monitoring"][mod]["state"] == "warning": + info_host["warning"].append(mod) + elif self.db["hosts"][host]["monitoring"][mod]["state"] == "danger": + info_host["danger"].append(mod) res.append(info_host) finally: self.close_db() diff --git a/app/process_monitoring.py b/app/process_monitoring.py index d977ce2..3e92499 100644 --- a/app/process_monitoring.py +++ b/app/process_monitoring.py @@ -11,12 +11,12 @@ import sys waiting_list = [] -def init(db): +def init(db,wsc): for instr in get_all_monitoring_instructions(db): #print "adding : " + str(instr) sys.stdout.flush() add_to_waiting_list(instr) - pm = ProcessMonitoring() + pm = ProcessMonitoring(wsc) pm.start() @@ -36,8 +36,9 @@ class ProcessMonitoring(threading.Thread): We could use here the deque structure from Python in order to use optimized poping left, but this structure don't have implemented the insert() function, which is used for adding new data and keep the queue ordored. """ - def __init__(self): + def __init__(self, wsc): threading.Thread.__init__(self) + self.wsc = wsc def run(self): """ @@ -54,7 +55,7 @@ class ProcessMonitoring(threading.Thread): modules_to_run.append(dict_mod) dict_mod['time'] = dict_mod['time'] + timedelta(seconds=dict_mod['freq']) add_to_waiting_list(dict_mod) - rm = RunMonitoring(modules_to_run) + rm = RunMonitoring(modules_to_run, self.wsc) rm.start() time.sleep(1) @@ -74,12 +75,14 @@ def add_to_waiting_list(dict_mod): class RunMonitoring(threading.Thread): - def __init__(self, list_dict_mod): + def __init__(self, list_dict_mod, wsc): threading.Thread.__init__(self) self.list_dict_mod = list_dict_mod + self.wsc = wsc def run(self): for dict_mod in self.list_dict_mod: print "Launching " + str(dict_mod['os']) + "." + str(dict_mod['mod_name']) + " on " + str(dict_mod['addr']) sys.stdout.flush() - run_one_monitoring_module(dict_mod['mod_name'], dict_mod['addr'], dict_mod['os'], None, None, None) \ No newline at end of file + run_one_monitoring_module(dict_mod['mod_name'], dict_mod['addr'], dict_mod['os'], None, None, None) + self.wsc.notify_state_change() \ No newline at end of file diff --git a/views/dashboard.html b/views/dashboard.html index e621f0d..13e67b0 100644 --- a/views/dashboard.html +++ b/views/dashboard.html @@ -70,7 +70,8 @@ group:{name:group_filter}}" class={{item.status}}> <td><a href="#/hostpage/{{item.addr}}" ng-click="get_host_informations({{item.addr}})">{{item.addr}}</a></td> <td>{{item.name}}</td> - <td>{{item.status}}</td> + <td>warning : {{item.warning}}<br/> + danger : {{item.danger}}</td> <td>{{getGroupsByAddr(item.addr)}}</td> <td>{{item.last_check}}</td> </tr> -- 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 a1175ea2326e3dea53dd9471076d64edb361ff0c Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Feb 26 15:42:54 2015 +0100 optimization on process_monitoring --- app/process_monitoring.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/process_monitoring.py b/app/process_monitoring.py index 3e92499..8ddbb04 100644 --- a/app/process_monitoring.py +++ b/app/process_monitoring.py @@ -47,6 +47,7 @@ class ProcessMonitoring(threading.Thread): having the same launching date. """ global waiting_list + ready_to_launch = False while True: if not waiting_list == []: modules_to_run = [] @@ -55,8 +56,11 @@ class ProcessMonitoring(threading.Thread): modules_to_run.append(dict_mod) dict_mod['time'] = dict_mod['time'] + timedelta(seconds=dict_mod['freq']) add_to_waiting_list(dict_mod) - rm = RunMonitoring(modules_to_run, self.wsc) - rm.start() + ready_to_launch = True + if ready_to_launch: + rm = RunMonitoring(modules_to_run, self.wsc) + rm.start() + ready_to_launch = False time.sleep(1) @@ -81,6 +85,8 @@ class RunMonitoring(threading.Thread): self.wsc = wsc def run(self): + print "running" + sys.stdout.flush() for dict_mod in self.list_dict_mod: print "Launching " + str(dict_mod['os']) + "." + str(dict_mod['mod_name']) + " on " + str(dict_mod['addr']) sys.stdout.flush() -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm