Add check-nodered-backups.py
This commit is contained in:
51
check-nodered-backups.py
Normal file
51
check-nodered-backups.py
Normal file
@@ -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()
|
||||||
Reference in New Issue
Block a user