Skip to content

Commit

Permalink
centralized logging function for shell skripts
Browse files Browse the repository at this point in the history
  • Loading branch information
benderl committed Jan 27, 2021
1 parent 2dc6237 commit 9b4da8b
Show file tree
Hide file tree
Showing 24 changed files with 640 additions and 1,117 deletions.
36 changes: 17 additions & 19 deletions auslademodus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,35 @@
auslademodus(){
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatus"; then
runs/set-current.sh 0 m
echo "$date LP1, Lademodus Stop. Stoppe Ladung" >> ramdisk/ladestatus.log
openwbDebugLog "CHARGESTAT" 0 "LP1, Lademodus Stop. Stoppe Ladung"
fi
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatuss1"; then
runs/set-current.sh 0 s1
echo "$date LP2, Lademodus Stop. Stoppe Ladung" >> ramdisk/ladestatus.log
openwbDebugLog "CHARGESTAT" 0 "LP2, Lademodus Stop. Stoppe Ladung"
fi
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatuss2"; then
runs/set-current.sh 0 s2
echo "$date LP3, Lademodus Stop. Stoppe Ladung" >> ramdisk/ladestatus.log

openwbDebugLog "CHARGESTAT" 0 "LP3, Lademodus Stop. Stoppe Ladung"
fi
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatuslp4"; then
runs/set-current.sh 0 lp4
echo "$date LP4, Lademodus Stop. Ladefreigabe noch aktiv. Stoppe Ladung" >> ramdisk/ladestatus.log
openwbDebugLog "CHARGESTAT" 0 "LP4, Lademodus Stop. Stoppe Ladung"
fi
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatuslp5"; then
runs/set-current.sh 0 lp5
echo "$date LP5, Lademodus Stop. Ladefreigabe noch aktiv. Stoppe Ladung" >> ramdisk/ladestatus.log
openwbDebugLog "CHARGESTAT" 0 "LP5, Lademodus Stop. Stoppe Ladung"
fi
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatuslp6"; then
runs/set-current.sh 0 lp6
echo "$date LP6, Lademodus Stop. Stoppe Ladung" >> ramdisk/ladestatus.log
openwbDebugLog "CHARGESTAT" 0 "LP6, Lademodus Stop. Stoppe Ladung"
fi
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatuslp7"; then
runs/set-current.sh 0 lp7
echo "$date LP7, Lademodus Stop. Stoppe Ladung" >> ramdisk/ladestatus.log
openwbDebugLog "CHARGESTAT" 0 "LP7, Lademodus Stop. Stoppe Ladung"
fi
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatuslp8"; then
runs/set-current.sh 0 lp8
echo "$date LP8, Lademodus Stop. Stoppe Ladung" >> ramdisk/ladestatus.log
openwbDebugLog "CHARGESTAT" 0 "LP8, Lademodus Stop. Stoppe Ladung"
fi
if (( ladeleistung > 300 )); then
runs/set-current.sh 0 m
Expand All @@ -44,44 +43,43 @@ auslademodus(){
runs/set-current.sh 0 lp7
runs/set-current.sh 0 lp8

echo "$date Alle Ladepunkte, Lademodus Stop. Stoppe Ladung" >> ramdisk/ladestatus.log

openwbDebugLog "CHARGESTAT" 0 "Alle Ladepunkte, Lademodus Stop. Stoppe Ladung"
fi
exit 0
}

semiauslademodus(){
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatus"; then
runs/set-current.sh 0 m
echo "$date LP1, Lademodus Standby. Ladefreigabe noch aktiv. Stoppe Ladung" >> ramdisk/ladestatus.log
openwbDebugLog "CHARGESTAT" 0 "LP1, Lademodus Standby. Ladefreigabe noch aktiv. Stoppe Ladung"
fi
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatuss1"; then
runs/set-current.sh 0 s1
echo "$date LP2, Lademodus Standby. Ladefreigabe noch aktiv. Stoppe Ladung" >> ramdisk/ladestatus.log
openwbDebugLog "CHARGESTAT" 0 "LP2, Lademodus Standby. Ladefreigabe noch aktiv. Stoppe Ladung"
fi
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatuss2"; then
runs/set-current.sh 0 s2
echo "$date LP3, Lademodus Standby. Ladefreigabe noch aktiv. Stoppe Ladung" >> ramdisk/ladestatus.log
openwbDebugLog "CHARGESTAT" 0 "LP3, Lademodus Standby. Ladefreigabe noch aktiv. Stoppe Ladung"
fi
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatuslp4"; then
runs/set-current.sh 0 lp4
echo "$date LP4, Lademodus Standby. Ladefreigabe noch aktiv. Stoppe Ladung" >> ramdisk/ladestatus.log
openwbDebugLog "CHARGESTAT" 0 "LP4, Lademodus Standby. Ladefreigabe noch aktiv. Stoppe Ladung"
fi
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatuslp5"; then
runs/set-current.sh 0 lp5
echo "$date LP5, Lademodus Standby. Ladefreigabe noch aktiv. Stoppe Ladung" >> ramdisk/ladestatus.log
openwbDebugLog "CHARGESTAT" 0 "LP5, Lademodus Standby. Ladefreigabe noch aktiv. Stoppe Ladung"
fi
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatuslp6"; then
runs/set-current.sh 0 lp6
echo "$date LP6, Lademodus Standby. Ladefreigabe noch aktiv. Stoppe Ladung" >> ramdisk/ladestatus.log
openwbDebugLog "CHARGESTAT" 0 "LP6, Lademodus Standby. Ladefreigabe noch aktiv. Stoppe Ladung"
fi
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatuslp7"; then
runs/set-current.sh 0 lp7
echo "$date LP7, Lademodus Standby. Ladefreigabe noch aktiv. Stoppe Ladung" >> ramdisk/ladestatus.log
openwbDebugLog "CHARGESTAT" 0 "LP7, Lademodus Standby. Ladefreigabe noch aktiv. Stoppe Ladung"
fi
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatuslp8"; then
runs/set-current.sh 0 lp8
echo "$date LP8, Lademodus Standby. Ladefreigabe noch aktiv. Stoppe Ladung" >> ramdisk/ladestatus.log
openwbDebugLog "CHARGESTAT" 0 "LP8, Lademodus Standby. Ladefreigabe noch aktiv. Stoppe Ladung"
fi

exit 0
Expand Down
48 changes: 18 additions & 30 deletions evsedintest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ evsedintest() {
sleep 1
evsedinstat=$(sudo python runs/readmodbus.py $modbusevsesource $modbusevseid 1000 1)
if [[ $evsedinstat == "9" ]]; then
echo "EVSE LP1 Prüfung erfolgreich"
openwbDebugLog "MAIN" 0 "EVSE LP1 Prüfung erfolgreich"
echo "erfolgreich" > ramdisk/evsedintestlp1
else
echo "EVSE LP1 Prüfung NICHt erfolgreich"
openwbDebugLog "MAIN" 0 "EVSE LP1 Prüfung NICHT erfolgreich"
echo "Fehler" > ramdisk/evsedintestlp1
fi
sleep 1
Expand All @@ -34,10 +34,10 @@ evsedintest() {
sleep 1
evsedinstat=$(sudo python runs/readmodbusethframer.py 192.168.193.18 1 1000 1)
if [[ $evsedinstat == "[9]" ]]; then
echo "EVSE LP1 Prüfung erfolgreich"
openwbDebugLog "MAIN" 0 "EVSE LP1 Prüfung erfolgreich"
echo "erfolgreich" > ramdisk/evsedintestlp1
else
echo "EVSE LP1 Prüfung NICHt erfolgreich"
openwbDebugLog "MAIN" 0 "EVSE LP1 Prüfung NICHT erfolgreich"
echo "Fehler" > ramdisk/evsedintestlp1
fi
sleep 1
Expand Down Expand Up @@ -66,10 +66,10 @@ evsedintest() {
sleep 1
evsedinstat=$(sudo python runs/readmodbus.py $evsesources1 $evseids1 1000 1)
if [[ $evsedinstat == "9" ]]; then
echo "EVSE LP2 Prüfung erfolgreich"
openwbDebugLog "MAIN" 0 "EVSE LP2 Prüfung erfolgreich"
echo "erfolgreich" > ramdisk/evsedintestlp2
else
echo "EVSE LP2 Prüfung NICHt erfolgreich"
openwbDebugLog "MAIN" 0 "EVSE LP2 Prüfung NICHT erfolgreich"
echo "Fehler" > ramdisk/evsedintestlp2
fi
sleep 1
Expand Down Expand Up @@ -97,10 +97,10 @@ evsedintest() {
sleep 1
evsedinstat=$(sudo python runs/readmodbus.py $evsesources2 $evseids2 1000 1)
if [[ $evsedinstat == "9" ]]; then
echo "EVSE LP3 Prüfung erfolgreich"
openwbDebugLog "MAIN" 0 "EVSE LP3 Prüfung erfolgreich"
echo "erfolgreich" > ramdisk/evsedintestlp3
else
echo "EVSE LP3 Prüfung NICHt erfolgreich"
openwbDebugLog "MAIN" 0 "EVSE LP3 Prüfung NICHT erfolgreich"
echo "Fehler" > ramdisk/evsedintestlp3
fi
sleep 1
Expand All @@ -127,19 +127,19 @@ evsedintest() {
fi
sleep 1
evselp12000=$(sudo python runs/readmodbus.py $modbusevsesource $modbusevseid 2000 1)
echo $evselp12000 > /var/www/html/openWB/ramdisk/progevsedinlp12000
echo $evselp12000 > /var/www/html/openWB/ramdisk/progevsedinlp12000
sleep 1
evselp12007=$(sudo python runs/readmodbus.py $modbusevsesource $modbusevseid 2007 1)
echo $evselp12007 > /var/www/html/openWB/ramdisk/progevsedinlp12007
echo $evselp12007 > /var/www/html/openWB/ramdisk/progevsedinlp12007
sleep 1
fi
if [[ $evsecon == "masterethframer" ]]; then
sleep 1
evselp12000=$(sudo python runs/readmodbusethframer.py 192.168.193.18 1 2000 1)
echo $evselp12000 > /var/www/html/openWB/ramdisk/progevsedinlp12000
echo $evselp12000 > /var/www/html/openWB/ramdisk/progevsedinlp12000
sleep 1
evselp12007=$(sudo python runs/readmodbusethframer.py 192.168.193.18 1 2007 1)
echo $evselp12007 > /var/www/html/openWB/ramdisk/progevsedinlp12007
echo $evselp12007 > /var/www/html/openWB/ramdisk/progevsedinlp12007
sleep 1
fi
fi
Expand Down Expand Up @@ -233,13 +233,9 @@ evsemodbuscheck() {
evsedinstat=$(sudo python runs/readmodbus.py $modbusevsesource $modbusevseid 1000 1)
sleep 1
if [[ $evsedinstat == "$llalt" ]]; then
if [[ $debug == "1" ]]; then
echo "LP1 Modbus $llalt korrekt"
fi
openwbDebugLog "MAIN" 1 "LP1 Modbus $llalt korrekt"
else
if [[ $debug == "1" ]]; then
echo "LP1 Modbus $llalt nicht korrekt"
fi
openwbDebugLog "MAIN" 1 "LP1 Modbus $llalt nicht korrekt"
sudo python runs/evsewritembusdev.py $modbusevsesource $modbusevseid 1000 $llalt
fi
fi
Expand All @@ -257,13 +253,9 @@ evsemodbuscheck() {
evsedinstat=$(sudo python runs/readmodbus.py $evsesources1 $evseids1 1000 1)
sleep 1
if [[ $evsedinstat == "$llalts1" ]]; then
if [[ $debug == "1" ]]; then
echo "LP2 Modbus $llalts1 korrekt"
fi
openwbDebugLog "MAIN" 1 "LP2 Modbus $llalts1 korrekt"
else
if [[ $debug == "1" ]]; then
echo "LP2 Modbus $llalts1 nichtkorrekt"
fi
openwbDebugLog "MAIN" 1 "LP2 Modbus $llalts1 nichtkorrekt"
sudo python runs/evsewritembusdev.py $evsesources1 $evseids1 1000 $llalts1
fi
fi
Expand All @@ -280,13 +272,9 @@ evsemodbuscheck() {
fi
evsedinstat=$(sudo python runs/readmodbus.py $evsesources2 $evseids2 1000 1)
if [[ $evsedinstat == "$llalts2" ]]; then
if [[ $debug == "1" ]]; then
echo "LP3 Modbus $llalts2 korrekt"
fi
openwbDebugLog "MAIN" 1 "LP3 Modbus $llalts2 korrekt"
else
if [[ $debug == "1" ]]; then
echo "LP3 Modbus $llalts2 nicht korrekt"
fi
openwbDebugLog "MAIN" 1 "LP3 Modbus $llalts2 nicht korrekt"
sudo python runs/evsewritembusdev.py $evsesources2 $evseids2 1000 $llalts2
fi
fi
Expand Down
53 changes: 52 additions & 1 deletion helperFunctions.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

openwbPublishModuleState() {
openwbModulePublishState() {
# $1: Modultyp (EVU, LP, EVSOC, PV, BAT)
# $2: Status (0=Ok, 1=Warning, 2=Error)
# $3: Meldung (String)
Expand Down Expand Up @@ -51,3 +51,54 @@ openwbPublishModuleState() {
;;
esac
}

export -f openwbModulePublishState

openwbDebugLog() {
# $1: Channel (MAIN=default, EVSOC, PV, MQTT, RFID, SMARTHOME, CHARGESTAT)
# $2: Level (0=Info, 1=Regelwerte , 2=Berechnungsgrundlage)
# $3: Meldung (String)
LOGFILE="/var/log/openWB.log"
timestamp=`date +"%Y-%m-%d %H:%M:%S"`

if [[ -z "$debug" ]]; then
# enable all levels as global $debug is not set up yet
DEBUGLEVEL=2
else
DEBUGLEVEL=$debug
fi
# echo "LVL: $2 DEBUG: $debug DEBUGLEVEL: $DEBUGLEVEL" >> $LOGFILE
if (( $2 <= $DEBUGLEVEL )); then
case $1 in
"EVSOC")
LOGFILE="/var/www/html/openWB/ramdisk/soc.log"
;;
"PV")
LOGFILE="/var/www/html/openWB/ramdisk/nurpv.log"
;;
"MQTT")
LOGFILE="/var/www/html/openWB/ramdisk/mqtt.log"
;;
"RFID")
LOGFILE="/var/www/html/openWB/ramdisk/rfid.log"
;;
"SMARTHOME")
LOGFILE="/var/www/html/openWB/ramdisk/smarthome.log"
;;
"CHARGESTAT")
LOGFILE="/var/www/html/openWB/ramdisk/ladestatus.log"
;;
*)
# MAIN
LOGFILE="/var/log/openWB.log"
;;
esac
if (( $DEBUGLEVEL > 0 )); then
echo "$timestamp: $3 (LV$2) at $(caller 0)" >> $LOGFILE
else
echo "$timestamp: $3 (LV$2)" >> $LOGFILE
fi
fi
}

export -f openwbDebugLog
Loading

0 comments on commit 9b4da8b

Please sign in to comment.