srv/poe_manager/app.py aktualisiert
This commit is contained in:
@@ -444,36 +444,43 @@ def logs():
|
|||||||
return render_template('logs.html', log_content=log_content, log_name=os.path.basename(latest_log), interval=interval)
|
return render_template('logs.html', log_content=log_content, log_name=os.path.basename(latest_log), interval=interval)
|
||||||
|
|
||||||
def load_device_status():
|
def load_device_status():
|
||||||
"""
|
|
||||||
Liest das aktuellste rpi-Logfile und extrahiert den letzten Status jedes Devices.
|
|
||||||
Gibt ein Dictionary zurück: {Device-Name: 'online'/'offline'}
|
|
||||||
"""
|
|
||||||
status = {}
|
status = {}
|
||||||
|
|
||||||
|
# Devices aus DB laden (Name → MAC)
|
||||||
|
conn = sqlite3.connect("sqlite.db")
|
||||||
|
conn.row_factory = sqlite3.Row
|
||||||
|
devices = conn.execute("SELECT mac, name FROM devices").fetchall()
|
||||||
|
name_to_mac = {d['name']: d['mac'] for d in devices}
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
# Logfile
|
||||||
log_files = glob.glob("/var/log/rpi-*.log")
|
log_files = glob.glob("/var/log/rpi-*.log")
|
||||||
if not log_files:
|
if not log_files:
|
||||||
return status
|
return status
|
||||||
|
|
||||||
latest_log = max(log_files, key=os.path.getctime)
|
latest_log = max(log_files, key=os.path.getctime)
|
||||||
|
|
||||||
# Jede Zeile des Logs lesen
|
|
||||||
with open(latest_log, "r") as f:
|
|
||||||
lines = f.readlines()
|
|
||||||
|
|
||||||
# Regex für Ping-Ergebnisse
|
|
||||||
online_re = re.compile(r"(\S+) ist erreichbar!")
|
online_re = re.compile(r"(\S+) ist erreichbar!")
|
||||||
offline_re = re.compile(r"(\S+) ist nicht erreichbar!")
|
offline_re = re.compile(r"(\S+) ist nicht erreichbar!")
|
||||||
|
|
||||||
for line in lines:
|
with open(latest_log, "r") as f:
|
||||||
line = line.strip()
|
for line in f:
|
||||||
m_online = online_re.search(line)
|
line = line.strip()
|
||||||
m_offline = offline_re.search(line)
|
m_online = online_re.search(line)
|
||||||
if m_online:
|
m_offline = offline_re.search(line)
|
||||||
status[m_online.group(1)] = 'online'
|
if m_online:
|
||||||
elif m_offline:
|
name = m_online.group(1)
|
||||||
status[m_offline.group(1)] = 'offline'
|
mac = name_to_mac.get(name)
|
||||||
|
if mac:
|
||||||
|
status[mac] = 'online'
|
||||||
|
elif m_offline:
|
||||||
|
name = m_offline.group(1)
|
||||||
|
mac = name_to_mac.get(name)
|
||||||
|
if mac:
|
||||||
|
status[mac] = 'offline'
|
||||||
|
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
|
||||||
@app.route("/users", methods=["GET", "POST"])
|
@app.route("/users", methods=["GET", "POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def users():
|
def users():
|
||||||
|
|||||||
Reference in New Issue
Block a user