v1.0
This commit is contained in:
@@ -3,7 +3,10 @@ Description=RPI Ping Check
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/local/bin/custom/poe.sh
|
||||
Type=simple
|
||||
User=root
|
||||
WorkingDirectory=/srv/poe_manager
|
||||
ExecStart=/srv/poe_manager/venv/bin/python3 /srv/poe_manager/poe_wrapper.py
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
|
||||
|
||||
@@ -82,19 +82,28 @@ def logout():
|
||||
logout_user()
|
||||
return redirect(url_for('login'))
|
||||
|
||||
@app.route('/')
|
||||
@app.route("/")
|
||||
@login_required
|
||||
def index():
|
||||
devices = get_devices() # alle Devices aus der DB
|
||||
status = load_device_status()
|
||||
conn = sqlite3.connect("sqlite.db")
|
||||
c = conn.cursor()
|
||||
c.execute("SELECT mac, name FROM devices")
|
||||
devices = c.fetchall()
|
||||
conn.close()
|
||||
|
||||
# Standardstatus, falls Gerät im Log noch nicht auftaucht
|
||||
for d in devices:
|
||||
if d['name'] not in status:
|
||||
status[d['name']] = 'offline'
|
||||
# Status aus letztem Log ermitteln
|
||||
import glob, os
|
||||
log_files = glob.glob("/var/log/rpi-*.log")
|
||||
status_dict = {}
|
||||
if log_files:
|
||||
latest_log = max(log_files, key=os.path.getctime)
|
||||
with open(latest_log, "r") as f:
|
||||
for line in f:
|
||||
for dev in devices:
|
||||
if dev[1] in line:
|
||||
status_dict[dev[0]] = "online" if "erreichbar" in line else "offline"
|
||||
|
||||
interval_min = get_interval_seconds() // 60
|
||||
return render_template('index.html', devices=devices, status=status, interval=interval_min)
|
||||
return render_template("index.html", devices=devices, status=status_dict)
|
||||
|
||||
@app.route('/settings', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
|
||||
9
srv/poe_manager/poe_wrapper.py
Normal file
9
srv/poe_manager/poe_wrapper.py
Normal file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env python3
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
# Virtuelle Umgebung aktivieren (Pfad zu deinem venv)
|
||||
venv_python = "/srv/poe_manager/venv/bin/python3"
|
||||
|
||||
# Poe.sh über bash ausführen, innerhalb der venv
|
||||
subprocess.run(["/bin/bash", "/usr/local/bin/custom/poe.sh"], env={"PATH": f"/srv/poe_manager/venv/bin:" + os.environ["PATH"]})
|
||||
@@ -2,17 +2,15 @@
|
||||
{% block content %}
|
||||
|
||||
<h2>Dashboard</h2>
|
||||
<div class="row">
|
||||
<div class="row row-cols-1 row-cols-md-6 g-3">
|
||||
{% for d in devices %}
|
||||
<div class="col-md-2 col-sm-4 col-6 mb-3">
|
||||
<div class="card text-center shadow-sm">
|
||||
<div class="col">
|
||||
<div class="card text-center p-2">
|
||||
<div class="card-header">{{ d[1] }}</div>
|
||||
<div class="card-body">
|
||||
<h6 class="card-title">{{ d['name'] }}</h6>
|
||||
{% if d['status'] == 'online' %}
|
||||
<p class="text-success">Online</p>
|
||||
{% else %}
|
||||
<p class="text-danger">Offline</p>
|
||||
{% endif %}
|
||||
<span class="fw-bold" style="color: {% if status[d[0]]=='online' %}green{% else %}red{% endif %};">
|
||||
{% if status[d[0]] %}{{ status[d[0]]|capitalize }}{% else %}unbekannt{% endif %}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user