Report devices with old or missing backups
A backup system’s real risk is the device nobody noticed it stopped backing up. This recipe reads every device from rConfig, checks when its last backup finished and whether it succeeded, and lists the ones that need attention: failed, too old, or never backed up. It writes a CSV for a daily report and exits non-zero when anything is wrong, so a monitoring system can run it as a check.
How it works
- Page through v2
GET /deviceswithwith_credentials=false. - Skip disabled devices (
status100). - Read each device’s
last_backup_statusandlast_backup_at. - Flag the device if the last backup failed, failed its integrity check, is older than the limit, or never happened.
For one quick total instead of a device list, v2 GET /devices/summary returns counts of successful, failed and never-backed-up devices.
What you need
- A token with
devices.readonly. Its owner’s role decides which devices are checked; an administrator’s token checks everything. - Python 3 with
requests. - rConfig’s time zone.
last_backup_atis in rConfig’s local time (theTIMEZONEsetting in its.env,Europe/Dublinunless changed), with no zone attached. SetSERVER_TZin the script to match.
The script
Save it as rconfig_backup_coverage.py.
#!/usr/bin/env python3"""List rConfig devices whose last backup failed, is too old, or never happened.
Usage: RCONFIG_URL=https://rconfig.example.com RCONFIG_TOKEN=... \ python3 rconfig_backup_coverage.py [max_age_hours] > coverage.csv
Exit code 0 when every device is covered, 1 when any device is flagged,2 when the check itself fails (so monitoring can tell them apart)."""
import csvimport osimport sysfrom datetime import datetime, timedeltafrom zoneinfo import ZoneInfo
import requests
SERVER_TZ = ZoneInfo("Europe/Dublin") # rConfig's TIMEZONE setting (Europe/Dublin unless changed)DISABLED = 100STATUS_TEXT = {0: "failed", 1: "ok", 2: "ok (integrity unknown)", 3: "integrity check failed"}
BASE = os.environ.get("RCONFIG_URL", "").rstrip("/")TOKEN = os.environ.get("RCONFIG_TOKEN", "")
def devices(): page = 1 while True: response = requests.get(f"{BASE}/api/v2/devices", timeout=60, headers={"apitoken": TOKEN, "Accept": "application/json"}, params={"per_page": 100, "page": page, "with_credentials": "false"}) response.raise_for_status() body = response.json() yield from body["data"] if body["next_page_url"] is None: return page += 1
def problem(device, now, max_age): status, finished = device.get("last_backup_status"), device.get("last_backup_at") if status is None or not finished: return "never backed up" if status in (0, 3): return STATUS_TEXT[status] age = now - datetime.fromisoformat(finished.replace(" ", "T")).replace(tzinfo=SERVER_TZ) if age > max_age: return f"last backup {age.days}d {age.seconds // 3600}h ago" return None
def main(): if not BASE or not TOKEN: print("set RCONFIG_URL and RCONFIG_TOKEN", file=sys.stderr) return 2 max_age = timedelta(hours=float(sys.argv[1]) if len(sys.argv) > 1 else 26) now = datetime.now(SERVER_TZ)
out = csv.writer(sys.stdout) out.writerow(["device_id", "device_name", "device_ip", "last_backup_at", "problem"]) checked = flagged = 0 try: for device in devices(): if device.get("status") == DISABLED: continue checked += 1 reason = problem(device, now, max_age) if reason: flagged += 1 out.writerow([device["id"], device["device_name"], device["device_ip"], device.get("last_backup_at") or "", reason]) except requests.RequestException as exc: print(f"check failed: {exc}", file=sys.stderr) return 2
print(f"{flagged} of {checked} enabled devices need attention", file=sys.stderr) return 1 if flagged else 0
if __name__ == "__main__": sys.exit(main())The default limit is 26 hours: a daily backup plus two hours’ grace. Set it a little above your backup schedule’s interval.
What it writes
device_id,device_name,device_ip,last_backup_at,problem31,branch-fw-07,198.51.100.7,2026-11-12 02:00:41,last backup 3d 7h ago44,lab-sw-03,192.0.2.44,2026-11-15 02:01:10,failed58,new-ap-12,192.0.2.112,,never backed upOn stderr: 3 of 361 enabled devices need attention.
Adapting it
- As a monitoring check. Run it from Nagios, Zabbix or similar; the exit codes follow the usual convention for “OK” and “problem”, with
2meaning the check couldn’t run. - Different limits per group. Each device comes with its
categoryandtagrelations; pick the limit per category or tag. - A weekly email. Run it from cron and mail the CSV when the exit code is
1. - Already covered by a playbook? If your team uses AI agents, the Iris backup coverage audit loop does a similar check through MCP.