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 1ccba97b34c21edb3adc9d977cf5bed435dff794 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Tue May 19 16:19:16 2015 +0200 removed useless attribute "return_dict" on moni mod + moved websocket core functions from mum.py to new module websocket_func --- app/module_loader.py | 1 - .../monitoring_modules/15_min_load_snmp_linux.py | 1 - app/modules/monitoring_modules/cpu_glances.py | 1 - app/modules/monitoring_modules/cpu_snmp_linux.py | 1 - app/modules/monitoring_modules/cpu_ssh_linux.py | 1 - app/modules/monitoring_modules/disk_snmp_linux.py | 1 - app/modules/monitoring_modules/disk_ssh_linux.py | 1 - app/modules/monitoring_modules/http.py | 1 - app/modules/monitoring_modules/load_ssh_linux.py | 1 - .../monitoring_modules/memory_snmp_linux.py | 1 - app/modules/monitoring_modules/memory_ssh_linux.py | 1 - app/modules/monitoring_modules/ping.py | 1 - app/modules/monitoring_modules/smtp.py | 1 - app/modules/monitoring_modules/swap_snmp_linux.py | 1 - app/modules/monitoring_modules/swap_ssh_linux.py | 1 - .../updated_packages_ssh_linux.py | 1 - app/mum.py | 115 +------------- app/websocket_func.py | 168 +++++++++++++++++++++ views/dashboard.html | 10 +- 19 files changed, 182 insertions(+), 127 deletions(-) diff --git a/app/module_loader.py b/app/module_loader.py index 02140a7..c6bc8b8 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -383,7 +383,6 @@ class ModuleLoader: loaded_mod_sample = self.loaded_mod_moni[part]['modules'][mod_sample]['imported'] res[part]['unit'] = getattr(loaded_mod_sample, 'unit') res[part]['block'] = getattr(loaded_mod_sample, 'block') - res[part]['return_dict'] = getattr(loaded_mod_sample, 'return_dict') return res def load_all_connection_modules(self): diff --git a/app/modules/monitoring_modules/15_min_load_snmp_linux.py b/app/modules/monitoring_modules/15_min_load_snmp_linux.py index 98dace9..9e0f615 100644 --- a/app/modules/monitoring_modules/15_min_load_snmp_linux.py +++ b/app/modules/monitoring_modules/15_min_load_snmp_linux.py @@ -6,7 +6,6 @@ block = "hardware" part = "min_15_load" unit = "" connection = "snmp" -return_dict = False def check(conn, mnce, subparts): diff --git a/app/modules/monitoring_modules/cpu_glances.py b/app/modules/monitoring_modules/cpu_glances.py index d634971..79811c9 100644 --- a/app/modules/monitoring_modules/cpu_glances.py +++ b/app/modules/monitoring_modules/cpu_glances.py @@ -8,7 +8,6 @@ block = "hardware" part = "cpu" unit = "%" connection = "glances" -return_dict = False def check(conn, mnce, subparts): diff --git a/app/modules/monitoring_modules/cpu_snmp_linux.py b/app/modules/monitoring_modules/cpu_snmp_linux.py index 40203df..4e7e9f7 100644 --- a/app/modules/monitoring_modules/cpu_snmp_linux.py +++ b/app/modules/monitoring_modules/cpu_snmp_linux.py @@ -6,7 +6,6 @@ block = "hardware" part = "cpu" unit = "%" connection = "snmp" -return_dict = False def check(conn, mnce, subparts): diff --git a/app/modules/monitoring_modules/cpu_ssh_linux.py b/app/modules/monitoring_modules/cpu_ssh_linux.py index a1c7c94..c7a4b20 100644 --- a/app/modules/monitoring_modules/cpu_ssh_linux.py +++ b/app/modules/monitoring_modules/cpu_ssh_linux.py @@ -6,7 +6,6 @@ block = "hardware" part = "cpu" unit = "%" connection = "ssh" -return_dict = False def check(conn, mnce, subparts): diff --git a/app/modules/monitoring_modules/disk_snmp_linux.py b/app/modules/monitoring_modules/disk_snmp_linux.py index a99eda3..18ff25c 100644 --- a/app/modules/monitoring_modules/disk_snmp_linux.py +++ b/app/modules/monitoring_modules/disk_snmp_linux.py @@ -5,7 +5,6 @@ block = "hardware" part = "disk" unit = "%" connection = "snmp_walk" -return_dict = True def check(conn, mnce, subparts): diff --git a/app/modules/monitoring_modules/disk_ssh_linux.py b/app/modules/monitoring_modules/disk_ssh_linux.py index e329fc6..2c49d20 100644 --- a/app/modules/monitoring_modules/disk_ssh_linux.py +++ b/app/modules/monitoring_modules/disk_ssh_linux.py @@ -8,7 +8,6 @@ block = "hardware" part = "disk" unit = "%" connection = "ssh" -return_dict = False def check(conn, mnce, subparts): diff --git a/app/modules/monitoring_modules/http.py b/app/modules/monitoring_modules/http.py index 0ef3cbe..659b605 100644 --- a/app/modules/monitoring_modules/http.py +++ b/app/modules/monitoring_modules/http.py @@ -7,7 +7,6 @@ block = "network" part = "http" unit = "bool" connection = "" -return_dict = False def check(addr_host, port_list, cnfe): diff --git a/app/modules/monitoring_modules/load_ssh_linux.py b/app/modules/monitoring_modules/load_ssh_linux.py index 62a2ae3..29486fa 100644 --- a/app/modules/monitoring_modules/load_ssh_linux.py +++ b/app/modules/monitoring_modules/load_ssh_linux.py @@ -6,7 +6,6 @@ block = "hardware" part = "min_15_load" unit = "" connection = "ssh" -return_dict = False def check(conn, mnce, subparts): diff --git a/app/modules/monitoring_modules/memory_snmp_linux.py b/app/modules/monitoring_modules/memory_snmp_linux.py index 016c86a..2ea19ba 100644 --- a/app/modules/monitoring_modules/memory_snmp_linux.py +++ b/app/modules/monitoring_modules/memory_snmp_linux.py @@ -5,7 +5,6 @@ block = "hardware" part = "memory" unit = "%" connection = "snmp" -return_dict = False def check(conn, mnce, subparts): diff --git a/app/modules/monitoring_modules/memory_ssh_linux.py b/app/modules/monitoring_modules/memory_ssh_linux.py index f7e88a4..033443c 100644 --- a/app/modules/monitoring_modules/memory_ssh_linux.py +++ b/app/modules/monitoring_modules/memory_ssh_linux.py @@ -8,7 +8,6 @@ block = "hardware" part = "memory" unit = "%" connection = "ssh" -return_dict = False def check(conn, mnce, subparts): diff --git a/app/modules/monitoring_modules/ping.py b/app/modules/monitoring_modules/ping.py index 7a69e2d..c433507 100644 --- a/app/modules/monitoring_modules/ping.py +++ b/app/modules/monitoring_modules/ping.py @@ -8,7 +8,6 @@ block = "network" part = "ping" unit = "bool" connection = "" -return_dict = False def check(addr_host, port_list, cnfe): diff --git a/app/modules/monitoring_modules/smtp.py b/app/modules/monitoring_modules/smtp.py index a6f19b9..fefb8c4 100644 --- a/app/modules/monitoring_modules/smtp.py +++ b/app/modules/monitoring_modules/smtp.py @@ -7,7 +7,6 @@ block = "network" part = "smtp" unit = "bool" connection = "" -return_dict = True def check(addr_host, port_list, cnfe): diff --git a/app/modules/monitoring_modules/swap_snmp_linux.py b/app/modules/monitoring_modules/swap_snmp_linux.py index d708eb9..12f61a0 100644 --- a/app/modules/monitoring_modules/swap_snmp_linux.py +++ b/app/modules/monitoring_modules/swap_snmp_linux.py @@ -5,7 +5,6 @@ block = "hardware" part = "swap" unit = "%" connection = "snmp" -return_dict = False def check(conn, mnce, subparts): diff --git a/app/modules/monitoring_modules/swap_ssh_linux.py b/app/modules/monitoring_modules/swap_ssh_linux.py index c3805fe..14b81a7 100644 --- a/app/modules/monitoring_modules/swap_ssh_linux.py +++ b/app/modules/monitoring_modules/swap_ssh_linux.py @@ -6,7 +6,6 @@ block = "hardware" part = "swap" unit = "%" connection = "ssh" -return_dict = False def check(conn, mnce, subparts): diff --git a/app/modules/monitoring_modules/updated_packages_ssh_linux.py b/app/modules/monitoring_modules/updated_packages_ssh_linux.py index 7434d4d..cd9e4a6 100644 --- a/app/modules/monitoring_modules/updated_packages_ssh_linux.py +++ b/app/modules/monitoring_modules/updated_packages_ssh_linux.py @@ -6,7 +6,6 @@ block = "software" part = "updated_packages" unit = "bool" connection = "ssh" -return_dict = False def check(conn, mnce, subparts): diff --git a/app/mum.py b/app/mum.py index fbee41a..efc48bd 100755 --- a/app/mum.py +++ b/app/mum.py @@ -7,58 +7,15 @@ from bottle_websocket import GeventWebSocketServer from bottle_websocket import websocket from geventwebsocket import WebSocketError import json -import threading from module_loader import ModuleLoader +import websocket_func import argparse import os -# To Launch the nmap detection with a new thread -class ThreadDetect(threading.Thread): - def __init__(self, param, opt, ml, ws): - threading.Thread.__init__(self) - self.param = param # ip_range or hostname - self.opt = opt # nmap options - self.ml = ml # module_loader - self.ws = ws # websocket connection - - def run(self): - task_name = "Scanning " + self.param - self.ml.create_task(task_name) - scanned_ip = self.ml.run_nmap_detection(self.param, self.opt, self.ws) - if scanned_ip is not None: - try: - self.ws.send(json.dumps({"SUCCESS_MODULE": scanned_ip})) - except WebSocketError: - pass - for ip in json.loads(scanned_ip): - ml.run_all_detection_modules(ip) - monitoring_intructions = ml.get_db().get_monitoring_instructions(ip) - for instr in monitoring_intructions: - ml.add_to_waiting_list(instr) - self.ml.remove_task(task_name) - """ - # 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, self.ws) - monitoring_intructions = db.get_monitoring_instructions(ip) - for instr in monitoring_intructions: - process_monitoring.add_to_waiting_list(instr) - #module_loader.run_all_monitoring_modules("unix", conn, db, self.ws) - # adding entries on process monitoring - """ - - -# Launching of the detection after getting a ip range. -def start_first_detection(args, ml, ws): - t = ThreadDetect(args['ip_range'], args['nmap_options'], ml, ws) - t.start() - @route('/') def index(section='home'): return template('index') - @route('/dashboard.html') def angular(): return template('dashboard') @@ -127,72 +84,10 @@ def receive(ws): if response is not None: msg = json.loads(response) for code in msg: - if code == "NMAP_SCAN_DEMAND": # asked from scan page - if os.getegid() != 0: - print "Error: Cannot run nmap without root privileges." - ws.send(json.dumps({"ERROR": "Nmap needs to be root to be executed."})) - else: - start_first_detection(msg["NMAP_SCAN_DEMAND"], ml, ws) - elif code == "CREATE_EMPTY_HOST": # asked from scan page - ml.create_empty_host(msg["CREATE_EMPTY_HOST"]) - ws.send(json.dumps({"SUCCESS_MODULE": "Creation of new host"})) - elif code == "LAUNCH_FULL_DETECTION": # asked from hostpage - suceess_detection = ml.run_all_detection_modules(msg["LAUNCH_FULL_DETECTION"]) - if suceess_detection: - ws.send(json.dumps({"SUCCESS_MODULE": "Full detection"})) - else: - ws.send(json.dumps({"ERROR": "Full detection has failed (is SSH well configured?)"})) - elif code == "GET_HOSTS": # asked from head controller - db = ml.get_db() - ws.send(json.dumps({"RES_GET_HOSTS": db.get_hosts()})) - elif code == "GET_HOST_INFO": # asked from hostpage - dict_host_info = ml.get_host_info(msg["GET_HOST_INFO"]) - dict_host_info['loaded_moni_mod'] = ml.get_info_mod_monitoring() - ws.send(json.dumps({"RES_INFO_HOST": dict_host_info})) - elif code == "REM_HOST": - ml.remove_host(msg["REM_HOST"]) - ws.send(json.dumps({"RES_REM_HOST": True})) - elif code == "CALL_FUNC_DB": # asked when the request can directly pass by database - res = ml.launch_db_function(msg["CALL_FUNC_DB"]) - msg = json.dumps({"RES_CALL_FUNC_DB": { - "func": msg["CALL_FUNC_DB"]['func'], - "res": res - }}) - ws.send(msg) - elif code == "GET_LOADED_CONN_MOD": # asked from hostpage, at the connection configuration - ws.send(json.dumps({"RES_GET_LOADED_CONN_MOD": ml.get_info_mod_conn()})) - elif code == "GET_LOADED_NOTIF_MOD": # asekd from notification parameters page - ws.send(json.dumps({"RES_GET_LOADED_NOTIF_MOD": ml.get_info_mod_notification()})) - elif code == "GET_ALL_SUBSCRIPTIONS": # asekd from notification parameters page - ws.send(json.dumps({"RES_GET_ALL_SUBSCRIPTIONS": ml.get_all_subscriptions()})) - elif code == "SET_IDLE_STATE": # asked from hostpage - ml.set_idling_state(msg["SET_IDLE_STATE"]) - dict_host_info = ml.get_host_info(msg["SET_IDLE_STATE"]) - dict_host_info['loaded_moni_mod'] = ml.get_info_mod_monitoring() - ws.send(json.dumps({"RES_INFO_HOST": dict_host_info})) - ws.send(json.dumps({"RES_GET_HOSTS": ml.get_db().get_hosts()})) - elif code == "SET_MOD_ACTIVATION": # asked from hostpage, at the block activation conf - ml.update_activated_modules(msg["SET_MOD_ACTIVATION"]) - ws.send(json.dumps({"RES_GET_HOSTS": ml.db.get_hosts()})) - elif code == "TEST_CONN": # asked from hostpage, at the connection configuration modal - try: - ml.test_connection(msg["TEST_CONN"]["addr_host"], - msg["TEST_CONN"]["conn_mod_name"]) - ws.send(json_dumps({"RES_TEST_CONN": True})) - except Exception: - ws.send(json_dumps({"RES_TEST_CONN": False})) - elif code == "SET_CONF_MOD": # asked from hostpage, at the monitoring module configuration - ml.set_conf_moni_mod(msg["SET_CONF_MOD"]) - elif code == "CHECK_NOW": # asekd from hostpage - args = msg["CHECK_NOW"] - ml.run_one_monitoring_module(args['mod_name'], args['addr_host']) - ws.send(json.dumps({"RES_INFO_HOST": ml.get_host_info(args['addr_host'])})) - elif code == "GET_KEYS_LIST": # asked from hostpage, at the connection configuration - ws.send(json.dumps({"KEYS_LIST": ml.get_public_keys_list()})) - elif code == "TASK_LIST": # asked from the header controller - ws.send(json.dumps({"RES_TASK_LIST": ml.get_db().get_task_list()})) - else: - break + try: + getattr(websocket_func, code)(msg, ws, ml) + except AttributeError: + print "Unknown websocket code: " + code except WebSocketError: # Should be WebSocketError when closing the connection ml.get_websocket_container().remove_websocket(ws) break diff --git a/app/websocket_func.py b/app/websocket_func.py new file mode 100644 index 0000000..83552eb --- /dev/null +++ b/app/websocket_func.py @@ -0,0 +1,168 @@ +# -*- coding: utf8 -*- + +__author__ = 'aguilbaud' +import os +import json +import threading +from geventwebsocket import WebSocketError + +# ---- Definitions for the nmap detection procedure ---- + +# To Launch the nmap detection with a new thread +class ThreadDetect(threading.Thread): + def __init__(self, param, opt, ml, ws): + threading.Thread.__init__(self) + self.param = param # ip_range or hostname + self.opt = opt # nmap options + self.ml = ml # module_loader + self.ws = ws # websocket connection + + def run(self): + task_name = "Scanning " + self.param + self.ml.create_task(task_name) + scanned_ip = self.ml.run_nmap_detection(self.param, self.opt, self.ws) + if scanned_ip is not None: + try: + self.ws.send(json.dumps({"SUCCESS_MODULE": scanned_ip})) + except WebSocketError: + pass + for ip in json.loads(scanned_ip): + self.ml.run_all_detection_modules(ip) + monitoring_intructions = self.ml.get_db().get_monitoring_instructions(ip) + for instr in monitoring_intructions: + self.ml.add_to_waiting_list(instr) + self.ml.remove_task(task_name) + """ + # 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, self.ws) + monitoring_intructions = db.get_monitoring_instructions(ip) + for instr in monitoring_intructions: + process_monitoring.add_to_waiting_list(instr) + #module_loader.run_all_monitoring_modules("unix", conn, db, self.ws) + # adding entries on process monitoring + """ + + +# Launching of the detection after getting a ip range. +def start_first_detection(args, ml, ws): + t = ThreadDetect(args['ip_range'], args['nmap_options'], ml, ws) + t.start() + + +# ---- Functions corresponding to a websocket code ---- + +# asked from scan page +def NMAP_SCAN_DEMAND(msg, ws, ml): + if os.getegid() != 0: + print "Error: Cannot run nmap without root privileges." + ws.send(json.dumps({"ERROR": "Cannot run nmap without root privileges."})) + else: + start_first_detection(msg["NMAP_SCAN_DEMAND"], ml, ws) + + +# asked from scan page +def CREATE_EMPTY_HOST(msg, ws, ml): + ml.create_empty_host(msg["CREATE_EMPTY_HOST"]) + ws.send(json.dumps({"SUCCESS_MODULE": "Creation of new host"})) + + +# asked from hostpage +def LAUNCH_FULL_DETECTION(msg, ws, ml): + suceess_detection = ml.run_all_detection_modules(msg["LAUNCH_FULL_DETECTION"]) + if suceess_detection: + ws.send(json.dumps({"SUCCESS_MODULE": "Full detection"})) + else: + ws.send(json.dumps({"ERROR": "Full detection has failed (is SSH well configured?)"})) + + +# asked from head controller +def GET_HOSTS(msg, ws, ml): + db = ml.get_db() + ws.send(json.dumps({"RES_GET_HOSTS": db.get_hosts()})) + + +# asked from hostpage +def GET_HOST_INFO(msg, ws, ml): + dict_host_info = ml.get_host_info(msg["GET_HOST_INFO"]) + dict_host_info['loaded_moni_mod'] = ml.get_info_mod_monitoring() + ws.send(json.dumps({"RES_INFO_HOST": dict_host_info})) + + +# asked from hostpage +def REM_HOST(msg, ws, ml): + ml.remove_host(msg["REM_HOST"]) + ws.send(json.dumps({"RES_REM_HOST": True})) + + +# asked when the request can directly pass by database +def CALL_FUNC_DB(msg, ws, ml): + res = ml.launch_db_function(msg["CALL_FUNC_DB"]) + msg = json.dumps({"RES_CALL_FUNC_DB": { + "func": msg["CALL_FUNC_DB"]['func'], + "res": res + }}) + ws.send(msg) + + +# asked from hostpage, at the connection configuration +def GET_LOADED_CONN_MOD(msg, ws, ml): + ws.send(json.dumps({"RES_GET_LOADED_CONN_MOD": ml.get_info_mod_conn()})) + + +# asekd from notification parameters page +def GET_LOADED_NOTIF_MOD(msg, ws, ml): + ws.send(json.dumps({"RES_GET_LOADED_NOTIF_MOD": ml.get_info_mod_notification()})) + + +# asekd from notification parameters page +def GET_ALL_SUBSCRIPTIONS(msg, ws, ml): + ws.send(json.dumps({"RES_GET_ALL_SUBSCRIPTIONS": ml.get_all_subscriptions()})) + + +# asked from hostpage +def SET_IDLE_STATE(msg, ws, ml): + ml.set_idling_state(msg["SET_IDLE_STATE"]) + dict_host_info = ml.get_host_info(msg["SET_IDLE_STATE"]) + dict_host_info['loaded_moni_mod'] = ml.get_info_mod_monitoring() + ws.send(json.dumps({"RES_INFO_HOST": dict_host_info})) + ws.send(json.dumps({"RES_GET_HOSTS": ml.get_db().get_hosts()})) + + +# asked from hostpage, at the block activation conf +def SET_MOD_ACTIVATION(msg, ws, ml): + ml.update_activated_modules(msg["SET_MOD_ACTIVATION"]) + ws.send(json.dumps({"RES_GET_HOSTS": ml.db.get_hosts()})) + + +# asked from hostpage, at the connection configuration modal +def TEST_CONN(msg, ws, ml): + try: + ml.test_connection(msg["TEST_CONN"]["addr_host"], + msg["TEST_CONN"]["conn_mod_name"]) + ws.send(json.dumps({"RES_TEST_CONN": True})) + except Exception: + ws.send(json.dumps({"RES_TEST_CONN": False})) + + +# asked from hostpage, at the monitoring module configuration +def SET_CONF_MOD(msg, ws, ml): + ml.set_conf_moni_mod(msg["SET_CONF_MOD"]) + + +# asekd from hostpage +def CHECK_NOW(msg, ws, ml): + args = msg["CHECK_NOW"] + ml.run_one_monitoring_module(args['mod_name'], args['addr_host']) + ws.send(json.dumps({"RES_INFO_HOST": ml.get_host_info(args['addr_host'])})) + + +# asked from hostpage, at the connection configuration +def GET_KEYS_LIST(msg, ws, ml): + ws.send(json.dumps({"KEYS_LIST": ml.get_public_keys_list()})) + + +# asked from the header controller +def TASK_LIST(msg, ws, ml): + ws.send(json.dumps({"RES_TASK_LIST": ml.get_db().get_task_list()})) diff --git a/views/dashboard.html b/views/dashboard.html index 22f9ffa..5dbca83 100644 --- a/views/dashboard.html +++ b/views/dashboard.html @@ -64,7 +64,15 @@ </div> <div ng-show="items.length == 0"> - <p>No hosts for the moment. <a href="#scan">Scan for new hosts now!</a></p> + <p> + No machines are under monitoring for the moment... + </p> + <p> + If this is the first execution, we recommand to parameter the <a href="#settings">global settings</a> first. + </p> + <p> + If you are ready, <a href="#scan">scan for new machines</a>! + </p> </div> </div> \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.