diff --git a/.gitignore b/.gitignore index e87758c..c86d868 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,33 @@ +# Alles ignorieren * -!/*.gitignore + +# .gitignore selbst tracken +!.gitignore + +# Virtuelle Umgebung ignorieren +venv/ +__pycache__/ + +# Logfiles ignorieren +*.log + +# Systemd Services tracken !etc/ !etc/systemd/ -!etc/systemd/system +!etc/systemd/system/ !etc/systemd/system/rpi*.service !etc/systemd/system/rpi*.timer + +# Custom Scripts tracken !usr/ !usr/local/ !usr/local/bin/ !usr/local/bin/custom/ !usr/local/bin/custom/* + +# Web-App Dateien im poe_manager tracken +!/srv/poe_manager/ +!/srv/poe_manager/* + +# Optional: SQLite DB ignorieren (falls du nicht willst, dass Passwörter im Repo landen) +# /srv/poe_manager/sqlite.db diff --git a/usr/local/bin/custom/poe.sh b/usr/local/bin/custom/poe.sh index 40e78f7..507bf87 100644 --- a/usr/local/bin/custom/poe.sh +++ b/usr/local/bin/custom/poe.sh @@ -1,19 +1,33 @@ #!/bin/bash -USER="" -PASS="" -IP_FILE="/usr/local/bin/custom/ips.list" LOGFILE="/var/log/rpi-$(date '+%Y%m%d%H%M%S').log" +IP_FILE=$(python3 /srv/poe_manager/generate_ips.py) + +# Intervall aus DB (Sekunden) abrufen +SLEEP=$(python3 - < $" { } } @@ -37,13 +51,15 @@ EOF function enable_poe() { local switch_ip=$1 - local port=$2 + local switch_port=$2 + local username=$3 + local password=$4 expect < $" { } } @@ -67,19 +83,21 @@ EOF echo "" > $LOGFILE while true; do - echo "--------------------------------------------------------------------" >> $LOGFILE - while IFS=: read -r ip switch port hap; do - ping -c 1 -W 2 $ip &> /dev/null - if [ $? -ne 0 ]; then - echo "$(date '+%Y-%m-%d %H:%M:%S') $hap ist nicht erreichbar!" >> $LOGFILE - disable_poe $switch $port - echo "$(date '+%Y-%m-%d %H:%M:%S') $hap PoE auf Port $port für IP $ip am Switch $switch deaktiviert." >> $LOGFILE - sleep 2 - enable_poe $switch $port - echo "$(date '+%Y-%m-%d %H:%M:%S') $hap PoE auf Port $port für IP $ip am Switch $switch aktiviert." >> $LOGFILE - else - echo "$(date '+%Y-%m-%d %H:%M:%S') $hap ist erreichbar!" >> $LOGFILE - fi - done < "$IP_FILE" - sleep 300 -done \ No newline at end of file + echo "--------------------------------------------------------------------" >> $LOGFILE + IP_FILE=$(python3 /srv/poe_manager/generate_ips.py) + while IFS=: read -r rpi_ip dev_name switch_ip switch_hostname switch_port switch_user switch_pass; do + ping -c 1 -W 2 "$rpi_ip" &> /dev/null + if [ $? -ne 0 ]; then + echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name ist nicht erreichbar!" >> $LOGFILE + disable_poe "$switch_ip" "$switch_port" "$switch_user" "$switch_pass" + echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name PoE auf Port $switch_port am Switch $switch_hostname deaktiviert." >> $LOGFILE + sleep 2 + enable_poe "$switch_ip" "$switch_port" "$switch_user" "$switch_pass" + echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name PoE auf Port $switch_port am Switch $switch_hostname aktiviert." >> $LOGFILE + else + echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name ist erreichbar!" >> $LOGFILE + fi + done < "$IP_FILE" + rm -f "$IP_FILE" + sleep $SLEEP +done