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 b0970805803825d20468ef8dbf87a38617a45443 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Tue Apr 21 17:58:00 2015 +0200 removed known ports verification because was causing random locks on db + refactored modules to move db dependency on module_loader --- app/module_loader.py | 23 ++++++------ .../monitoring_modules/15_min_load_snmp_linux.py | 4 +-- app/modules/monitoring_modules/cpu.py | 4 +-- app/modules/monitoring_modules/cpu_glances.py | 4 +-- app/modules/monitoring_modules/cpu_snmp_linux.py | 4 +-- app/modules/monitoring_modules/disk.py | 4 +-- app/modules/monitoring_modules/disk_snmp_linux.py | 4 +-- app/modules/monitoring_modules/load.py | 4 +-- app/modules/monitoring_modules/memory.py | 4 +-- .../monitoring_modules/memory_snmp_linux.py | 4 +-- app/modules/monitoring_modules/ping.py | 4 +-- app/modules/monitoring_modules/smtp.py | 4 +-- app/modules/monitoring_modules/swap.py | 4 +-- app/modules/monitoring_modules/swap_snmp_linux.py | 4 +-- app/modules/monitoring_modules/updated_packages.py | 4 +-- app/modules/nmap_detection.py | 6 ++-- app/modules/storage_modules/shelve_db.py | 41 ++-------------------- app/mum.py | 2 +- app/process_monitoring.py | 11 ++---- static/js/controllers/dashboardCtrl.js | 2 +- views/dashboard.html | 2 +- 21 files changed, 48 insertions(+), 95 deletions(-) diff --git a/app/module_loader.py b/app/module_loader.py index fb89d0b..26a539e 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -52,12 +52,13 @@ class ModuleLoader: def get_websocket_container(self): return self.wsc - + """ def get_all_known_ports(self): res = [] for conn_mod in self.loaded_mod_conn: res.append(self.loaded_mod_conn[conn_mod]['known_port']) return res + """ def create_task(self, task_id): self.db.store_task(task_id) @@ -93,7 +94,6 @@ class ModuleLoader: ws, self.get_conection_modules_list(), self.get_monitoring_modules_list(), - self.get_all_known_ports(), modules.HostNotFoundException) try: if re.search('^\d{1,3}(-\d{1,3})?[.]\d{1,3}(-\d{1,3})?[.]\d{1,3}(-\d{1,3})?[.]\d{1,3}(-\d{1,3})?$', param): @@ -122,8 +122,7 @@ class ModuleLoader: self.db.add_host(addr_host, json.dumps(fake_nmap_res), self.get_conection_modules_list(), - self.get_monitoring_modules_list(), - self.get_all_known_ports()) + self.get_monitoring_modules_list()) monitoring_intructions = self.db.get_monitoring_instructions(addr_host) for instr in monitoring_intructions: self.add_to_waiting_list(instr) @@ -270,19 +269,17 @@ class ModuleLoader: print "Error : external monitoring module " + mod_name + " could not have been loaded. Traceback:" print traceback.format_exc() - def run_one_monitoring_module(self, part_name, addr_host, conn, db): + def run_one_monitoring_module(self, part_name, addr_host): """ Instanciates and runs one monitoring_module of the package corresponding to the operating system entered in parameters. :param part_name: the name of the part to check - :param conn: an instance of a connection module - :param db: an instance of a storage module + :param addr_host: the IP address of the host """ - if db is None: - db = self.get_db() if part_name == 'ping': - dict_notif = getattr(self.loaded_mod_moni['ping']['modules']['ping']['imported'], - 'check')(db, addr_host) + res_check = getattr(self.loaded_mod_moni['ping']['modules']['ping']['imported'], + 'check')(addr_host) + dict_notif = self.db.add_check(addr_host, part_name, res_check) self.run_notification_modules(dict_notif) else: # getting all availiable connections for this part to check @@ -299,10 +296,10 @@ class ModuleLoader: # if this monitoring module is compatible for the current connection try: conn_inst = self.create_connection(addr_host, conf_conn[i]) - dict_notif = getattr(self.loaded_mod_moni[part_name]['modules'][mod]['imported'], + res_check = getattr(self.loaded_mod_moni[part_name]['modules'][mod]['imported'], 'check')(conn_inst, - db, modules.ModuleNotCompatibleException) + dict_notif = self.db.add_check(conn_inst.get_addr_host(), part_name, res_check) self.run_notification_modules(dict_notif) check_done = True except Exception: 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 4275b85..00ab092 100644 --- a/app/modules/monitoring_modules/15_min_load_snmp_linux.py +++ b/app/modules/monitoring_modules/15_min_load_snmp_linux.py @@ -8,7 +8,7 @@ unit = "" connection = "snmp" -def check(conn, db, mnce): +def check(conn, mnce): oid = ".1.3.6.1.4.1.2021.10.1.3.3" load = float(conn.exec_command(oid)) - return db.add_check(conn.get_addr_host(), part, load) \ No newline at end of file + return load \ No newline at end of file diff --git a/app/modules/monitoring_modules/cpu.py b/app/modules/monitoring_modules/cpu.py index b733cad..7127125 100644 --- a/app/modules/monitoring_modules/cpu.py +++ b/app/modules/monitoring_modules/cpu.py @@ -8,7 +8,7 @@ unit = "%" connection = "ssh" -def check(conn, db, mnce): +def check(conn, mnce): """ Returns the greatest between the user and system CPU charge """ @@ -30,4 +30,4 @@ def check(conn, db, mnce): field_sys = field_sys.replace(',', '.') system_cpu_charge = float(field_sys) res_cpu = max(user_cpu_charge, system_cpu_charge) - return db.add_check(conn.get_addr_host(), 'cpu', res_cpu) \ No newline at end of file + return res_cpu \ No newline at end of file diff --git a/app/modules/monitoring_modules/cpu_glances.py b/app/modules/monitoring_modules/cpu_glances.py index a16ac18..b7cc8da 100644 --- a/app/modules/monitoring_modules/cpu_glances.py +++ b/app/modules/monitoring_modules/cpu_glances.py @@ -10,7 +10,7 @@ unit = "%" connection = "glances" -def check(conn, db, mnce): +def check(conn, mnce): """ Returns the greatest between the user and system CPU charge """ @@ -27,4 +27,4 @@ def check(conn, db, mnce): ) raise exception_inst res_cpu = max(user_cpu_charge, system_cpu_charge) - return db.add_check(conn.get_addr_host(), 'cpu', res_cpu) \ No newline at end of file + return res_cpu \ No newline at end of file diff --git a/app/modules/monitoring_modules/cpu_snmp_linux.py b/app/modules/monitoring_modules/cpu_snmp_linux.py index e17f638..fad9f05 100644 --- a/app/modules/monitoring_modules/cpu_snmp_linux.py +++ b/app/modules/monitoring_modules/cpu_snmp_linux.py @@ -8,7 +8,7 @@ unit = "%" connection = "snmp" -def check(conn, db, mnce): +def check(conn, mnce): """ Check the greatest between the user and system CPU charge """ @@ -17,4 +17,4 @@ def check(conn, db, mnce): oid = ".1.3.6.1.4.1.2021.11.10.0" system_cpu_charge = int(conn.exec_command(oid)) res_cpu = max(user_cpu_charge, system_cpu_charge) - return db.add_check(conn.get_addr_host(), part, res_cpu) \ No newline at end of file + return res_cpu \ No newline at end of file diff --git a/app/modules/monitoring_modules/disk.py b/app/modules/monitoring_modules/disk.py index ea6cd5f..73b0129 100644 --- a/app/modules/monitoring_modules/disk.py +++ b/app/modules/monitoring_modules/disk.py @@ -10,7 +10,7 @@ unit = "%" connection = "ssh" -def check(conn, db, mnce): +def check(conn, mnce): cmd = "df -h" stdout = conn.exec_command(cmd) disk_used = None @@ -29,4 +29,4 @@ def check(conn, db, mnce): ) raise exception_inst res_check = int(disk_used) - return db.add_check(conn.get_addr_host(), 'disk', res_check) \ No newline at end of file + return res_check \ No newline at end of file diff --git a/app/modules/monitoring_modules/disk_snmp_linux.py b/app/modules/monitoring_modules/disk_snmp_linux.py index d5a584a..255b6df 100644 --- a/app/modules/monitoring_modules/disk_snmp_linux.py +++ b/app/modules/monitoring_modules/disk_snmp_linux.py @@ -7,10 +7,10 @@ unit = "%" connection = "snmp" -def check(conn, db, mnce): +def check(conn, mnce): oid = ".1.3.6.1.4.1.2021.9.1.7.1" total_space_on_disk = float(conn.exec_command(oid)) oid = ".1.3.6.1.4.1.2021.9.1.8.1" disk_used = float(conn.exec_command(oid)) percent_disk_used = round((disk_used * 100) / total_space_on_disk, 2) - return db.add_check(conn.get_addr_host(), part, percent_disk_used) \ No newline at end of file + return percent_disk_used \ No newline at end of file diff --git a/app/modules/monitoring_modules/load.py b/app/modules/monitoring_modules/load.py index ceadd21..49e7b66 100644 --- a/app/modules/monitoring_modules/load.py +++ b/app/modules/monitoring_modules/load.py @@ -8,7 +8,7 @@ unit = "" connection = "ssh" -def check(conn, db, mnce): +def check(conn, mnce): """ Returns the greatest between the user and system CPU charge """ @@ -24,4 +24,4 @@ def check(conn, db, mnce): field_load_avg = fields[i+3] field_load_avg = field_load_avg.replace(',', '.') load_avg = float(field_load_avg) - return db.add_check(conn.get_addr_host(), 'load', load_avg) \ No newline at end of file + return load_avg \ No newline at end of file diff --git a/app/modules/monitoring_modules/memory.py b/app/modules/monitoring_modules/memory.py index 27f8423..3f2a0ea 100644 --- a/app/modules/monitoring_modules/memory.py +++ b/app/modules/monitoring_modules/memory.py @@ -10,7 +10,7 @@ unit = "%" connection = "ssh" -def check(conn, db, mnce): +def check(conn, mnce): cmd = "cat /proc/meminfo" stdout = conn.exec_command(cmd) memfree = 0 @@ -28,4 +28,4 @@ def check(conn, db, mnce): ) raise exception_inst res_check = memused * 100 / int(memtotal) - return db.add_check(conn.get_addr_host(), "memory", res_check) \ No newline at end of file + return res_check \ No newline at end of file diff --git a/app/modules/monitoring_modules/memory_snmp_linux.py b/app/modules/monitoring_modules/memory_snmp_linux.py index 9459346..98b7e5c 100644 --- a/app/modules/monitoring_modules/memory_snmp_linux.py +++ b/app/modules/monitoring_modules/memory_snmp_linux.py @@ -7,10 +7,10 @@ unit = "%" connection = "snmp" -def check(conn, db, mnce): +def check(conn, mnce): oid = ".1.3.6.1.4.1.2021.4.5.0" total_mem = float(conn.exec_command(oid)) oid = ".1.3.6.1.4.1.2021.4.6.0" mem_used = float(conn.exec_command(oid)) percent_mem_used = round((mem_used * 100) / total_mem, 2) - return db.add_check(conn.get_addr_host(), part, percent_mem_used) \ No newline at end of file + return percent_mem_used \ No newline at end of file diff --git a/app/modules/monitoring_modules/ping.py b/app/modules/monitoring_modules/ping.py index 80883ae..a3da3c1 100644 --- a/app/modules/monitoring_modules/ping.py +++ b/app/modules/monitoring_modules/ping.py @@ -10,7 +10,7 @@ unit = "bool" connection = "" -def check(db, addr_host): +def check(addr_host): res_check = False try: child = pexpect.spawn('ping '+ addr_host + ' -c 1') @@ -24,4 +24,4 @@ def check(db, addr_host): except pexpect.TIMEOUT: res_check = False finally: - return db.add_check(addr_host, "ping", res_check) \ No newline at end of file + return res_check \ No newline at end of file diff --git a/app/modules/monitoring_modules/smtp.py b/app/modules/monitoring_modules/smtp.py index 80cb00f..bba24ff 100644 --- a/app/modules/monitoring_modules/smtp.py +++ b/app/modules/monitoring_modules/smtp.py @@ -8,11 +8,11 @@ part = "smtp" unit = "bool" connection = "" -def check(db, addr_host, smtp_port): +def check(addr_host, smtp_port): res_smtp_check = True try: s = smtplib.SMTP(addr_host, smtp_port) except Exception: res_smtp_check = False finally: - return db.add_check(addr_host, part, res_smtp_check) \ No newline at end of file + return res_smtp_check \ No newline at end of file diff --git a/app/modules/monitoring_modules/swap.py b/app/modules/monitoring_modules/swap.py index 696415a..c796578 100644 --- a/app/modules/monitoring_modules/swap.py +++ b/app/modules/monitoring_modules/swap.py @@ -8,7 +8,7 @@ unit = "%" connection = "ssh" -def check(conn, db, mnce): +def check(conn, mnce): cmd = "free -m" stdout = conn.exec_command(cmd) swap_total = 0 @@ -25,4 +25,4 @@ def check(conn, db, mnce): "swap", conn.get_addr_host() ) raise exception_inst - return db.add_check(conn.get_addr_host(), 'swap', res_swap) \ No newline at end of file + return res_swap \ No newline at end of file diff --git a/app/modules/monitoring_modules/swap_snmp_linux.py b/app/modules/monitoring_modules/swap_snmp_linux.py index cbb60a8..2e85f3d 100644 --- a/app/modules/monitoring_modules/swap_snmp_linux.py +++ b/app/modules/monitoring_modules/swap_snmp_linux.py @@ -7,10 +7,10 @@ unit = "%" connection = "snmp" -def check(conn, db, mnce): +def check(conn, mnce): oid = ".1.3.6.1.4.1.2021.4.3.0" total_swap = float(conn.exec_command(oid)) oid = ".1.3.6.1.4.1.2021.4.4.0" swap_used = total_swap - float(conn.exec_command(oid)) percent_swap_used = round( (swap_used * 100) / total_swap, 2) - return db.add_check(conn.get_addr_host(), part, percent_swap_used) \ No newline at end of file + return percent_swap_used \ No newline at end of file diff --git a/app/modules/monitoring_modules/updated_packages.py b/app/modules/monitoring_modules/updated_packages.py index 3717577..67be4e9 100644 --- a/app/modules/monitoring_modules/updated_packages.py +++ b/app/modules/monitoring_modules/updated_packages.py @@ -8,9 +8,9 @@ unit = "bool" connection = "ssh" -def check(conn, db, mnce): +def check(conn, mnce): cmd = "apt-get upgrade -s" stdout = conn.exec_command(cmd) tab_res = stdout.split(':') res_check = len(tab_res) <= 2 - return db.add_check(conn.get_addr_host(), "updated_packages", res_check) \ No newline at end of file + return res_check \ No newline at end of file diff --git a/app/modules/nmap_detection.py b/app/modules/nmap_detection.py index 0c08fb4..532d2db 100644 --- a/app/modules/nmap_detection.py +++ b/app/modules/nmap_detection.py @@ -8,7 +8,7 @@ from string import letters class nmap_detection: - def __init__(self, opt, db, ws, list_mod_conn, dict_mod_monitoring, known_ports, hnfe): + def __init__(self, opt, db, ws, list_mod_conn, dict_mod_monitoring, hnfe): self.opt = opt self.db = db self.ws = ws @@ -16,7 +16,6 @@ class nmap_detection: self.scanned_ip = [] self.list_mod_conn = list_mod_conn self.dict_mod_monitoring = dict_mod_monitoring - self.known_ports = known_ports self.HostNotFoundException = hnfe # function for splitting the different ranges of the IP adress @@ -170,6 +169,5 @@ class nmap_detection: self.db.add_host(dict_host['addr'], json.dumps(dict_host), self.list_mod_conn, - self.dict_mod_monitoring, - self.known_ports) + self.dict_mod_monitoring) self.scanned_ip.append(dict_host['addr']) \ 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 2e7f768..290d35d 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -150,7 +150,7 @@ class shelve_db: finally: self.close_db() - def add_host(self, addr_host, nmap_res, conn_infos, dict_mod_info, known_ports): + def add_host(self, addr_host, nmap_res, conn_infos, dict_mod_info): """ Called by the nmap_detection module or directly by the module loader if no detection was asked. Add and save a new host after its first nmap detection @@ -175,9 +175,6 @@ class shelve_db: # Preconfiguration self.db["hosts"][addr_host]["conf"] = {} nmap_res_data = json.loads(nmap_res) - nmap_res_data['openports'] = self.check_if_known_port_is_open(addr_host, - known_ports, - nmap_res_data['openports']) self.db["hosts"][addr_host]['detected']['nmap'] = json.dumps(nmap_res_data) self.db["hosts"][addr_host]["conf"]["connections"] = self.init_conn(nmap_res_data, conn_infos) os_host = nmap_res_data['os'] @@ -204,40 +201,6 @@ class shelve_db: self.close_db() @staticmethod - def check_if_known_port_is_open(addr_host, known_ports, openports): - """ - For each known_port that may not be detected by nmap, we will try to verify if this port is open or not by - opening a socket. - :param addr_host: the IP address of the host - :param known_ports: a list containing integers representing the known_ports to verify. - :param openports: a dictionary containing the nmap result of the detected open ports - :return: openports attribute with new fields for each open port newly verified. - """ - new_port_dict_list = [] - try: - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - for port_id in known_ports: - print port_id - port_id_was_detected = False - for port_dict in openports: - if port_dict['portid'] == port_id: - print 1 - port_id_was_detected = True - if not port_id_was_detected: - try: - if sock.connect_ex((addr_host, port_id)) == 0: - print 2 - new_port_dict_list.append({"portname": "", "portid": port_id}) - except Exception: - pass - print new_port_dict_list - for new_port_dict in new_port_dict_list: - openports.append(new_port_dict) - print openports - finally: - return openports - - @staticmethod def init_conn(dict_nmap_res, conn_infos): """ Returns an initialization for the connection configuration on a host. @@ -906,7 +869,7 @@ class shelve_db: title = "[Mum] " + status + " for " + addr_host + " " + moni_mod msg = "Mum reported a " + status + " value from the " + moni_mod + " module. " msg += "The following users will be notified: " - msg += self.db['hosts'][addr_host]['subscribers'] + msg += str(self.db['hosts'][addr_host]['conf']['subscribers']) dict_notif = {} notif_type = "" if status == 'warning': diff --git a/app/mum.py b/app/mum.py index dc79af3..a9bcd3e 100755 --- a/app/mum.py +++ b/app/mum.py @@ -178,7 +178,7 @@ def receive(ws): 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'], None, None) + ml.run_one_monitoring_module(args['mod_name'], 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": diff --git a/app/process_monitoring.py b/app/process_monitoring.py index 9085da7..efafd13 100644 --- a/app/process_monitoring.py +++ b/app/process_monitoring.py @@ -132,12 +132,7 @@ class RunMonitoring(threading.Thread): def run(self): sys.stdout.flush() for dict_mod in self.list_dict_mod: - if dict_mod['mod_name'] == 'ping': - print "Launching " + str(dict_mod['mod_name']) + " request on " + str(dict_mod['addr']) - sys.stdout.flush() - self.ml.run_one_monitoring_module(dict_mod['mod_name'], dict_mod['addr'], None, None) - else: - 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) + #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']) self.wsc.notify_state_change() \ No newline at end of file diff --git a/static/js/controllers/dashboardCtrl.js b/static/js/controllers/dashboardCtrl.js index 6b5ffc9..8fab9e6 100644 --- a/static/js/controllers/dashboardCtrl.js +++ b/static/js/controllers/dashboardCtrl.js @@ -14,7 +14,7 @@ mumApp.controller('dashboardCtrl', function($scope, $filter, $routeParams, DataH "name":"www.example.com", "status":val, //"success" or "warning" or "danger" or "" "group":[ "all", ...], - "last_check":val //UNIX time + "last_check":string "subscribers":{ "uid":val, "priority":val diff --git a/views/dashboard.html b/views/dashboard.html index b50abb6..e3bfb08 100644 --- a/views/dashboard.html +++ b/views/dashboard.html @@ -69,7 +69,7 @@ <tbody> <tr ng-repeat="item in items | orderBy:sort.sortingOrder:sort.reverse | - filter:{addr:addr_filter, name:name_filter, group:filtering_group} | + filter:{addr:addr_filter, name:name_filter, group:group_filter} | filter:filtering_status" class={{item.status}}> <!-- group.name:group_filter --> <td><a href="#/hostpage/{{item.addr}}">{{item.addr}}</a></td> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.