v1.0
This commit is contained in:
@@ -3,7 +3,10 @@ Description=RPI Ping Check
|
|||||||
After=network.target
|
After=network.target
|
||||||
|
|
||||||
[Service]
|
[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
|
Restart=always
|
||||||
RestartSec=5
|
RestartSec=5
|
||||||
|
|
||||||
|
|||||||
@@ -82,19 +82,28 @@ def logout():
|
|||||||
logout_user()
|
logout_user()
|
||||||
return redirect(url_for('login'))
|
return redirect(url_for('login'))
|
||||||
|
|
||||||
@app.route('/')
|
@app.route("/")
|
||||||
@login_required
|
@login_required
|
||||||
def index():
|
def index():
|
||||||
devices = get_devices() # alle Devices aus der DB
|
conn = sqlite3.connect("sqlite.db")
|
||||||
status = load_device_status()
|
c = conn.cursor()
|
||||||
|
c.execute("SELECT mac, name FROM devices")
|
||||||
|
devices = c.fetchall()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
# Standardstatus, falls Gerät im Log noch nicht auftaucht
|
# Status aus letztem Log ermitteln
|
||||||
for d in devices:
|
import glob, os
|
||||||
if d['name'] not in status:
|
log_files = glob.glob("/var/log/rpi-*.log")
|
||||||
status[d['name']] = 'offline'
|
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_dict)
|
||||||
return render_template('index.html', devices=devices, status=status, interval=interval_min)
|
|
||||||
|
|
||||||
@app.route('/settings', methods=['GET', 'POST'])
|
@app.route('/settings', methods=['GET', 'POST'])
|
||||||
@login_required
|
@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 %}
|
{% block content %}
|
||||||
|
|
||||||
<h2>Dashboard</h2>
|
<h2>Dashboard</h2>
|
||||||
<div class="row">
|
<div class="row row-cols-1 row-cols-md-6 g-3">
|
||||||
{% for d in devices %}
|
{% for d in devices %}
|
||||||
<div class="col-md-2 col-sm-4 col-6 mb-3">
|
<div class="col">
|
||||||
<div class="card text-center shadow-sm">
|
<div class="card text-center p-2">
|
||||||
|
<div class="card-header">{{ d[1] }}</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h6 class="card-title">{{ d['name'] }}</h6>
|
<span class="fw-bold" style="color: {% if status[d[0]]=='online' %}green{% else %}red{% endif %};">
|
||||||
{% if d['status'] == 'online' %}
|
{% if status[d[0]] %}{{ status[d[0]]|capitalize }}{% else %}unbekannt{% endif %}
|
||||||
<p class="text-success">Online</p>
|
</span>
|
||||||
{% else %}
|
|
||||||
<p class="text-danger">Offline</p>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user