Files
pleiades/monitor.py

22 lines
612 B
Python

#!/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)