From 33180d0947118c53f7e6c96da2882483a9be6df9 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 1 Aug 2019 21:11:13 +0200 Subject: [PATCH] Add base system diagnostic --- data/hooks/diagnosis/00-basesystem.py | 54 +++++++++++++++++++++++++++ locales/en.json | 6 +++ src/yunohost/diagnosis.py | 4 +- 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 data/hooks/diagnosis/00-basesystem.py diff --git a/data/hooks/diagnosis/00-basesystem.py b/data/hooks/diagnosis/00-basesystem.py new file mode 100644 index 000000000..8fa90e65e --- /dev/null +++ b/data/hooks/diagnosis/00-basesystem.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python + +import os + +from moulinette.utils.filesystem import read_file +from yunohost.diagnosis import Diagnoser +from yunohost.utils.packages import ynh_packages_version + + +class BaseSystemDiagnoser(Diagnoser): + + id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1] + cache_duration = 3600 * 24 + dependencies = [] + + def run(self): + + # Kernel version + kernel_version = read_file('/proc/sys/kernel/osrelease').strip() + yield dict(meta={"test": "kernel"}, + status="INFO", + summary=("diagnosis_basesystem_kernel", {"kernel_version": kernel_version})) + + # Debian release + debian_version = read_file("/etc/debian_version").strip() + yield dict(meta={"test": "host"}, + status="INFO", + summary=("diagnosis_basesystem_host", {"debian_version": debian_version})) + + # Yunohost packages versions + ynh_packages = ynh_packages_version() + # We check if versions are consistent (e.g. all 3.6 and not 3 packages with 3.6 and the other with 3.5) + # This is a classical issue for upgrades that failed in the middle + # (or people upgrading half of the package because they did 'apt upgrade' instead of 'dist-upgrade') + # Here, ynh_core_version is for example "3.5.4.12", so [:3] is "3.5" and we check it's the same for all packages + ynh_core_version = ynh_packages["yunohost"]["version"] + consistent_versions = all(infos["version"][:3] == ynh_core_version[:3] for infos in ynh_packages.values()) + ynh_version_details = [("diagnosis_basesystem_ynh_single_version", (package, infos["version"])) + for package, infos in ynh_packages.items()] + + if consistent_versions: + yield dict(meta={"test": "ynh_versions"}, + status="INFO", + summary=("diagnosis_basesystem_ynh_main_version", {"main_version": ynh_core_version[:3]}), + details=ynh_version_details) + else: + yield dict(meta={"test": "ynh_versions"}, + status="ERROR", + summary=("diagnosis_basesystem_ynh_inconsistent_versions", {}), + details=ynh_version_details) + + +def main(args, env, loggers): + return BaseSystemDiagnoser(args, env, loggers).diagnose() diff --git a/locales/en.json b/locales/en.json index 979edbbef..f942d3dc4 100644 --- a/locales/en.json +++ b/locales/en.json @@ -150,6 +150,11 @@ "custom_appslist_name_required": "You must provide a name for your custom app list", "diagnosis_debian_version_error": "Could not retrieve the Debian version: {error}", "diagnosis_kernel_version_error": "Could not retrieve kernel version: {error}", + "diagnosis_basesystem_host": "Server is running Debian {debian_version}.", + "diagnosis_basesystem_kernel": "Server is running Linux kernel {kernel_version}", + "diagnosis_basesystem_ynh_single_version": "{0} version: {1}", + "diagnosis_basesystem_ynh_main_version": "Server is running YunoHost {main_version}", + "diagnosis_basesystem_ynh_inconsistent_versions": "You are running inconsistents versions of the YunoHost packages ... most probably because of a failed or partial upgrade.", "diagnosis_monitor_disk_error": "Could not monitor disks: {error}", "diagnosis_monitor_system_error": "Could not monitor system: {error}", "diagnosis_no_apps": "No installed application", @@ -192,6 +197,7 @@ "diagnosis_security_all_good": "No critical security vulnerability was found.", "diagnosis_security_vulnerable_to_meltdown": "You appear vulnerable to the Meltdown criticial security vulnerability", "diagnosis_security_vulnerable_to_meltdown_details": "To fix this, you should upgrade your system and reboot to load the new linux kernel (or contact your server provider if this doesn't work). See https://meltdownattack.com/ for more infos.", + "diagnosis_description_basesystem": "Base system", "diagnosis_description_ip": "Internet connectivity", "diagnosis_description_dnsrecords": "DNS records", "diagnosis_description_services": "Services status check", diff --git a/src/yunohost/diagnosis.py b/src/yunohost/diagnosis.py index 6cf207282..b9fe111ed 100644 --- a/src/yunohost/diagnosis.py +++ b/src/yunohost/diagnosis.py @@ -74,7 +74,7 @@ def diagnosis_show(categories=[], issues=False, full=False, share=False): if "data" in item: del item["data"] if issues: - report["items"] = [item for item in report["items"] if item["status"] != "SUCCESS"] + report["items"] = [item for item in report["items"] if item["status"] in ["WARNING", "ERROR"]] # Ignore this category if no issue was found if not report["items"]: continue @@ -140,7 +140,7 @@ def diagnosis_run(categories=[], force=False): else: diagnosed_categories.append(category) if report != {}: - issues.extend([item for item in report["items"] if item["status"] != "SUCCESS"]) + issues.extend([item for item in report["items"] if item["status"] in ["WARNING", "ERROR"]]) if issues: if msettings.get("interface") == "api":