From e578140172378d2e48e7499dc2e4e2ee10d5887a Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 7 Nov 2019 15:57:26 +0100 Subject: [PATCH] Improve service diagnoser, report details related to configuration tests --- data/hooks/diagnosis/30-services.py | 30 +++++++++------------------- data/hooks/diagnosis/70-regenconf.py | 13 ------------ locales/en.json | 5 +++-- 3 files changed, 12 insertions(+), 36 deletions(-) diff --git a/data/hooks/diagnosis/30-services.py b/data/hooks/diagnosis/30-services.py index 6589d83f2..fed0a1156 100644 --- a/data/hooks/diagnosis/30-services.py +++ b/data/hooks/diagnosis/30-services.py @@ -5,17 +5,6 @@ import os from yunohost.diagnosis import Diagnoser from yunohost.service import service_status -# TODO : all these are arbitrary, should be collectively validated -services_ignored = {"glances"} -services_critical = {"dnsmasq", "fail2ban", "yunohost-firewall", "nginx", "slapd", "ssh"} -# TODO / FIXME : we should do something about this postfix thing -# The nominal value is to be "exited" ... some daemon is actually running -# in a different thread that the thing started by systemd, which is fine -# but somehow sometimes it gets killed and there's no easy way to detect it -# Just randomly restarting it will fix ths issue. We should find some trick -# to identify the PID of the process and check it's still up or idk -services_expected_to_be_exited = {"postfix", "yunohost-firewall"} - class ServicesDiagnoser(Diagnoser): id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1] @@ -28,23 +17,22 @@ class ServicesDiagnoser(Diagnoser): for service, result in all_result.items(): - if service in services_ignored: - continue - item = dict(meta={"service": service}) - expected_status = "running" if service not in services_expected_to_be_exited else "exited" - # TODO / FIXME : might also want to check that services are enabled + if result["status"] != "running": + item["status"] = "ERROR" + item["summary"] = ("diagnosis_services_bad_status", {"service": service, "status": result["status"]}) - if result["active"] != "active" or result["status"] != expected_status: - item["status"] = "WARNING" if service not in services_critical else "ERROR" - item["summary"] = ("diagnosis_services_bad_status", {"service": service, "status": result["active"] + "/" + result["status"]}) + elif result["configuration"] == "broken": + item["status"] = "WARNING" + item["summary"] = ("diagnosis_services_conf_broken", {"service": service}) - # TODO : could try to append the tail of the service log to the "details" key ... else: item["status"] = "SUCCESS" - item["summary"] = ("diagnosis_services_good_status", {"service": service, "status": result["active"] + "/" + result["status"]}) + item["summary"] = ("diagnosis_services_running", {"service": service, "status": result["status"]}) + if result["configuration"] == "broken": + item["details"] = [(d, tuple()) for d in result["configuration-details"]] yield item def main(args, env, loggers): diff --git a/data/hooks/diagnosis/70-regenconf.py b/data/hooks/diagnosis/70-regenconf.py index 105d43fa3..a04f5f98d 100644 --- a/data/hooks/diagnosis/70-regenconf.py +++ b/data/hooks/diagnosis/70-regenconf.py @@ -15,19 +15,6 @@ class RegenconfDiagnoser(Diagnoser): def run(self): - # nginx -t - p = subprocess.Popen("nginx -t".split(), - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT) - out, _ = p.communicate() - - if p.returncode != 0: - yield dict(meta={"test": "nginx-t"}, - status="ERROR", - summary=("diagnosis_regenconf_nginx_conf_broken", {}), - details=[(out, ())] - ) - regenconf_modified_files = manually_modified_files() debian_modified_files = manually_modified_files_compared_to_debian_default(ignore_handled_by_regenconf=True) diff --git a/locales/en.json b/locales/en.json index 751180a37..505bb44fd 100644 --- a/locales/en.json +++ b/locales/en.json @@ -180,8 +180,9 @@ "diagnosis_dns_bad_conf": "Bad / missing DNS configuration for domain {domain} (category {category})", "diagnosis_dns_missing_record": "According to the recommended DNS configuration, you should add a DNS record with type {0}, name {1} and value {2}", "diagnosis_dns_discrepancy": "According to the recommended DNS configuration, the value for the DNS record with type {0} and name {1} should be {2}, not {3}.", - "diagnosis_services_good_status": "Service {service} is {status} as expected!", - "diagnosis_services_bad_status": "Service {service} is {status} :/", + "diagnosis_services_running": "Service {service} is running!", + "diagnosis_services_conf_broken": "Configuration is broken for service {service}!", + "diagnosis_services_bad_status": "Service {service} is {status} :(", "diagnosis_diskusage_verylow": "Storage {mountpoint} (on device {device}) has only {free_abs_GB} GB ({free_percent}%) space remaining. You should really consider cleaning up some space.", "diagnosis_diskusage_low": "Storage {mountpoint} (on device {device}) has only {free_abs_GB} GB ({free_percent}%) space remaining. Be careful.", "diagnosis_diskusage_ok": "Storage {mountpoint} (on device {device}) still has {free_abs_GB} GB ({free_percent}%) space left!",