mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Implement a first version for services status check
This commit is contained in:
parent
aed53786f2
commit
1019e95b1d
2 changed files with 57 additions and 0 deletions
54
data/hooks/diagnosis/30-services.py
Normal file
54
data/hooks/diagnosis/30-services.py
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
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]
|
||||||
|
cache_duration = 300
|
||||||
|
|
||||||
|
def validate_args(self, args):
|
||||||
|
# TODO / FIXME Ugh do we really need this arg system
|
||||||
|
return {}
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
|
||||||
|
all_result = service_status()
|
||||||
|
|
||||||
|
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["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"]})
|
||||||
|
|
||||||
|
# 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"]})
|
||||||
|
|
||||||
|
yield item
|
||||||
|
|
||||||
|
def main(args, env, loggers):
|
||||||
|
return ServicesDiagnoser(args, env, loggers).diagnose()
|
|
@ -166,8 +166,11 @@
|
||||||
"diagnosis_dns_bad_conf": "Bad DNS configuration for domain {domain} (category {category})",
|
"diagnosis_dns_bad_conf": "Bad 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_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_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_description_ip": "Internet connectivity",
|
"diagnosis_description_ip": "Internet connectivity",
|
||||||
"diagnosis_description_dnsrecords": "DNS records",
|
"diagnosis_description_dnsrecords": "DNS records",
|
||||||
|
"diagnosis_description_services": "Services status check",
|
||||||
"domain_cannot_remove_main": "Cannot remove main domain. Set a new main domain first",
|
"domain_cannot_remove_main": "Cannot remove main domain. Set a new main domain first",
|
||||||
"domain_cert_gen_failed": "Could not generate certificate",
|
"domain_cert_gen_failed": "Could not generate certificate",
|
||||||
"domain_created": "Domain created",
|
"domain_created": "Domain created",
|
||||||
|
|
Loading…
Add table
Reference in a new issue