Add balance monitor, low-balance admin banner, dry-run auto-topup (sweep) framework

This commit is contained in:
drjones
2026-09-19 19:49:25 -07:00
parent 15c103eb65
commit 70a77e4987
4 changed files with 81 additions and 1 deletions

21
monitor.py Normal file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/env python3
"""Monitor IPRoyal reseller balance. Prints an ALERT line (for cron -> Telegram)
when below threshold. Exit 0 = OK, 1 = low/failed."""
import sys
import iproyal
threshold = iproyal.CFG.get("alerts", {}).get("low_balance_threshold", 10.0)
try:
bal = iproyal.get_balance()
except Exception as e:
print(f"ALERT: IPRoyal balance check FAILED: {e}")
sys.exit(1)
if isinstance(bal, (int, float)) and bal < threshold:
print(f"ALERT: IPRoyal reseller balance ${bal:.2f} is below ${threshold:.2f}. Top up now.")
sys.exit(1)
print(f"OK: IPRoyal balance ${bal}")
sys.exit(0)