Files
SnarfCode/scripts/update_heimdall_ha.py

53 lines
1.5 KiB
Python

import paramiko
import sys
import json
sys.stdout.reconfigure(encoding='utf-8')
key_path = r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet'
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("140.44.4.75", username="root", key_filename=key_path, timeout=10)
py_script = """
import sqlite3, json
conn = sqlite3.connect('/var/lib/docker/volumes/heimdall_heimdall_config/_data/www/app.sqlite')
cur = conn.cursor()
# Backup first
cur.execute("SELECT id, title, description FROM items WHERE id IN (12, 44)")
rows = cur.fetchall()
for r in rows:
print('Before:', r)
cfg = json.loads(r[2])
cfg['override_url'] = 'http://14.4.4.20:8123/'
new_desc = json.dumps(cfg)
cur.execute("UPDATE items SET description = ? WHERE id = ?", (new_desc, r[0]))
# Also clear cache table if any
cur.execute("DELETE FROM cache")
conn.commit()
print('Cache cleared and items updated!')
cur.execute("SELECT id, title, description FROM items WHERE id IN (12, 44)")
for r in cur.fetchall():
print('After:', r)
conn.close()
"""
c.exec_command("cat << 'EOF' > /tmp/update_h_ha.py\n" + py_script + "\nEOF\n")
stdin, stdout, stderr = c.exec_command("python3 /tmp/update_h_ha.py")
print(stdout.read().decode())
err = stderr.read().decode()
if err: print("Stderr:", err)
# Trigger a curl to Heimdall item livestats
print("\nTesting Heimdall live stats endpoint:")
stdin, stdout, stderr = c.exec_command("docker exec $(docker ps -q -f name=heimdall) curl -s http://127.0.0.1/get_stats/44")
print(stdout.read().decode())
c.close()