Add support for send log to piGardenWeb

This commit is contained in:
lejubila
2020-09-06 08:24:26 +02:00
parent bdab0fb6fe
commit 9183bbcef5
15 changed files with 140 additions and 77 deletions

View File

@@ -10,7 +10,7 @@ function cron_del {
if [ -z "$CRON_TYPE" ]; then
echo "Cron type is empty" >&2
log_write "Cron type is empty"
log_write "cron" "error" "Cron type is empty"
return 1
fi
@@ -25,17 +25,17 @@ function cron_del {
fi
if ! [[ $START =~ $re ]] ; then
echo "Cron start don't find" >&2
log_write "Cron start don't find"
log_write "cron" "error" "Cron start don't find"
return 1
fi
if ! [[ $END =~ $re ]] ; then
echo "Cron end cron don't find" >&2
log_write "Cron end cron don't find"
log_write "cron" "error" "Cron end cron don't find"
return 1
fi
if [ "$START" -gt "$END" ]; then
echo "Wrong position for start and end in cron" >&2
log_write "Wrong position for start and end in cron"
log_write "cron" "error" "Wrong position for start and end in cron"
return 1
fi
@@ -74,7 +74,7 @@ function cron_add {
if [ -z "$CRON_TYPE" ]; then
echo "Cron type is empty" >&2
log_write "Cron type is empty"
log_write "cron" "error" "Cron type is empty"
return 1
fi
@@ -91,12 +91,12 @@ function cron_add {
else
if ! [[ $START =~ $re ]] ; then
echo "Cron start don't find" >&2
log_write "Cron start don't find"
log_write "cron" "error" "Cron start don't find"
return 1
fi
if ! [[ $END =~ $re ]] ; then
echo "Cron end cron don't find" >&2
log_write "Cron end cron don't find"
log_write "cron" "error" "Cron end cron don't find"
return 1
fi
START=$(($START + 1))
@@ -104,7 +104,7 @@ function cron_add {
if [ "$START" -gt "$END" ]; then
echo "Wrong position for start and end in cron" >&2
log_write "Wrong position for start and end in cron"
log_write "cron" "error" "Wrong position for start and end in cron"
return 1
fi
@@ -183,7 +183,7 @@ function cron_add {
*)
echo "Wrong cron type: $CRON_TYPE"
log_write "Wrong cron type: $CRON_TYPE"
log_write "cron" "error" "Wrong cron type: $CRON_TYPE"
;;
esac
@@ -225,7 +225,7 @@ function cron_get {
if [ -z "$CRON_TYPE" ]; then
echo "Cron type is empty" >&2
log_write "Cron type is empty"
log_write "cron" "error" "Cron type is empty"
return 1
fi
@@ -241,12 +241,12 @@ function cron_get {
else
if ! [[ $START =~ $re ]] ; then
echo "Cron start don't find" >&2
log_write "Cron start don't find"
log_write "cron" "error" "Cron start don't find"
return 1
fi
if ! [[ $END =~ $re ]] ; then
echo "Cron end cron don't find" >&2
log_write "Cron end cron don't find"
log_write "cron" "error" "Cron end cron don't find"
return 1
fi
START=$(($START + 1))
@@ -254,7 +254,7 @@ function cron_get {
if [ "$START" -gt "$END" ]; then
echo "Wrong position for start and end in cron" >&2
log_write "Wrong position for start and end in cron"
log_write "cron" "error" "Wrong position for start and end in cron"
return 1
fi
@@ -370,7 +370,7 @@ function add_cron_open {
local exists=`alias_exists $1`
if [ "check $exists" = "check FALSE" ]; then
log_write "Alias $1 not found"
log_write "cron" "error" "Alias $1 not found"
echo "Alias $1 not found"
return 1
fi
@@ -387,7 +387,7 @@ function del_cron_open {
local exists=`alias_exists $1`
if [ "check $exists" = "check FALSE" ]; then
log_write "Alias $1 not found"
log_write "cron" "error" "Alias $1 not found"
echo "Alias $1 not found"
return 1
fi
@@ -404,7 +404,7 @@ function get_cron_open {
local exists=`alias_exists $1`
if [ "check $exists" = "check FALSE" ]; then
log_write "Alias $1 not found"
log_write "cron" "error" "Alias $1 not found"
echo "Alias $1 not found"
return 1
fi
@@ -421,7 +421,7 @@ function del_cron_open_in {
local exists=`alias_exists $1`
if [ "check $exists" = "check FALSE" ]; then
log_write "Alias $1 not found"
log_write "cron" "error" "Alias $1 not found"
echo "Alias $1 not found"
return 1
fi
@@ -439,7 +439,7 @@ function get_cron_close {
local exists=`alias_exists $1`
if [ "check $exists" = "check FALSE" ]; then
log_write "Alias $1 not found"
log_write "cron" "error" "Alias $1 not found"
echo "Alias $1 not found"
return 1
fi
@@ -462,7 +462,7 @@ function add_cron_close {
local exists=`alias_exists $1`
if [ "check $exists" = "check FALSE" ]; then
log_write "Alias $1 not found"
log_write "cron" "error" "Alias $1 not found"
echo "Alias $1 not found"
return 1
fi
@@ -479,7 +479,7 @@ function del_cron_close {
local exists=`alias_exists $1`
if [ "check $exists" = "check FALSE" ]; then
log_write "Alias $1 not found"
log_write "cron" "error" "Alias $1 not found"
echo "Alias $1 not found"
return 1
fi

View File

@@ -94,7 +94,7 @@ function drv_rele_init {
$GPIO -g mode $idx out # setta il gpio nella modalita di scrittura
# Il driver definito non è stato trovato
elif [ "$fnc" == "drvnotfound" ]; then
log_write "Driver not found: $idx"
log_write "drv" "error" "Driver not found: $idx"
message_write "warning" "Driver not found: $idx"
else
echo "$(date) $fnc arg:$idx" >> "$LOG_OUTPUT_DRV_FILE"
@@ -116,7 +116,7 @@ function drv_rele_close {
$GPIO -g write $idx $RELE_GPIO_CLOSE
# Il driver definito non è stato trovato
elif [ "$fnc" == "drvnotfound" ]; then
log_write "Driver not found: $idx"
log_write "drv" "error" "Driver not found: $idx"
message_write "warning" "Driver not found: $idx"
return 1
else
@@ -142,7 +142,7 @@ function drv_rele_open {
$GPIO -g write $idx $RELE_GPIO_OPEN
# Il driver definito non è stato trovato
elif [ "$fnc" == "drvnotfound" ]; then
log_write "Driver not found: $idx"
log_write "drv" "error" "Driver not found: $idx"
message_write "warning" "Driver not found: $idx"
return 1
else
@@ -172,7 +172,7 @@ function drv_supply_bistable_init {
$GPIO -g mode $idx1 out
# Il driver definito non è stato trovato
elif [ "$fnc1" == "drvnotfound" ]; then
log_write "Driver not found: $idx1"
log_write "drv" "error" "Driver not found: $idx1"
message_write "warning" "Driver not found: $idx1"
return
else
@@ -186,7 +186,7 @@ function drv_supply_bistable_init {
$GPIO -g mode $idx2 out
# Il driver definito non è stato trovato
elif [ "$fnc2" == "drvnotfound" ]; then
log_write "Driver not found: $idx2"
log_write "drv" "error" "Driver not found: $idx2"
message_write "warning" "Driver not found: $idx2"
else
echo "$(date) $fnc2 arg:$idx2" >> "$LOG_OUTPUT_DRV_FILE"
@@ -212,7 +212,7 @@ function drv_supply_positive {
$GPIO -g write $idx1 $SUPPLY_GPIO_POS
# Il driver definito non è stato trovato
elif [ "$fnc1" == "drvnotfound" ]; then
log_write "Driver not found: $idx1"
log_write "drv" "error" "Driver not found: $idx1"
message_write "warning" "Driver not found: $idx1"
return
else
@@ -225,7 +225,7 @@ function drv_supply_positive {
$GPIO -g write $idx2 $SUPPLY_GPIO_POS
# Il driver definito non è stato trovato
elif [ "$fnc2" == "drvnotfound" ]; then
log_write "Driver not found: $idx2"
log_write "drv" "error" "Driver not found: $idx2"
message_write "warning" "Driver not found: $idx2"
else
echo "$(date) $fnc2 arg:$idx2" >> "$LOG_OUTPUT_DRV_FILE"
@@ -251,7 +251,7 @@ function drv_supply_negative {
$GPIO -g write $idx1 $SUPPLY_GPIO_NEG
# Il driver definito non è stato trovato
elif [ "$fnc1" == "drvnotfound" ]; then
log_write "Driver not found: $idx1"
log_write "drv" "error" "Driver not found: $idx1"
message_write "warning" "Driver not found: $idx1"
return
else
@@ -264,7 +264,7 @@ function drv_supply_negative {
$GPIO -g write $idx2 $SUPPLY_GPIO_NEG
# Il driver definito non è stato trovato
elif [ "$fnc2" == "drvnotfound" ]; then
log_write "Driver not found: $idx2"
log_write "drv" "error" "Driver not found: $idx2"
message_write "warning" "Driver not found: $idx2"
else
echo "$(date) $fnc2 arg:$idx2" >> "$LOG_OUTPUT_DRV_FILE"
@@ -288,7 +288,7 @@ function drv_rain_sensor_init {
$GPIO -g mode $idx in
# Il driver definito non è stato trovato
elif [ "$fnc" == "drvnotfound" ]; then
log_write "Driver not found: $idx"
log_write "drv" "error" "Driver not found: $idx"
message_write "warning" "Driver not found: $idx"
else
echo "$(date) $fnc arg:$idx" >> "$LOG_OUTPUT_DRV_FILE"
@@ -312,7 +312,7 @@ function drv_rain_sensor_get {
vret=`$GPIO -g read $idx`
# Il driver definito non è stato trovato
elif [ "$fnc" == "drvnotfound" ]; then
log_write "Driver not found: $idx"
log_write "drv" "error" "Driver not found: $idx"
message_write "warning" "Driver not found: $idx"
else
echo "$(date) $fnc arg:$idx" >> "$LOG_OUTPUT_DRV_FILE"
@@ -335,11 +335,11 @@ function drv_rain_online_get {
# Nessun driver definito, esegue la lettura del sensore tramite gpio del raspberry
if [ -z "$fnc" ]; then
log_write "Driver not found: $idx"
log_write "drv" "error" "Driver not found: $idx"
message_write "warning" "Driver not found: $idx"
# Il driver definito non è stato trovato
elif [ "$fnc" == "drvnotfound" ]; then
log_write "Driver not found: $idx"
log_write "drv" "error" "Driver not found: $idx"
message_write "warning" "Driver not found: $idx"
else
echo "$(date) $fnc arg:$idx" >> "$LOG_OUTPUT_DRV_FILE"

View File

@@ -4,7 +4,7 @@
function check_rain_online {
if [ "$WEATHER_SERVICE" == "none" ]; then
log_write "check_rain_online - online service is disable"
log_write "rain" "warning" "check_rain_online - online service is disabled"
return
fi
@@ -17,7 +17,7 @@ function check_rain_online {
if [[ $local_epoch =~ ^-?[0-9]+$ ]]; then
if [ $local_epoch -eq 0 ]; then
log_write "check_rain_online - failed read online data"
log_write "rain" "error" "check_rain_online - failed read online data"
else
if [ $local_epoch -gt 0 ]; then
current_state_rain_online='rain'
@@ -27,14 +27,14 @@ function check_rain_online {
fi
weather=$(cat "$STATUS_DIR/last_weather_online" | $JQ -M ".weather")
log_write "check_rain_online - weather=$weather, local_epoch=$local_epoch"
log_write "rain" "info" "check_rain_online - weather=$weather, local_epoch=$local_epoch"
if [ "$current_state_rain_online" != "$last_state_rain_online" ]; then
echo "$current_state_rain_online" > "$STATUS_DIR/last_state_rain_online"
trigger_event "check_rain_online_change" "$current_state_rain_online" "$weather"
fi
fi
else
log_write "check_rain_online - failed read online data"
log_write "rain" "error" "check_rain_online - failed read online data"
fi
trigger_event "check_rain_online_after" "$current_state_rain_online" "$weather"
@@ -57,11 +57,11 @@ function check_rain_sensor {
current_state_rain_sensor='rain'
local local_epoch=`date +%s`
echo $local_epoch > "$STATUS_DIR/last_rain_sensor"
log_write "check_rain_sensor - now it's raining ($local_epoch)"
log_write "rain" "info" "check_rain_sensor - now it's raining ($local_epoch)"
#return $local_epoch
else
current_state_rain_sensor='norain'
log_write "check_rain_sensor - now is not raining"
log_write "rain" "info" "check_rain_sensor - now is not raining"
fi
if [ "$current_state_rain_sensor" != "$last_state_rain_sensor" ]; then
echo "$current_state_rain_sensor" > "$STATUS_DIR/last_state_rain_sensor"
@@ -69,7 +69,7 @@ function check_rain_sensor {
fi
trigger_event "check_rain_sensor_after" "$current_state_rain_sensor"
else
log_write "Rain sensor not present"
log_write "rain" "warning" "Rain sensor not present"
fi
}
@@ -113,7 +113,7 @@ function close_all_for_rain {
#echo "$al = $state"
if [ "$state" = "1" ] && [ "$evnorain" != "1" ]; then
ev_close $al
log_write "close_all_for_rain - Close solenoid '$al' for rain"
log_write "irrigate" "warning" "close_all_for_rain - Close solenoid '$al' for rain"
fi
done
fi

View File

@@ -19,7 +19,7 @@ function stop_socket_server {
exit 1
fi
log_write "stop socket server"
log_write "socket_server" "info" "stop socket server"
kill -9 $(list_descendants `cat "$TCPSERVER_PID_FILE"`) 2> /dev/null
kill -9 `cat "$TCPSERVER_PID_FILE"` 2> /dev/null
@@ -44,7 +44,7 @@ function socket_server_command {
user=$(echo "$user" | $TR -d '[\r\n]')
password=$(echo "$password" | $TR -d '[\r\n]')
if [ "$user" != "$TCPSERVER_USER" ] || [ "$password" != "$TCPSERVER_PWD" ]; then
log_write "socket connection from: $TCPREMOTEIP - Bad socket server credentials - user:$user"
log_write "socket_server" "warning" "socket connection from: $TCPREMOTEIP - Bad socket server credentials - user:$user"
json_error 0 "Bad socket server credentials"
return
fi
@@ -61,7 +61,7 @@ function socket_server_command {
arg7=$(echo "$line " | $CUT -d ' ' -f7)
arg8=$(echo "$line " | $CUT -d ' ' -f8)
log_write "socket connection from: $TCPREMOTEIP - command: $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8"
log_write "socket_server" "info" "socket connection from: $TCPREMOTEIP - command: $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8"
#reset_messages &> /dev/null
@@ -127,7 +127,7 @@ function socket_server_command {
if [[ ! -z $vret ]]; then
json_error 0 "Cron set failed"
log_write "Cron set failed: $vret"
log_write "socket_server" "error" "Cron set failed: $vret"
else
message_write "success" "Cron set successfull"
json_status
@@ -142,7 +142,7 @@ function socket_server_command {
if [[ ! -z $vret ]]; then
json_error 0 "Cron set failed"
log_write "Cron del failed: $vret"
log_write "socket_server" "error" "Cron del failed: $vret"
else
message_write "success" "Cron set successfull"
json_status
@@ -157,7 +157,7 @@ function socket_server_command {
if [[ ! -z $vret ]]; then
json_error 0 "Cron del failed"
log_write "Cron del failed: $vret"
log_write "socket_server" "error" "Cron del failed: $vret"
else
message_write "success" "Scheduled start successfully deleted"
json_status "get_cron_open_in:$arg2"
@@ -173,7 +173,7 @@ function socket_server_command {
if [[ ! -z $vret ]]; then
json_error 0 "Cron set failed"
log_write "Cron set failed: $vret"
log_write "socket_server" "error" "Cron set failed: $vret"
else
message_write "success" "Cron set successfull"
json_status
@@ -188,7 +188,7 @@ function socket_server_command {
if [[ ! -z $vret ]]; then
json_error 0 "Cron set failed"
log_write "Cron set failed: $vret"
log_write "socket_server" "error" "Cron set failed: $vret"
else
message_write "success" "Cron set successfull"
json_status
@@ -203,7 +203,7 @@ function socket_server_command {
if [[ ! -z $vret ]]; then
json_error 0 "Cron set failed"
log_write "Cron set failed: $vret"
log_write "socket_server" "error" "Cron set failed: $vret"
else
message_write "success" "Cron set successfull"
json_status
@@ -218,7 +218,7 @@ function socket_server_command {
if [[ ! -z $vret ]]; then
json_error 0 "piGardenSched command failed"
log_write "piGardenSched command failed: $vret"
log_write "socket_server" "error" "piGardenSched command failed: $vret"
else
message_write "success" "Schedule set successfull"
json_status