-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
90 lines (70 loc) · 2.71 KB
/
app.py
File metadata and controls
90 lines (70 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import subprocess
import re
import os
# OpenMind cron log dosyan
LOG_FILE = "/root/om-dev/log.txt"
def run(cmd):
return subprocess.run(cmd, shell=True, capture_output=True, text=True)
def check_openmind_screen():
r = run("screen -ls")
return "RUNNING" if "openmind" in r.stdout else "NOT RUNNING"
def analyze_recent_logs(tail_lines=400):
if not os.path.exists(LOG_FILE):
return {"status": "FAIL", "findings": [f"Log file not found: {LOG_FILE}"]}
with open(LOG_FILE, "r", encoding="utf-8", errors="ignore") as f:
lines = f.readlines()
recent = "".join(lines[-tail_lines:])
checks = [
("FAIL", r"panic|fatal|segmentation fault", "CRITICAL: panic/fatal/segfault"),
("FAIL", r"out of memory|oom killer|killed process", "CRITICAL: OOM / killed process"),
("WARN", r"connection refused|unable to connect|rpc.*(fail|error)", "WARN: RPC/connectivity issues"),
("WARN", r"timeout|timed out", "WARN: timeouts"),
("WARN", r"\berror\b|\bfailed\b", "WARN: error/failed keywords"),
]
findings = []
worst = "OK"
counts = {}
for level, pattern, msg in checks:
matches = re.findall(pattern, recent, flags=re.IGNORECASE)
if matches:
counts[msg] = len(matches)
findings.append(f"{msg} ({len(matches)})")
if level == "FAIL":
worst = "FAIL"
elif level == "WARN" and worst != "FAIL":
worst = "WARN"
# çok fazla error varsa FAIL
err_count = 0
for k, v in counts.items():
if "error/failed" in k.lower():
err_count = v
break
if worst == "WARN" and err_count >= 30:
worst = "FAIL"
findings.append("FAIL rule: too many error/failed occurrences in recent logs")
if not findings:
findings = ["No critical patterns found in recent logs."]
worst = "OK"
return {"status": worst, "findings": findings}
def main():
print("=== OpenMind Node Analyzer ===")
screen_status = check_openmind_screen()
print("Screen status:", screen_status)
log_report = analyze_recent_logs(tail_lines=400)
print("\nLog Analysis (last 400 lines):")
for f in log_report["findings"]:
print("-", f)
if screen_status != "RUNNING":
print("\n⚠️ OpenMind screen is NOT running. (FAIL)")
raise SystemExit(2)
if log_report["status"] == "FAIL":
print("\n⚠️ Attention required! (FAIL)")
raise SystemExit(2)
elif log_report["status"] == "WARN":
print("\n⚠️ Warnings found. (WARN)")
raise SystemExit(1)
else:
print("\n✅ Node looks healthy. (OK)")
raise SystemExit(0)
if __name__ == "__main__":
main()