import subprocess,json,time,datetime,sys LOG="/var/www/html/sentinel-monitor.log" STATUS="/var/www/html/sentinel-status.json" CHECKS={"S88_nginx":"systemctl is-active nginx","S88_phpfpm":"systemctl is-active php8.3-fpm","S88_node":"curl -s -o /dev/null -w '%{http_code}' --connect-timeout 5 http://127.0.0.1:3001/api/actualites","S88_ollama":"curl -s -o /dev/null -w '%{http_code}' --connect-timeout 5 http://127.0.0.1:11434/api/tags","S88_site":"curl -s -o /dev/null -w '%{http_code}' --connect-timeout 5 https://weval-consulting.com/","S88_disk":"df / --output=pcent | tail -1 | tr -d ' %'","S95_sentinel":"curl -s -o /dev/null -w '%{http_code}' --connect-timeout 5 http://95.216.167.89:5890/","S95_adx":"curl -s -o /dev/null -w '%{http_code}' --connect-timeout 5 http://95.216.167.89:5821/","S151_http":"curl -s -o /dev/null -w '%{http_code}' --connect-timeout 5 http://151.80.235.110/","S202_http":"curl -s -o /dev/null -w '%{http_code}' --connect-timeout 5 http://204.168.152.13/"} def run(cmd): try: r=subprocess.run(cmd,shell=True,capture_output=True,text=True,timeout=15);return r.stdout.strip() except:return "TIMEOUT" def is_ok(k,v): if "disk" in k:return v.isdigit() and int(v)<85 if "ram" in k:return v.isdigit() and int(v)<90 return v in ["active","200","301","302","401"] def check(): ts=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S");results={};alerts=[] for k,cmd in CHECKS.items(): v=run(cmd);ok=is_ok(k,v);results[k]={"v":v,"ok":ok} if not ok:alerts.append(k+"="+v) ok_n=sum(1 for r in results.values() if r["ok"]);line="[%s] %d/%d OK"%(ts,ok_n,len(results)) if alerts:line+=" | ALERTS: "+",".join(alerts) open(LOG,"a").write(line+"\n");json.dump({"ts":ts,"checks":results,"alerts":alerts},open(STATUS,"w")) print(line) if __name__=="__main__": if "--daemon" in sys.argv: while True: try:check() except:pass time.sleep(120) else:check()