branch develop updated (aad9726 -> b1f4907)
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 aad9726 dashboard: multiple params separated by ',' on URL for status_filter + hostpage: modal for modifying the detected open ports new 7872155 snmp_walk connection added + monitoring modules can return a dictionary of values (must specify 'return_dict' attribute) new b1f4907 hostpage: detected configuration separated from nmap detection. subparts can be checked from the detected config, and the monitoring will check the selected subparts 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 b1f49077b42b54b817c18c0bce0c395f9f431c33 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Apr 29 10:53:26 2015 +0200 hostpage: detected configuration separated from nmap detection. subparts can be checked from the detected config, and the monitoring will check the selected subparts commit 7872155801d2b11a270b8dbcbfa592d1c6093427 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Tue Apr 28 16:03:35 2015 +0200 snmp_walk connection added + monitoring modules can return a dictionary of values (must specify 'return_dict' attribute) Summary of changes: app/module_loader.py | 5 +- .../connection_modules/{snmp.py => snmp_walk.py} | 21 ++-- app/modules/detection_modules/drive_detection.py | 3 +- app/modules/detection_modules/drive_snmp_linux.py | 14 +++ .../monitoring_modules/15_min_load_snmp_linux.py | 3 +- app/modules/monitoring_modules/cpu_glances.py | 3 +- app/modules/monitoring_modules/cpu_snmp_linux.py | 3 +- app/modules/monitoring_modules/cpu_ssh_linux.py | 3 +- app/modules/monitoring_modules/disk_snmp_linux.py | 39 +++--- app/modules/monitoring_modules/disk_ssh_linux.py | 3 +- app/modules/monitoring_modules/http.py | 26 ++-- app/modules/monitoring_modules/load_ssh_linux.py | 3 +- .../monitoring_modules/memory_snmp_linux.py | 3 +- app/modules/monitoring_modules/memory_ssh_linux.py | 3 +- app/modules/monitoring_modules/ping.py | 1 + app/modules/monitoring_modules/smtp.py | 24 ++-- app/modules/monitoring_modules/swap_snmp_linux.py | 3 +- app/modules/monitoring_modules/swap_ssh_linux.py | 3 +- .../updated_packages_ssh_linux.py | 3 +- app/modules/storage_modules/shelve_db.py | 140 ++++++++++++++------- static/js/controllers/hostPageCtrl.js | 35 +++++- views/hostpage.html | 45 +++++-- 22 files changed, 264 insertions(+), 122 deletions(-) copy app/modules/connection_modules/{snmp.py => snmp_walk.py} (66%) create mode 100644 app/modules/detection_modules/drive_snmp_linux.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 7872155801d2b11a270b8dbcbfa592d1c6093427 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Tue Apr 28 16:03:35 2015 +0200 snmp_walk connection added + monitoring modules can return a dictionary of values (must specify 'return_dict' attribute) --- app/module_loader.py | 5 +- app/modules/connection_modules/snmp_walk.py | 57 ++++++++++ .../monitoring_modules/15_min_load_snmp_linux.py | 3 +- app/modules/monitoring_modules/cpu_glances.py | 3 +- app/modules/monitoring_modules/cpu_snmp_linux.py | 3 +- app/modules/monitoring_modules/cpu_ssh_linux.py | 3 +- app/modules/monitoring_modules/disk_snmp_linux.py | 39 ++++--- app/modules/monitoring_modules/disk_ssh_linux.py | 3 +- app/modules/monitoring_modules/http.py | 26 +++-- app/modules/monitoring_modules/load_ssh_linux.py | 3 +- .../monitoring_modules/memory_snmp_linux.py | 3 +- app/modules/monitoring_modules/memory_ssh_linux.py | 3 +- app/modules/monitoring_modules/ping.py | 1 + app/modules/monitoring_modules/smtp.py | 24 ++-- app/modules/monitoring_modules/swap_snmp_linux.py | 3 +- app/modules/monitoring_modules/swap_ssh_linux.py | 3 +- .../updated_packages_ssh_linux.py | 3 +- app/modules/storage_modules/shelve_db.py | 121 +++++++++++++-------- static/js/controllers/hostPageCtrl.js | 16 ++- views/hostpage.html | 16 ++- 20 files changed, 236 insertions(+), 102 deletions(-) diff --git a/app/module_loader.py b/app/module_loader.py index bd78d61..dc59d3a 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -310,12 +310,14 @@ class ModuleLoader: # for each monitoring module, being from this part, activated for this host loaded_mod = self.loaded_mod_moni[part_name]['modules'][mod]['imported'] if getattr(loaded_mod, 'connection') == conf_conn[i]['conn_mod_name']: + subpart_list = self.db.get_subpart(addr_host, part_name) # if this monitoring module is compatible for the current connection try: conn_inst = self.create_connection(addr_host, conf_conn[i]) res_check = getattr(self.loaded_mod_moni[part_name]['modules'][mod]['imported'], 'check')(conn_inst, - modules.ModuleNotCompatibleException) + modules.ModuleNotCompatibleException, + subpart_list) dict_notif = self.db.add_check(conn_inst.get_addr_host(), part_name, res_check) self.run_notification_modules(dict_notif) check_done = True @@ -378,6 +380,7 @@ 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/connection_modules/snmp_walk.py b/app/modules/connection_modules/snmp_walk.py new file mode 100644 index 0000000..d9d8722 --- /dev/null +++ b/app/modules/connection_modules/snmp_walk.py @@ -0,0 +1,57 @@ +__author__ = 'aguilbaud' + +from pysnmp.entity.rfc3413.oneliner import cmdgen + + +def get_class_name(): + return "SNMPWalk" + + +class SNMPWalk: + def __init__(self, addr_host, params, key_loc, cnfe): + self.parameters = {"port": "int"} + self.params_stored = params + self.name = get_class_name() + self.addr_host = addr_host + self.known_port = 161 + self.CommandNotFoundException = cnfe + self.cmdGen = cmdgen.CommandGenerator() + + def get_name(self): + return self.name + + def get_addr_host(self): + # Called by monitoring modules + return self.addr_host + + def get_parameters(self): + return self.parameters + + def get_known_port(self): + return self.known_port + + def exec_command(self, cmd): + res = {} + errorIndication, errorStatus, errorIndex, varBindTable = self.cmdGen.nextCmd( + cmdgen.CommunityData('public'), + cmdgen.UdpTransportTarget((self.addr_host, int(self.params_stored['port']))), + cmd + ) + + # Check for errors and print out results + if errorIndication: + print(errorIndication) + else: + if errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBindTable[-1][int(errorIndex)-1] or '?' + )) + else: + for varBindTableRow in varBindTable: + for name, val in varBindTableRow: + res[name.prettyPrint()] = val.prettyPrint() + return res + + def disconnect(self): + self.cmdGen = None \ No newline at end of file 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 6334708..98dace9 100644 --- a/app/modules/monitoring_modules/15_min_load_snmp_linux.py +++ b/app/modules/monitoring_modules/15_min_load_snmp_linux.py @@ -6,9 +6,10 @@ block = "hardware" part = "min_15_load" unit = "" connection = "snmp" +return_dict = False -def check(conn, mnce): +def check(conn, mnce, subparts): # http://www.oid-info.com/get/1.3.6.1.4.1.2021.10.1.3 (.X) # X = 1 : 5 min load # X = 2 : 10 min load diff --git a/app/modules/monitoring_modules/cpu_glances.py b/app/modules/monitoring_modules/cpu_glances.py index b7cc8da..d634971 100644 --- a/app/modules/monitoring_modules/cpu_glances.py +++ b/app/modules/monitoring_modules/cpu_glances.py @@ -8,9 +8,10 @@ block = "hardware" part = "cpu" unit = "%" connection = "glances" +return_dict = False -def check(conn, mnce): +def check(conn, mnce, subparts): """ Returns the greatest between the user and system CPU charge """ diff --git a/app/modules/monitoring_modules/cpu_snmp_linux.py b/app/modules/monitoring_modules/cpu_snmp_linux.py index fa395e3..40203df 100644 --- a/app/modules/monitoring_modules/cpu_snmp_linux.py +++ b/app/modules/monitoring_modules/cpu_snmp_linux.py @@ -6,9 +6,10 @@ block = "hardware" part = "cpu" unit = "%" connection = "snmp" +return_dict = False -def check(conn, mnce): +def check(conn, mnce, subparts): """ Returns the greatest between the user and system CPU charge """ diff --git a/app/modules/monitoring_modules/cpu_ssh_linux.py b/app/modules/monitoring_modules/cpu_ssh_linux.py index 7127125..a1c7c94 100644 --- a/app/modules/monitoring_modules/cpu_ssh_linux.py +++ b/app/modules/monitoring_modules/cpu_ssh_linux.py @@ -6,9 +6,10 @@ block = "hardware" part = "cpu" unit = "%" connection = "ssh" +return_dict = False -def check(conn, mnce): +def check(conn, mnce, subparts): """ Returns the greatest between the user and system CPU charge """ diff --git a/app/modules/monitoring_modules/disk_snmp_linux.py b/app/modules/monitoring_modules/disk_snmp_linux.py index c18d153..a99eda3 100644 --- a/app/modules/monitoring_modules/disk_snmp_linux.py +++ b/app/modules/monitoring_modules/disk_snmp_linux.py @@ -4,21 +4,28 @@ compatible_os = ['linux'] block = "hardware" part = "disk" unit = "%" -connection = "snmp" +connection = "snmp_walk" +return_dict = True -def check(conn, mnce): - # http://www.oid-info.com/get/1.3.6.1.4.1.2021.9.1.7.1 - oid_available_space = ".1.3.6.1.4.1.2021.9.1.7.1" - total_space_on_disk = float(conn.exec_command(oid_available_space)) - # http://www.oid-info.com/get/1.3.6.1.4.1.2021.9.1.8.1 - oid_used_space = ".1.3.6.1.4.1.2021.9.1.8.1" - disk_used = float(conn.exec_command(oid_used_space)) - try: - percent_disk_used = round((disk_used * 100) / total_space_on_disk, 2) - except ZeroDivisionError: - exception_inst = getattr(mnce, "ModuleNotCompatibleException")( - part, conn.get_addr_host() - ) - raise exception_inst - return percent_disk_used \ No newline at end of file +def check(conn, mnce, subparts): + res_check = {} + + if subparts == []: + subparts.append('/') + + # http://www.oid-info.com/get/1.3.6.1.4.1.2021.9.1.2 + oid_mounted_partitions = "1.3.6.1.4.1.2021.9.1.2" + mounted_partitions = conn.exec_command(oid_mounted_partitions) + # http://www.oid-info.com/get/1.3.6.1.4.1.2021.9.1.9 + oid_percent_used = "1.3.6.1.4.1.2021.9.1.9" + disk_used_on_partitions = conn.exec_command(oid_percent_used) + + for partition in mounted_partitions: + if mounted_partitions[partition] in subparts: + oid_nodes = partition.split('.') + partition_node_number = oid_nodes[len(oid_nodes) - 1] + res_check[mounted_partitions[partition]] = \ + int(disk_used_on_partitions["1.3.6.1.4.1.2021.9.1.9." + partition_node_number]) + + return res_check \ No newline at end of file diff --git a/app/modules/monitoring_modules/disk_ssh_linux.py b/app/modules/monitoring_modules/disk_ssh_linux.py index 73b0129..e329fc6 100644 --- a/app/modules/monitoring_modules/disk_ssh_linux.py +++ b/app/modules/monitoring_modules/disk_ssh_linux.py @@ -8,9 +8,10 @@ block = "hardware" part = "disk" unit = "%" connection = "ssh" +return_dict = False -def check(conn, mnce): +def check(conn, mnce, subparts): cmd = "df -h" stdout = conn.exec_command(cmd) disk_used = None diff --git a/app/modules/monitoring_modules/http.py b/app/modules/monitoring_modules/http.py index 1475b31..07fb16a 100644 --- a/app/modules/monitoring_modules/http.py +++ b/app/modules/monitoring_modules/http.py @@ -7,14 +7,16 @@ block = "network" part = "http" unit = "bool" connection = "" +return_dict = False def check(addr_host, port_list, cnfe): res_http_check = False http_port_found = False - try: - for i in range(len(port_list)): - # for each http port detected for this host + + for i in range(len(port_list)): + # for each http port detected for this host + try: if port_list[i]['portname'] == part: http_port_found = True # the result of the check is true if urlopen returns the http code 200 @@ -22,12 +24,12 @@ def check(addr_host, port_list, cnfe): None, 10 ).getcode() == 200 - if not http_port_found: - # if there is no http port detected for this host - exception_inst = getattr(cnfe, "CommandNotFoundException")( - part, addr_host - ) - raise exception_inst - return res_http_check - except Exception: - return False \ No newline at end of file + except Exception: + return False + if not http_port_found: + # if there is no http port detected for this host + exception_inst = getattr(cnfe, "CommandNotFoundException")( + part, addr_host + ) + raise exception_inst + return res_http_check diff --git a/app/modules/monitoring_modules/load_ssh_linux.py b/app/modules/monitoring_modules/load_ssh_linux.py index 49e7b66..62a2ae3 100644 --- a/app/modules/monitoring_modules/load_ssh_linux.py +++ b/app/modules/monitoring_modules/load_ssh_linux.py @@ -6,9 +6,10 @@ block = "hardware" part = "min_15_load" unit = "" connection = "ssh" +return_dict = False -def check(conn, mnce): +def check(conn, mnce, subparts): """ Returns the greatest between the user and system CPU charge """ diff --git a/app/modules/monitoring_modules/memory_snmp_linux.py b/app/modules/monitoring_modules/memory_snmp_linux.py index fbbc95a..016c86a 100644 --- a/app/modules/monitoring_modules/memory_snmp_linux.py +++ b/app/modules/monitoring_modules/memory_snmp_linux.py @@ -5,9 +5,10 @@ block = "hardware" part = "memory" unit = "%" connection = "snmp" +return_dict = False -def check(conn, mnce): +def check(conn, mnce, subparts): # http://www.oid-info.com/get/1.3.6.1.4.1.2021.4.5.0 oid_total_ram_avaliable = ".1.3.6.1.4.1.2021.4.5.0" total_mem = float(conn.exec_command(oid_total_ram_avaliable)) diff --git a/app/modules/monitoring_modules/memory_ssh_linux.py b/app/modules/monitoring_modules/memory_ssh_linux.py index 3f2a0ea..f7e88a4 100644 --- a/app/modules/monitoring_modules/memory_ssh_linux.py +++ b/app/modules/monitoring_modules/memory_ssh_linux.py @@ -8,9 +8,10 @@ block = "hardware" part = "memory" unit = "%" connection = "ssh" +return_dict = False -def check(conn, mnce): +def check(conn, mnce, subparts): cmd = "cat /proc/meminfo" stdout = conn.exec_command(cmd) memfree = 0 diff --git a/app/modules/monitoring_modules/ping.py b/app/modules/monitoring_modules/ping.py index c433507..7a69e2d 100644 --- a/app/modules/monitoring_modules/ping.py +++ b/app/modules/monitoring_modules/ping.py @@ -8,6 +8,7 @@ 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 531f13e..a2e466b 100644 --- a/app/modules/monitoring_modules/smtp.py +++ b/app/modules/monitoring_modules/smtp.py @@ -7,13 +7,15 @@ block = "network" part = "smtp" unit = "bool" connection = "" +return_dict = False def check(addr_host, port_list, cnfe): res_smtp_check = False smtp_port_found = False - try: - for i in range(len(port_list)): + + for i in range(len(port_list)): + try: # for each smtp port detected for this host if port_list[i]['portname'] == part: smtp_port_found = True @@ -23,12 +25,12 @@ def check(addr_host, port_list, cnfe): res_smtp_check = smtp_conn_inst.helo()[0] == 250 # close the connection when finished smtp_conn_inst.quit() - if not smtp_port_found: - # if there is no smtp port detected for this host - exception_inst = getattr(cnfe, "CommandNotFoundException")( - part, addr_host - ) - raise exception_inst - return res_smtp_check - except Exception: - return False \ No newline at end of file + except Exception: + return False + if not smtp_port_found: + # if there is no smtp port detected for this host + exception_inst = getattr(cnfe, "CommandNotFoundException")( + part, addr_host + ) + raise exception_inst + return res_smtp_check diff --git a/app/modules/monitoring_modules/swap_snmp_linux.py b/app/modules/monitoring_modules/swap_snmp_linux.py index c7940ec..d708eb9 100644 --- a/app/modules/monitoring_modules/swap_snmp_linux.py +++ b/app/modules/monitoring_modules/swap_snmp_linux.py @@ -5,9 +5,10 @@ block = "hardware" part = "swap" unit = "%" connection = "snmp" +return_dict = False -def check(conn, mnce): +def check(conn, mnce, subparts): # http://www.oid-info.com/get/1.3.6.1.4.1.2021.4.3.0 oid_total_swap_size = ".1.3.6.1.4.1.2021.4.3.0" total_swap = float(conn.exec_command(oid_total_swap_size)) diff --git a/app/modules/monitoring_modules/swap_ssh_linux.py b/app/modules/monitoring_modules/swap_ssh_linux.py index c796578..c3805fe 100644 --- a/app/modules/monitoring_modules/swap_ssh_linux.py +++ b/app/modules/monitoring_modules/swap_ssh_linux.py @@ -6,9 +6,10 @@ block = "hardware" part = "swap" unit = "%" connection = "ssh" +return_dict = False -def check(conn, mnce): +def check(conn, mnce, subparts): cmd = "free -m" stdout = conn.exec_command(cmd) swap_total = 0 diff --git a/app/modules/monitoring_modules/updated_packages_ssh_linux.py b/app/modules/monitoring_modules/updated_packages_ssh_linux.py index 67be4e9..7434d4d 100644 --- a/app/modules/monitoring_modules/updated_packages_ssh_linux.py +++ b/app/modules/monitoring_modules/updated_packages_ssh_linux.py @@ -6,9 +6,10 @@ block = "software" part = "updated_packages" unit = "bool" connection = "ssh" +return_dict = False -def check(conn, mnce): +def check(conn, mnce, subparts): cmd = "apt-get upgrade -s" stdout = conn.exec_command(cmd) tab_res = stdout.split(':') diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index 0dba636..25b4dbd 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -72,6 +72,7 @@ class shelve_db: 'class_name': string, => the name of the class to instanciate 'compatible_os': [string1, string2, ...], => a list containing the compatibles os 'unit': string, => the unit type of return ('%', 'bool' or other) + 'return_dict': bool => true if the module return a dict of values 'block': string, => the monitoring block of the module 'external': bool => indicates if this modules comes from external directory } @@ -84,6 +85,7 @@ class shelve_db: if mod not in self.db['global_conf']: # adding a entry for every module loaded for the first time mod_conf = {} mod_conf['block'] = loaded_mod_moni[mod]['block'] + mod_conf['return_dict'] = loaded_mod_moni[mod]['return_dict'] # all modules are added if the os is compatible, we'll try at least # once the check, if it exists a connection that can lauch the module mod_conf['activated'] = True @@ -96,6 +98,7 @@ class shelve_db: mod_conf['nb_month'] = 6 mod_conf['nb_year'] = None """ + mod_conf['subparts'] = [] # a list that can contain for example the names of the disk partitions unit = loaded_mod_moni[mod]['unit'] mod_conf['unit'] = unit if unit == '%': @@ -157,6 +160,23 @@ class shelve_db: finally: self.close_db() + def get_subpart(self, addr_host, modname): + """ + Asked while launching a monitoring module. + :param addr_host: The IP adress of the host + :param modname: the name of the monitoring module + :return: a list containing subparts to check, if configured + """ + self.open_db() + res = [] + try: + res = self.db['hosts'][addr_host]['conf']['monitoring'][modname]['subparts'] + except Exception: + print traceback.format_exc() + finally: + self.close_db() + return res + 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. @@ -223,33 +243,19 @@ class shelve_db: """ dict_conn = {} for port in dict_nmap_res['openports']: - if port["portname"] in conn_infos: - # if this open port is part of the loaded connections - dict_conn[port["portname"]] = {} - if len(conn_infos[port['portname']]['params'].keys()) == 1 and \ - 'port' in conn_infos[port['portname']]['params']: - # if there is only the port to configure, the conn module can be activated because is - # already configured - dict_conn[port["portname"]]["priority"] = 1 - else: - for param in conn_infos[port["portname"]]['params']: - dict_conn[port["portname"]][param] = None - dict_conn[port["portname"]]["priority"] = 0 - dict_conn[port["portname"]]["port"] = int(port["portid"]) - else: - for loaded_conn_mod in conn_infos: - if conn_infos[loaded_conn_mod]['known_port'] == int(port['portid']): - dict_conn[loaded_conn_mod] = {} + for loaded_conn_mod in conn_infos: + if conn_infos[loaded_conn_mod]['known_port'] == int(port['portid']): + dict_conn[loaded_conn_mod] = {} + if len(conn_infos[loaded_conn_mod]['params'].keys()) == 1 and \ + 'port' in conn_infos[loaded_conn_mod]['params']: + # if there is only the port to configure, the conn module can be activated because is + # already configured + dict_conn[loaded_conn_mod]["priority"] = 1 + else: for param in conn_infos[loaded_conn_mod]['params']: dict_conn[loaded_conn_mod][param] = None - if len(conn_infos[loaded_conn_mod]['params'].keys()) == 1 and \ - 'port' in conn_infos[loaded_conn_mod]['params']: - # if there is only the port to configure, the conn module can be activated because is - # already configured - dict_conn[loaded_conn_mod]["priority"] = 1 - else: - dict_conn[loaded_conn_mod]["priority"] = 0 - dict_conn[loaded_conn_mod]["port"] = conn_infos[loaded_conn_mod]['known_port'] + dict_conn[loaded_conn_mod]["priority"] = 0 + dict_conn[loaded_conn_mod]["port"] = conn_infos[loaded_conn_mod]['known_port'] return dict_conn def get_conn_param(self, args): @@ -804,26 +810,18 @@ class shelve_db: if mod_name not in self.db['hosts'][addr_host]["monitoring"]: # creating the monitoring structure for this module if not exists self.db['hosts'][addr_host]["monitoring"][mod_name] = {} - if isinstance(val, type(True)): - # if boolean - if self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['minor_limit'] and not val: - # if warning set for fail and fail occures - new_val['state'] = 'warning' - elif self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['major_limit'] and not val: - # if danger set for fail and fail occures - new_val['state'] = 'danger' - else: - new_val['state'] = 'success' + if isinstance(val, type({})): + # if dictionary + for subval in val: + new_val = self.set_new_val(val[subval], + new_val, + self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['minor_limit'], + self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['major_limit']) else: - # if numerical value - if val >= self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['minor_limit']: - # if value is above waning limit - new_val['state'] = 'warning' - elif val >= self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['major_limit']: - # if value is above danger limit - new_val['state'] = 'danger' - else: - new_val['state'] = 'success' + new_val = self.set_new_val(val, + new_val, + self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['minor_limit'], + self.db['hosts'][addr_host]['conf']['monitoring'][mod_name]['major_limit']) previous_val = self.db['hosts'][addr_host]["monitoring"][mod_name] self.db['hosts'][addr_host]['monitoring'][mod_name] = new_val # updating the global state of the host @@ -855,6 +853,41 @@ class shelve_db: self.close_db() return dict_notif + @staticmethod + def set_new_val(val, dict_val, minor_limit, major_limit): + new_status = "" + if isinstance(val, type(True)): + # if boolean + if minor_limit and not val: + # if warning set for fail and fail occures + new_status = 'warning' + elif major_limit and not val: + # if danger set for fail and fail occures + new_status = 'danger' + else: + new_status = 'success' + else: + # if numerical value + if val >= minor_limit: + # if value is above waning limit + new_status = 'warning' + elif val >= major_limit: + # if value is above danger limit + new_status = 'danger' + else: + new_status = 'success' + if 'state' in dict_val: + # multiple values because the value returned by the moni mod is a dictionary + if new_status == 'danger': + dict_val['state'] = 'danger' + elif new_status == 'warning' and dict_val['state'] != 'danger': + dict_val['state'] = 'warning' + # is success in other cases, so success is in dict_val or have been already overwrited + else: + # first value of the dictionary, or unique value + dict_val['state'] = new_status + return dict_val + def update_stats(self, stats, val): """ Updates calulated statistics once a new value is received. diff --git a/static/js/controllers/hostPageCtrl.js b/static/js/controllers/hostPageCtrl.js index d1783ba..137437d 100644 --- a/static/js/controllers/hostPageCtrl.js +++ b/static/js/controllers/hostPageCtrl.js @@ -45,6 +45,9 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $route, $routePar } } */ + + $scope.collapsed = {}; + $scope.update_nmap_attribute = function(attribute, new_value){ var args = {}; args['attribute'] = attribute; @@ -59,7 +62,11 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $route, $routePar res = $scope.items.loaded_moni_mod[mod_name].unit; } return res; - } + }; + + $scope.get_type_of = function(attr){ + return typeof(attr); + }; $scope.get_idle_state = function(){ res = ""; @@ -70,7 +77,7 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $route, $routePar res = "success"; } return res - } + }; $scope.popover_message = function(){ msg = ""; @@ -81,7 +88,7 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $route, $routePar msg = "Click to suspend the monitoring for this host."; } return msg - } + }; $scope.$on("resCall", function (event, args) { if(args.func == 'update_nmap_attribute'){ @@ -124,6 +131,9 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $route, $routePar $scope.model.custom_infos = args.custom_infos; $scope.loaded = true; $scope.model['compatible_os_list'] = args['compatible_os_list']; + for(modname in args.monitoring){ + $scope.collapsed[modname] = true; + } } else{ // we takes only monitoring updates $scope.items.monitoring = args.monitoring; diff --git a/views/hostpage.html b/views/hostpage.html index 9a5e32c..0226772 100644 --- a/views/hostpage.html +++ b/views/hostpage.html @@ -40,11 +40,14 @@ </thead> <tbody> - <tr ng-repeat="(itemname, item) in items.monitoring" + <tr ng-repeat-start="(itemname, item) in items.monitoring" class={{item.state}} - ng-show="items.activated_monitoring[itemname]"> + > <!-- ng-show="items.activated_monitoring[itemname]" --> <td>{{itemname}}</td> - <td>{{item.value}} {{get_unit(itemname)}}</td> + <td ng-show="get_type_of(item.value) != 'object'">{{item.value}} {{get_unit(itemname)}}</td> + <td ng-show="get_type_of(item.value) == 'object'"> + <a ng-click="collapsed[itemname] = !collapsed[itemname]">▼</a> + </td> <td>{{item.state}}</td> <td>{{item.date.split('.')[0]}}</td> <td><button type="button" class="btn btn-primary btn-xs" @@ -52,6 +55,12 @@ <td><button type="button" class="btn btn-info btn-xs" ng-click="check(itemname)">Check now</button></td> </tr> + <tr ng-repeat-end + ng-repeat="(valname, val) in item.value" + collapse="collapsed[itemname]"> + <td>{{valname}}</td> + <td>{{val}} {{get_unit(itemname)}}</td> + </tr> </tbody> </table> <accordion close-others="false"> @@ -359,7 +368,6 @@ <h3 class="modal-title">Add or delete the ports detected</h3> </div> <div class="modal-body"> - {{port_config_args.port_list}} <table class="table table-condensed table-hover"> <thead> -- 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 b1f49077b42b54b817c18c0bce0c395f9f431c33 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Apr 29 10:53:26 2015 +0200 hostpage: detected configuration separated from nmap detection. subparts can be checked from the detected config, and the monitoring will check the selected subparts --- app/modules/detection_modules/drive_detection.py | 3 ++- app/modules/detection_modules/drive_snmp_linux.py | 14 +++++++++++ app/modules/storage_modules/shelve_db.py | 27 +++++++++++++++++---- static/js/controllers/hostPageCtrl.js | 21 +++++++++++++++- views/hostpage.html | 29 ++++++++++++++++++----- 5 files changed, 82 insertions(+), 12 deletions(-) diff --git a/app/modules/detection_modules/drive_detection.py b/app/modules/detection_modules/drive_detection.py index 2f34fce..be02ae1 100644 --- a/app/modules/detection_modules/drive_detection.py +++ b/app/modules/detection_modules/drive_detection.py @@ -3,6 +3,7 @@ import json compatible_os = ['linux', 'unix'] connection = "ssh" +part = 'disk' def run_detection(conn, db): @@ -32,4 +33,4 @@ def run_detection(conn, db): # 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 + db.save_detection(conn.get_addr_host(), part, json.dumps(dict_total)) \ No newline at end of file diff --git a/app/modules/detection_modules/drive_snmp_linux.py b/app/modules/detection_modules/drive_snmp_linux.py new file mode 100644 index 0000000..9faa53b --- /dev/null +++ b/app/modules/detection_modules/drive_snmp_linux.py @@ -0,0 +1,14 @@ +__author__ = 'aguilbaud' +import json + +compatible_os = ['linux', 'unix'] +connection = "snmp_walk" +part = 'disk' + +def run_detection(conn, db): + oid_mounted_partitions = "1.3.6.1.4.1.2021.9.1.2" + mounted_partitions = conn.exec_command(oid_mounted_partitions) + partition_list = [] + for partition in mounted_partitions: + partition_list.append(mounted_partitions[partition]) + db.save_detection(conn.get_addr_host(), part, json.dumps(partition_list)) \ 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 25b4dbd..344dc7c 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -177,6 +177,25 @@ class shelve_db: self.close_db() return res + def set_subpart(self, args): + """ + Asked from the hostpage. Set the subpart list to monitore. + :param args: A dictionary containing: + { + 'addr_host': str, + 'modname': str, + 'subpart_list': [str, str, ...] + } + """ + self.open_db() + try: + self.db['hosts'][args['addr_host']]['conf']['monitoring'][args['modname']]['subparts'] = \ + args['subpart_list'] + except Exception: + print traceback.format_exc() + finally: + self.close_db() + 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. @@ -868,12 +887,12 @@ class shelve_db: new_status = 'success' else: # if numerical value - if val >= minor_limit: + if val >= int(minor_limit): # if value is above waning limit new_status = 'warning' - elif val >= major_limit: - # if value is above danger limit - new_status = 'danger' + if val >= int(major_limit): + # if value is above danger limit + new_status = 'danger' else: new_status = 'success' if 'state' in dict_val: diff --git a/static/js/controllers/hostPageCtrl.js b/static/js/controllers/hostPageCtrl.js index 137437d..3d4f675 100644 --- a/static/js/controllers/hostPageCtrl.js +++ b/static/js/controllers/hostPageCtrl.js @@ -48,6 +48,8 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $route, $routePar $scope.collapsed = {}; + $scope.subparts_checked = {}; + $scope.update_nmap_attribute = function(attribute, new_value){ var args = {}; args['attribute'] = attribute; @@ -56,6 +58,19 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $route, $routePar $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'update_nmap_attribute', 'args': args}})); }; + $scope.save_subpart = function(modname){ + var args = {}; + args['addr_host'] = $scope.addr_host; + args['modname'] = modname; + args['subpart_list'] = []; + for(key in $scope.subparts_checked[modname]){ + if($scope.subparts_checked[modname][key]){ + args['subpart_list'].push(key); + } + } + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'set_subpart', 'args': args}})); + } + $scope.get_unit = function(mod_name){ res = ''; if($scope.items.loaded_moni_mod[mod_name].unit != 'bool'){ @@ -131,8 +146,12 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $route, $routePar $scope.model.custom_infos = args.custom_infos; $scope.loaded = true; $scope.model['compatible_os_list'] = args['compatible_os_list']; - for(modname in args.monitoring){ + for(var modname in args.monitoring){ $scope.collapsed[modname] = true; + $scope.subparts_checked[modname] = {} + for(var key in args.detected[modname]){ + $scope.subparts_checked[modname][args.detected[modname][key]] = false; + } } } else{ // we takes only monitoring updates diff --git a/views/hostpage.html b/views/hostpage.html index 0226772..ea883ef 100644 --- a/views/hostpage.html +++ b/views/hostpage.html @@ -64,13 +64,9 @@ </tbody> </table> <accordion close-others="false"> - <accordion-group heading="Detected Configuration"> + <accordion-group heading="Essential configuration (nmap detection)"> <table class="table table-bordered table-hover"> - <tr ng-repeat-start="(modname, mod) in items.detected"> - <th>{{modname}}</th> - </tr> - <tr ng-repeat-end - ng-repeat="(key, val) in mod"> + <tr ng-repeat="(key, val) in items.detected.nmap"> <td>{{key}}</td> <td>{{val}}</td> <td ng-show="(key == 'os')"> @@ -97,6 +93,27 @@ </tr> </table> </accordion-group> + <accordion-group heading="Detected configuration (select the subparts to monitore here)"> + <table class="table table-bordered table-hover"> + <tr ng-repeat-start="(modname, mod) in items.detected" + ng-show="modname != 'nmap'"> + <th>{{modname}}</th> + <th> + <button type="button" class="btn btn-info btn-xs" + ng-click="save_subpart(modname)"> + Monitore selected subparts + </button> + </th> + </tr> + <tr ng-repeat-end + ng-repeat="(key, val) in mod" + ng-show="modname != 'nmap'"> + <td>{{key}}</td> + <td>{{val}}</td> + <td><input type="checkbox" ng-model="subparts_checked[modname][val]"></td> + </tr> + </table> + </accordion-group> <accordion-group heading="Custom informations"> <label for="custom_info">Add any information here :</label> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm