#!/usr/bin/env python3 """walk_fill_t1.py — claims backup.fill-warning and fail.drive-filling on Tester 1: a data drive fills; is the household warned BEFORE it is full, in Hungarian, naming the drive and the free space, once? A test file (fallocate, no write load) takes `adatlemez` over 85 %; the watcher runs every 10 minutes (R-363). The household's address is typed on the notification page and cleared after. The file goes after the mail; the back-to-normal line is read.""" import os, re, sys, time sys.path.insert(0, "/mnt/5_hdd/felhom.eu/git/app-catalog-felhom.eu/scripts") os.environ.setdefault("TARGET", "tester-1") import box_walk as w EV, ADDRESS = os.environ["EV"], "tester1@felhom.eu" DRIVE = "/mnt/felhom-drives/adatlemez" FILE = f"{DRIVE}/sec1102-fill.bin" def form(fields): sess = open(f"{w.SC}/sess{os.getpid()}.txt").read().strip() csrf = open(f"{w.SC}/csrf{os.getpid()}.txt").read().strip() args = ["curl", "-sk", "-D", "-", "-o", "/dev/null", "-H", w.HOSTHDR, "-H", f"Cookie: {sess}", "-X", "POST", "--data-urlencode", f"_csrf={csrf}"] for k, v in fields: args += ["--data-urlencode", f"{k}={v}"] return (w.sh(args + [f"{w.BASE}/settings/notifications"], timeout=60).stdout or "").split("\n")[0].strip() def log_since(t, rx): return w.guest(f"docker logs --since {t} felhom-controller 2>&1 | grep -aE '{rx}' | grep -av DEBUG | cut -b1-260 | iconv -c -t ascii//TRANSLIT | tail -8") w.login() page = w.page("/settings/notifications") page = page if isinstance(page, str) else str(page) fields = [("notification_email", ADDRESS), ("cooldown_hours", "6")] for m in re.finditer(r' {form(fields)}") time.sleep(10) w.say(" before: " + w.guest(f"df -h --output=size,used,avail,pcent {DRIVE} | tail -1")) avail = int(w.guest(f"df -B1G --output=size {DRIVE} | tail -1").strip()) * 86 // 100 - int(w.guest(f"df -B1G --output=used {DRIVE} | tail -1").strip()) w.say(f" filling with {avail} GiB: " + w.guest(f"fallocate -l {avail}G {FILE} && df -h --output=used,avail,pcent {DRIVE} | tail -1")) t0 = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()) for _ in range(50): time.sleep(15) got = log_since(t0, "fillwatch.*(notification|warning|critical)") if re.search(r"[1-9] notification", got): break w.say(f" the watcher, {time.strftime('%H:%M:%S', time.gmtime())}:\n{got}") w.say(" events:\n" + log_since(t0, "Event pushed: (disk_|storage_)")) time.sleep(int(os.environ.get("MAIL_WAIT_S", "90"))) w.say(" removing the file: " + w.guest(f"rm -f {FILE}; df -h --output=used,avail,pcent {DRIVE} | tail -1")) t1 = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()) for _ in range(50): time.sleep(15) got = log_since(t1, "fillwatch.*[1-9] notification|Event pushed: (disk_|storage_)") if got.strip(): break w.say(f" back to normal, {time.strftime('%H:%M:%S', time.gmtime())}:\n{got}") sess = open(f"{w.SC}/sess{os.getpid()}.txt").read().strip() w.say(" the address cleared -> " + form([("notification_email", ""), ("confirm_clear", "1"), ("cooldown_hours", "6")])) time.sleep(3) p2 = w.page("/settings/notifications") p2 = p2 if isinstance(p2, str) else str(p2) w.say(" the page's address now: " + repr((re.search(r'name="notification_email"\s*value="([^"]*)"', p2) or [None, "?"])[1])) w.say(" left on the drive: " + w.guest(f"ls -la {DRIVE} | grep -c sec1102; df -h --output=used,avail,pcent {DRIVE} | tail -1")) open(os.path.join(EV, "fill-walk.log"), "w").write("\n".join(w.LOG) + "\n")