Files
html/top-ia/proactive_scan.sh

36 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
python3 <<'PY'
import subprocess, json, os
def sh(c):
try: return subprocess.check_output(c, shell=True, timeout=5).decode().strip()
except: return ""
issues = []
# 1. SIGKILL recent
sk = sh("sudo tail -100 /var/log/php8.5-fpm.log 2>/dev/null | grep -c SIGKILL")
if sk.isdigit() and int(sk) > 10: issues.append(f"SIGKILL: {sk} in last 100 lines")
# 2. Disk >85%
disk = sh("df -h / | tail -1 | awk '{print $5}' | tr -d %")
if disk.isdigit() and int(disk) > 85: issues.append(f"Disk: {disk}%")
# 3. Load >3.0
load = float(sh("cut -d' ' -f1 /proc/loadavg") or 0)
if load > 3.0: issues.append(f"Load: {load}")
# 4. Git dirty
dirty = sh("cd /var/www/html && git status --short | wc -l")
if dirty.isdigit() and int(dirty) > 20: issues.append(f"Git dirty: {dirty} files")
# 5. Ollama down
ol = sh("curl -sS --max-time 2 http://localhost:11434/api/version 2>&1 | head -c 50")
if 'version' not in ol: issues.append("Ollama DOWN")
# 6. Qdrant down
qd = sh("curl -sS --max-time 2 http://localhost:6333/ 2>&1 | head -c 50")
if 'qdrant' not in qd.lower() and 'title' not in qd.lower(): issues.append("Qdrant DOWN")
# 7. NR fail
nr = sh("curl -sS --max-time 5 http://localhost/api/nonreg-api.php?cat=all 2>/dev/null")
if nr:
try:
d = json.loads(nr)
if d.get('score',100) < 100: issues.append(f"NR: {d.get('pass')}/{d.get('total')}")
except: pass
status = "OK" if not issues else "ANOMALIES"
print(json.dumps({"status":status,"count":len(issues),"issues":issues}))
PY