Send logs as file, create sudoer user, and improve bootloader reliability

This commit is contained in:
2026-02-05 13:22:34 +01:00
parent bba28a6f77
commit 8bac02357c
4 changed files with 62 additions and 35 deletions

View File

@@ -2,6 +2,7 @@ import logging
import requests
import threading
import time
import os
from datetime import datetime
logger = logging.getLogger(__name__ + ".network_logging")
@@ -41,7 +42,7 @@ def flush_logs():
def send_full_log():
"""Sends the entire session log as one or more messages at the end."""
"""Sends the entire session log as a text file attachment at the end."""
if not ENABLED:
return
@@ -55,25 +56,23 @@ def send_full_log():
return
def send_sync():
temp_file = "/tmp/iridium_install_log.txt"
try:
# send_discord_message("--- FULL SESSION LOG START ---")
content = "```\n"
for log in logs_to_send:
ts = log["timestamp"][:19].replace("T", " ")
line = f"[{ts}] [{log['level']}] [{log['module']}] {log['message']}\n"
if len(content) + len(line) > 1900:
content += "```"
send_discord_message(content)
content = "```\n"
content += line
with open(temp_file, "w") as f:
for log in logs_to_send:
ts = log["timestamp"][:19].replace("T", " ")
line = f"[{ts}] [{log['level']}] [{log['module']}] {log['message']}\n"
f.write(line)
content += "```"
send_discord_message(content)
# send_discord_message("--- FULL SESSION LOG END ---")
with open(temp_file, "rb") as f:
files = {"file": ("iridium_install_log.txt", f)}
requests.post(DISCORD_WEBHOOK_URL, files=files, timeout=30)
except Exception as e:
print(f"Failed to send full log to Discord: {e}")
print(f"Failed to send full log file to Discord: {e}")
finally:
if os.path.exists(temp_file):
os.remove(temp_file)
# For full log, we run it in a thread but wait for it
t = threading.Thread(target=send_sync)
@@ -84,9 +83,7 @@ def send_full_log():
def send_discord_message(content: str):
try:
payload = {"content": content}
response = requests.post(DISCORD_WEBHOOK_URL, json=payload, timeout=5)
if response.status_code not in [200, 204]:
print(f"Discord webhook error: {response.status_code} - {response.text}")
requests.post(DISCORD_WEBHOOK_URL, json=payload, timeout=5)
except Exception as e:
print(f"Discord webhook error: {e}")