branch develop updated (1ccba97 -> 1135a78)
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 1ccba97 removed useless attribute "return_dict" on moni mod + moved websocket core functions from mum.py to new module websocket_func new 1135a78 detection modules returns result (no db dependency) + commented ssh modules with output examples The 1 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 1135a7854b9997aee13bef3c6f38dae3a814bc67 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed May 20 11:15:10 2015 +0200 detection modules returns result (no db dependency) + commented ssh modules with output examples Summary of changes: app/module_loader.py | 9 ++++++--- app/modules/detection_modules/drive_detection.py | 17 ++++++++++++++--- app/modules/detection_modules/drive_snmp_linux.py | 4 ++-- app/modules/detection_modules/kernel_detection.py | 10 ++++++++-- .../detection_modules/open_ports_detection.py | 15 +++++++++++++-- app/modules/detection_modules/os_detection.py | 22 ++++++++++++++++++---- app/modules/monitoring_modules/cpu_glances.py | 2 +- app/modules/monitoring_modules/cpu_ssh_linux.py | 17 +++++++++++++++++ app/modules/monitoring_modules/disk_ssh_linux.py | 16 +++++++++++++++- app/modules/monitoring_modules/load_ssh_linux.py | 16 ++++++++++++++++ app/modules/monitoring_modules/memory_ssh_linux.py | 15 ++++++++++++++- app/modules/monitoring_modules/swap_ssh_linux.py | 14 +++++++++++++- .../updated_packages_ssh_linux.py | 16 ++++++++++++++++ 13 files changed, 153 insertions(+), 20 deletions(-) -- 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 1135a7854b9997aee13bef3c6f38dae3a814bc67 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed May 20 11:15:10 2015 +0200 detection modules returns result (no db dependency) + commented ssh modules with output examples --- app/module_loader.py | 9 ++++++--- app/modules/detection_modules/drive_detection.py | 17 ++++++++++++++--- app/modules/detection_modules/drive_snmp_linux.py | 4 ++-- app/modules/detection_modules/kernel_detection.py | 10 ++++++++-- .../detection_modules/open_ports_detection.py | 15 +++++++++++++-- app/modules/detection_modules/os_detection.py | 22 ++++++++++++++++++---- app/modules/monitoring_modules/cpu_glances.py | 2 +- app/modules/monitoring_modules/cpu_ssh_linux.py | 17 +++++++++++++++++ app/modules/monitoring_modules/disk_ssh_linux.py | 16 +++++++++++++++- app/modules/monitoring_modules/load_ssh_linux.py | 16 ++++++++++++++++ app/modules/monitoring_modules/memory_ssh_linux.py | 15 ++++++++++++++- app/modules/monitoring_modules/swap_ssh_linux.py | 14 +++++++++++++- .../updated_packages_ssh_linux.py | 16 ++++++++++++++++ 13 files changed, 153 insertions(+), 20 deletions(-) diff --git a/app/module_loader.py b/app/module_loader.py index c6bc8b8..99501b1 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -188,7 +188,6 @@ class ModuleLoader: Instanciates and runs the run_detection() method from each detection modules loaded on loaded_mod_detect :param addr_host: the IP address of the host we want to run the detection """ - db = self.get_db() conf_conn = self.db.get_conf_conn(addr_host) success_detection = False for mod_name in self.loaded_mod_detect: @@ -196,8 +195,12 @@ class ModuleLoader: if self.loaded_mod_detect[mod_name]['compatible_conn'] == conf_conn[i]['conn_mod_name']: try: conn_inst = self.create_connection(addr_host, conf_conn[i]) - getattr(self.loaded_mod_detect[mod_name]['imported'], - 'run_detection')(conn_inst, db) + res_detection = getattr(self.loaded_mod_detect[mod_name]['imported'], + 'run_detection')(conn_inst) + self.db.save_detection(conn_inst.get_addr_host(), + getattr(self.loaded_mod_detect[mod_name]['imported'], 'part'), + json.dumps(res_detection) + ) success_detection = True except modules.ModuleNotCompatibleException.ModuleNotCompatibleException as mnce: print mnce.__str__() diff --git a/app/modules/detection_modules/drive_detection.py b/app/modules/detection_modules/drive_detection.py index be02ae1..6ff6ea4 100644 --- a/app/modules/detection_modules/drive_detection.py +++ b/app/modules/detection_modules/drive_detection.py @@ -1,18 +1,29 @@ __author__ = 'aguilbaud' -import json compatible_os = ['linux', 'unix'] connection = "ssh" part = 'disk' -def run_detection(conn, db): +def run_detection(conn): """ Retourne les informations des partitions systeme sous la forme : {"sr0": {"mountpoint": "none", "type": "rom", "name": "sr0", "size": "1024M"} """ cmd = "lsblk -r --output=NAME,SIZE,TYPE,MOUNTPOINT" stdout = conn.exec_command(cmd) + + # Output example: + """ + NAME SIZE TYPE MOUNTPOINT + sda 111,8G disk + sda1 55,9G part / + sda2 7,6G part [SWAP] + sda3 28G part /home + sda4 20,4G part /var/local + sr0 1024M rom + """ + dict_total = {} i = 1 ignore = True @@ -33,4 +44,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(), part, json.dumps(dict_total)) \ No newline at end of file + return 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 index 9faa53b..1e27807 100644 --- a/app/modules/detection_modules/drive_snmp_linux.py +++ b/app/modules/detection_modules/drive_snmp_linux.py @@ -5,10 +5,10 @@ compatible_os = ['linux', 'unix'] connection = "snmp_walk" part = 'disk' -def run_detection(conn, db): +def run_detection(conn): 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 + return partition_list \ No newline at end of file diff --git a/app/modules/detection_modules/kernel_detection.py b/app/modules/detection_modules/kernel_detection.py index d6058fe..5e8d122 100644 --- a/app/modules/detection_modules/kernel_detection.py +++ b/app/modules/detection_modules/kernel_detection.py @@ -5,9 +5,15 @@ compatible_os = ['linux', 'unix'] connection = "ssh" -def run_detection(conn, db): +def run_detection(conn): cmd = "cat /proc/version" stdout = conn.exec_command(cmd) + + # Output example: + """ + Linux version 3.16.0-0.bpo.4-amd64 (debian-kernel@lists.debian.org) (gcc version 4.6.3 (Debian 4.6.3-14) ) #1 SMP Debian 3.16.7-ckt9-3~deb8u1~bpo70+1 (2015-04-27) + """ + dict_total = {} dict_total["kernel"] = stdout.split('#')[0] - db.save_detection(conn.get_addr_host(), "kernel_detection", json.dumps(dict_total)) \ No newline at end of file + return dict_total \ No newline at end of file diff --git a/app/modules/detection_modules/open_ports_detection.py b/app/modules/detection_modules/open_ports_detection.py index 292c9ed..50dfbbe 100644 --- a/app/modules/detection_modules/open_ports_detection.py +++ b/app/modules/detection_modules/open_ports_detection.py @@ -5,9 +5,20 @@ compatible_os = ['linux', 'unix'] connection = "ssh" -def run_detection(conn, db): +def run_detection(conn): cmd = "netstat -tuln" stdout = conn.exec_command(cmd) + + # Output example: + """ + Proto Recv-Q Send-Q Adresse locale Adresse distante Etat + tcp 0 0 127.0.0.1:63342 0.0.0.0:* LISTEN + tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN + tcp 0 0 0.0.0.0:53205 0.0.0.0:* LISTEN + tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN + [...] + """ + dict_total = {} l_number = 0 for line in stdout.splitlines(): @@ -24,4 +35,4 @@ def run_detection(conn, db): dict_total[fields[0]].append(port_number) """ dict_total[fields[0]].append(fields[3]) - db.save_detection(conn.get_addr_host(), "open_ports_detection", json.dumps(dict_total)) + return dict_total \ No newline at end of file diff --git a/app/modules/detection_modules/os_detection.py b/app/modules/detection_modules/os_detection.py index ea54a60..6482c87 100644 --- a/app/modules/detection_modules/os_detection.py +++ b/app/modules/detection_modules/os_detection.py @@ -5,17 +5,31 @@ import json compatible_os = ['linux', 'unix'] connection = "ssh" -def run_detection(conn, db): +def run_detection(conn): dict_total = {} cmd = "cat /etc/os-release" stdout = conn.exec_command(cmd) + + # Output example: + """ + PRETTY_NAME="Debian GNU/Linux 7 (wheezy)" + NAME="Debian GNU/Linux" + VERSION_ID="7" + VERSION="7 (wheezy)" + ID=debian + ANSI_COLOR="1;31" + HOME_URL="http://www.debian.org/" + SUPPORT_URL="http://www.debian.org/support/" + BUG_REPORT_URL="http://bugs.debian.org/" + """ + for line in stdout.splitlines(): tab_elem = line.split("=") - # pour retirer les "" sur tous les champs qui en possedent + # to remove the "" on every fields (if any) tab_right = tab_elem[1].split('"') if len(tab_right) == 1: dict_total[str.lower(tab_elem[0])] = tab_right[0] else: dict_total[str.lower(tab_elem[0])] = tab_right[1] - # encore une fois, on recupere tout le contenu de la commande, p-e qu'il est possible d'enlever le superflu - db.save_detection(conn.get_addr_host(), "os_detection", json.dumps(dict_total)) \ No newline at end of file + # we get all the output, it is possible to add a filter here... + return dict_total \ 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 79811c9..f38584f 100644 --- a/app/modules/monitoring_modules/cpu_glances.py +++ b/app/modules/monitoring_modules/cpu_glances.py @@ -23,7 +23,7 @@ def check(conn, mnce, subparts): system_cpu_charge = dict_res["user"] except KeyError: exception_inst = getattr(mnce, "ModuleNotCompatibleException")( - "cpu_glances", conn.get_addr_host() + part, conn.get_addr_host() ) raise exception_inst res_cpu = max(user_cpu_charge, system_cpu_charge) diff --git a/app/modules/monitoring_modules/cpu_ssh_linux.py b/app/modules/monitoring_modules/cpu_ssh_linux.py index c7a4b20..e4e7be5 100644 --- a/app/modules/monitoring_modules/cpu_ssh_linux.py +++ b/app/modules/monitoring_modules/cpu_ssh_linux.py @@ -14,6 +14,22 @@ def check(conn, mnce, subparts): """ cmd = "top -b -n 1" stdout = conn.exec_command(cmd) + + # output example: + """ + top - 09:35:23 up 7 min, 2 users, load average: 0,25, 0,51, 0,32 +Tasks: 179 total, 1 running, 178 sleeping, 0 stopped, 0 zombie +%Cpu(s): 10,0 us, 1,2 sy, 0,0 ni, 76,4 id, 12,1 wa, 0,0 hi, 0,2 si, 0,0 st +KiB Mem: 5920240 total, 1952176 used, 3968064 free, 63364 buffers +KiB Swap: 7910396 total, 0 used, 7910396 free, 658164 cached + + PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND + 1 root 20 0 10660 1632 1496 S 0,0 0,0 0:00.95 init + 2 root 20 0 0 0 0 S 0,0 0,0 0:00.00 kthreadd + 3 root 20 0 0 0 0 S 0,0 0,0 0:00.06 ksoftirqd/0 + [...] + """ + user_cpu_charge = 0.0 system_cpu_charge = 0.0 for line in stdout.splitlines(): @@ -29,5 +45,6 @@ def check(conn, mnce, subparts): field_sys = fields[i-1] field_sys = field_sys.replace(',', '.') system_cpu_charge = float(field_sys) + res_cpu = max(user_cpu_charge, system_cpu_charge) return res_cpu \ 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 2c49d20..0511100 100644 --- a/app/modules/monitoring_modules/disk_ssh_linux.py +++ b/app/modules/monitoring_modules/disk_ssh_linux.py @@ -13,6 +13,20 @@ connection = "ssh" def check(conn, mnce, subparts): cmd = "df -h" stdout = conn.exec_command(cmd) + + # output example: + """ + Sys. fich. Taille Util. Dispo Uti% Monte sur + rootfs 55G 11G 42G 21% / + udev 10M 0 10M 0% /dev + tmpfs 579M 1,1M 578M 1% /run + /dev/disk/by-uuid/4fd2e184-118c-40d3-8ed0-9e288a96e155 55G 11G 42G 21% / + tmpfs 5,0M 0 5,0M 0% /run/lock + tmpfs 2,7G 92K 2,7G 1% /run/shm + /dev/sda3 28G 4,3G 22G 17% /home + /dev/sda4 20G 44M 19G 1% /var/local + """ + disk_used = None ignore = True for line in stdout.splitlines(): @@ -25,7 +39,7 @@ def check(conn, mnce, subparts): disk_used = re.sub("[^0-9]", "", values[len(values)-2]) if disk_used is None: exception_inst = getattr(mnce, "ModuleNotCompatibleException")( - "disk", conn.get_addr_host() + part, conn.get_addr_host() ) raise exception_inst res_check = int(disk_used) diff --git a/app/modules/monitoring_modules/load_ssh_linux.py b/app/modules/monitoring_modules/load_ssh_linux.py index 29486fa..4139812 100644 --- a/app/modules/monitoring_modules/load_ssh_linux.py +++ b/app/modules/monitoring_modules/load_ssh_linux.py @@ -14,6 +14,22 @@ def check(conn, mnce, subparts): """ cmd = "top -b -n 1" stdout = conn.exec_command(cmd) + + # output example: + """ + top - 09:35:23 up 7 min, 2 users, load average: 0,25, 0,51, 0,32 +Tasks: 179 total, 1 running, 178 sleeping, 0 stopped, 0 zombie +%Cpu(s): 10,0 us, 1,2 sy, 0,0 ni, 76,4 id, 12,1 wa, 0,0 hi, 0,2 si, 0,0 st +KiB Mem: 5920240 total, 1952176 used, 3968064 free, 63364 buffers +KiB Swap: 7910396 total, 0 used, 7910396 free, 658164 cached + + PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND + 1 root 20 0 10660 1632 1496 S 0,0 0,0 0:00.95 init + 2 root 20 0 0 0 0 S 0,0 0,0 0:00.00 kthreadd + 3 root 20 0 0 0 0 S 0,0 0,0 0:00.06 ksoftirqd/0 + [...] + """ + load_avg = 0.0 for line in stdout.splitlines(): fields = line.split() diff --git a/app/modules/monitoring_modules/memory_ssh_linux.py b/app/modules/monitoring_modules/memory_ssh_linux.py index 033443c..2f44649 100644 --- a/app/modules/monitoring_modules/memory_ssh_linux.py +++ b/app/modules/monitoring_modules/memory_ssh_linux.py @@ -11,8 +11,19 @@ connection = "ssh" def check(conn, mnce, subparts): + # returns the percentage of used RAM + cmd = "cat /proc/meminfo" stdout = conn.exec_command(cmd) + + # output example: + """ + MemTotal: 5920240 kB + MemFree: 3894920 kB + MemAvailable: 4408708 kB + [...] + """ + memfree = 0 memtotal = 0 for line in stdout.splitlines(): @@ -22,10 +33,12 @@ def check(conn, mnce, subparts): elif(tab_res[0]) == 'MemFree': memfree = re.sub("[^0-9]", "", tab_res[1]) memused = int(memtotal) - int(memfree) + if memused == 0: exception_inst = getattr(mnce, "ModuleNotCompatibleException")( - "memory", conn.get_addr_host() + part, conn.get_addr_host() ) raise exception_inst + res_check = memused * 100 / int(memtotal) return res_check \ No newline at end of file diff --git a/app/modules/monitoring_modules/swap_ssh_linux.py b/app/modules/monitoring_modules/swap_ssh_linux.py index 14b81a7..0a6f155 100644 --- a/app/modules/monitoring_modules/swap_ssh_linux.py +++ b/app/modules/monitoring_modules/swap_ssh_linux.py @@ -11,6 +11,16 @@ connection = "ssh" def check(conn, mnce, subparts): cmd = "free -m" stdout = conn.exec_command(cmd) + + # output example: + """ + total used free shared buffers cached +Mem: 5781 1995 3786 0 63 664 +-/+ buffers/cache: 1267 4513 +Swap: 7724 0 7724 + + """ + swap_total = 0 swap_used = 0 for line in stdout.splitlines(): @@ -18,11 +28,13 @@ def check(conn, mnce, subparts): if fields[0] == 'Swap:': swap_total = fields[1] swap_used = fields[2] + try: res_swap = (int(swap_used) * 100) / int(swap_total) except ZeroDivisionError: exception_inst = getattr(mnce, "ModuleNotCompatibleException")( - "swap", conn.get_addr_host() + part, conn.get_addr_host() ) raise exception_inst + return res_swap \ No newline at end of file diff --git a/app/modules/monitoring_modules/updated_packages_ssh_linux.py b/app/modules/monitoring_modules/updated_packages_ssh_linux.py index cd9e4a6..13329d5 100644 --- a/app/modules/monitoring_modules/updated_packages_ssh_linux.py +++ b/app/modules/monitoring_modules/updated_packages_ssh_linux.py @@ -1,3 +1,4 @@ +# -*- coding: utf8 -*- __author__ = 'aguilbaud' @@ -11,6 +12,21 @@ connection = "ssh" def check(conn, mnce, subparts): cmd = "apt-get upgrade -s" stdout = conn.exec_command(cmd) + + # Output example: + """ + NOTE: Ceci n'est qu'une simulation ! + apt-get a besoin des privilèges du superutilisateur + pour pouvoir vraiment fonctionner. + Veuillez aussi noter que le verrouillage est désactivé, + et la situation n'est donc pas forcément représentative + de la réalité ! +Lecture des listes de paquets... Fait +Construction de l'arbre des dépendances +Lecture des informations d'état... Fait +0 mis à jour, 0 nouvellement installés, 0 à enlever et 0 non mis à jour. + """ + tab_res = stdout.split(':') res_check = len(tab_res) <= 2 return res_check \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm