From ed4a820bf69339ae9058110d4681e8d9fcf4f6de Mon Sep 17 00:00:00 2001 From: kyle Date: Wed, 31 Dec 2025 04:26:24 -0800 Subject: [PATCH] Add check-nodered-backups.py --- check-nodered-backups.py | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 check-nodered-backups.py diff --git a/check-nodered-backups.py b/check-nodered-backups.py new file mode 100644 index 0000000..345dbb7 --- /dev/null +++ b/check-nodered-backups.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +"""Check Node-RED status and backup information""" +import urllib.request +import json +import sys + +TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI4NmM2ZGNlMTY2MWU0M2U5YjQ2MDI3MjMxYjE0NDFlMyIsImlhdCI6MTc2NzE3ODUyNiwiZXhwIjoyMDgyNTM4NTI2fQ.E8eShOsejwDYglixpgM_d_JYBlB1OVNhN7cHPnPiLOs" +HA_URL = "http://192.168.68.25:8123" + +def check_nodered(): + """Check Node-RED entities""" + url = f"{HA_URL}/api/states" + req = urllib.request.Request(url) + req.add_header("Authorization", f"Bearer {TOKEN}") + + try: + with urllib.request.urlopen(req) as response: + states = json.loads(response.read().decode()) + + # Find Node-RED entities + nodered = [e for e in states if 'nodered' in e['entity_id'].lower()] + + print("Node-RED Status:") + print("="*60) + if nodered: + for entity in sorted(nodered, key=lambda x: x['entity_id']): + print(f"{entity['entity_id']}: {entity.get('state', 'N/A')}") + else: + print("No Node-RED entities found") + print("Node-RED might not be running or configured") + + print() + + # Check backups + print("Backup Information:") + print("="*60) + backups = [e for e in states if 'backup' in e['entity_id'].lower()] + for entity in sorted(backups, key=lambda x: x['entity_id']): + eid = entity['entity_id'] + state = entity.get('state', 'N/A') + attrs = entity.get('attributes', {}) + name = attrs.get('friendly_name', eid) + print(f"{name}: {state}") + + return True + except Exception as e: + print(f"Error: {e}", file=sys.stderr) + return False + +if __name__ == '__main__': + check_nodered()