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 a30b6a6246f6ce09abd5fba74907e2802382bce2 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Fri Jul 3 11:49:31 2015 +0200 updated ssh modules for using english language only + sms notif logging errors on every case --- app/modules/monitoring_modules/cpu_ssh_linux.py | 2 +- app/modules/monitoring_modules/disk_ssh_linux.py | 4 +-- app/modules/monitoring_modules/http.py | 2 +- app/modules/monitoring_modules/process.py | 35 ++++++++++++++++++++++ app/modules/monitoring_modules/swap_ssh_linux.py | 2 +- .../updated_packages_ssh_linux.py | 31 ++++++++++--------- app/modules/notification_modules/sms_notif.py | 12 +++++--- 7 files changed, 65 insertions(+), 23 deletions(-) diff --git a/app/modules/monitoring_modules/cpu_ssh_linux.py b/app/modules/monitoring_modules/cpu_ssh_linux.py index b34a0a3..e7c7794 100644 --- a/app/modules/monitoring_modules/cpu_ssh_linux.py +++ b/app/modules/monitoring_modules/cpu_ssh_linux.py @@ -13,7 +13,7 @@ def check(conn, mnce, subparts): """ Returns the greatest between the user and system CPU charge """ - cmd = "top -b -n 1" + cmd = "LANG=C top -b -n 1" stdout = conn.exec_command(cmd) # output example: diff --git a/app/modules/monitoring_modules/disk_ssh_linux.py b/app/modules/monitoring_modules/disk_ssh_linux.py index 41af338..632bca5 100644 --- a/app/modules/monitoring_modules/disk_ssh_linux.py +++ b/app/modules/monitoring_modules/disk_ssh_linux.py @@ -12,12 +12,12 @@ connection = "ssh" def check(conn, mnce, subparts): - cmd = "df -h" + cmd = "LANG=C df -h" stdout = conn.exec_command(cmd) # output example: """ - Sys. fich. Taille Util. Dispo Uti% Monte sur + Filesystem Size Used Avail Use% Mounted on rootfs 55G 11G 42G 21% / udev 10M 0 10M 0% /dev tmpfs 579M 1,1M 578M 1% /run diff --git a/app/modules/monitoring_modules/http.py b/app/modules/monitoring_modules/http.py index 87e09cd..f95bb5e 100644 --- a/app/modules/monitoring_modules/http.py +++ b/app/modules/monitoring_modules/http.py @@ -23,7 +23,7 @@ def check(addr_host, port_list, cnfe): res_http_check[port_list[i]['portid']] = urllib2.urlopen("http://" + addr_host + ":" + str(port_list[i]['portid']), None, 10 - ).getcode() == 200 + ).getcode() == 200 or 401 except Exception: res_http_check[port_list[i]['portid']] = False if not http_port_found: diff --git a/app/modules/monitoring_modules/process.py b/app/modules/monitoring_modules/process.py new file mode 100644 index 0000000..ce092d4 --- /dev/null +++ b/app/modules/monitoring_modules/process.py @@ -0,0 +1,35 @@ +__author__ = 'aguilbaud' + +compatible_os = ['linux'] +block = "software" +part = "Process" +name = "Process SSH" +unit = "" +connection = "ssh" + +param = { + {"proc_name", {'type': 'string', 'value': '', 'doc': "The name of the process"}}, +} + +def check(conn, mnce, params): + cmd = "LANG=C ps -C " + params['proc_name'] + " -opid" + stdout = conn.exec_command(cmd) + + # output if process is running + """ + PID + 2993 + 2994 + 2995 + 2996 + 2997 + 2998 + """ + # output if process is not running + """ + PID + """ + + process_number_running = len(stdout.splitlines()) - 1 + + return process_number_running \ 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 daf1348..36d673a 100644 --- a/app/modules/monitoring_modules/swap_ssh_linux.py +++ b/app/modules/monitoring_modules/swap_ssh_linux.py @@ -10,7 +10,7 @@ connection = "ssh" def check(conn, mnce, subparts): - cmd = "free -m" + cmd = "LANG=C free -m" stdout = conn.exec_command(cmd) # output example: diff --git a/app/modules/monitoring_modules/updated_packages_ssh_linux.py b/app/modules/monitoring_modules/updated_packages_ssh_linux.py index 8436752..4662809 100644 --- a/app/modules/monitoring_modules/updated_packages_ssh_linux.py +++ b/app/modules/monitoring_modules/updated_packages_ssh_linux.py @@ -1,4 +1,6 @@ # -*- coding: utf8 -*- +import re + __author__ = 'aguilbaud' @@ -11,23 +13,24 @@ connection = "ssh" def check(conn, mnce, subparts): - cmd = "apt-get upgrade -s" + cmd = "LANG=C 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. + NOTE: This is only a simulation! + apt-get needs root privileges for real execution. + Keep also in mind that locking is deactivated, + so don't depend on the relevance to the real current situation! + Reading package lists... Done + Building dependency tree + Reading state information... Done + The following packages will be upgraded: + linux-image-3.16.0-0.bpo.4-amd64 linux-image-3.2.0-4-amd64 linux-libc-dev p7zip-full tzdata tzdata-java + 6 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. + Inst linux-image-3.16.0-0.bpo.4-amd64 [3.16.7-ckt9-3~deb8u1~bpo70+1] (3.16.7-ckt11-1~bpo70+1 Debian Backports:/wheezy-backports [amd64]) + Inst linux-image-3.2.0-4-amd64 [3.2.68-1+deb7u1] (3.2.68-1+deb7u2 Debian-Security:7.0/oldstable [amd64]) """ - tab_res = stdout.split(':') - res_check = len(tab_res) <= 2 - return res_check \ No newline at end of file + res_check = re.search("The following packages will be upgraded:", stdout) is not None + return res_check diff --git a/app/modules/notification_modules/sms_notif.py b/app/modules/notification_modules/sms_notif.py index c758e60..2401f60 100644 --- a/app/modules/notification_modules/sms_notif.py +++ b/app/modules/notification_modules/sms_notif.py @@ -30,9 +30,13 @@ class SMS: if hasattr(e,'code'): if e.code == 400: self.logger.error('sms_notif ' + self.user_data['sms_url'] + ' code 400: One of the url parameters is missing.') - if e.code == 402: + elif e.code == 402: self.logger.error('sms_notif ' + self.user_data['sms_url'] + ' code 402: Too many SMS have been sent in short time.') - if e.code == 403: + elif e.code == 403: self.logger.error('sms_notif ' + self.user_data['sms_url'] + ' code 403: The service is not activated or wrong login/key.') - if e.code == 500: - self.logger.error('sms_notif ' + self.user_data['sms_url'] + ' code 500: Server error. Please try again later.') \ No newline at end of file + elif e.code == 404: + self.logger.error('sms_notif ' + self.user_data['sms_url'] + ' code 404: The SMS URL does not exists.') + elif e.code == 500: + self.logger.error('sms_notif ' + self.user_data['sms_url'] + ' code 500: Server error. Please try again later.') + else: + self.logger.error('sms_notif ' + self.user_data['sms_url'] + ' code ' + e.code) \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.