diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f2a25c..a4c6635 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 0.6.1 - 06/09/2020 +- Add support for send log to piGardenWeb + # 0.6.0 - 16/05/2020 - Add support for enable all cron fron api - Update rainsensorqty driver to version 0.2.5b diff --git a/conf/piGarden.conf.example b/conf/piGarden.conf.example index 06c8b32..f080e96 100644 --- a/conf/piGarden.conf.example +++ b/conf/piGarden.conf.example @@ -2,6 +2,14 @@ LOG_FILE="/home/pi/piGarden/log/piGarden.log" LOG_FILE_MAX_SIZE=1048576 # 1MB +# +# Enable send log to piGardenWeb +# + +#LOG_URL="http://url_of_your_pigardenweb/api/log" +#LOG_API_TOKEN="token_of_pigardenweb_user" +#LOG_CURL_PARAM="--data-urlencode -k" + # Log file for driver output LOG_OUTPUT_DRV_FILE="/tmp/piGarden.drv.log" diff --git a/conf/piGarden.conf.rainsensorqty.example b/conf/piGarden.conf.rainsensorqty.example index 8aab3f8..9705d86 100644 --- a/conf/piGarden.conf.rainsensorqty.example +++ b/conf/piGarden.conf.rainsensorqty.example @@ -2,6 +2,14 @@ LOG_FILE="/home/pi/piGarden/log/piGarden.log" LOG_FILE_MAX_SIZE=1048576 # 1MB +# +# Enable send log to piGardenWeb +# + +#LOG_URL="http://url_of_your_pigardenweb/api/log" +#LOG_API_TOKEN="token_of_pigardenweb_user" +#LOG_CURL_PARAM="--data-urlencode -k" + # Log file for driver output LOG_OUTPUT_DRV_FILE="/tmp/piGarden.drv.log" diff --git a/conf/piGarden.conf.remote.example b/conf/piGarden.conf.remote.example index ffb8a52..49911a5 100644 --- a/conf/piGarden.conf.remote.example +++ b/conf/piGarden.conf.remote.example @@ -2,6 +2,14 @@ LOG_FILE="/home/pi/piGarden/log/piGarden.log" LOG_FILE_MAX_SIZE=1048576 # 1MB +# +# Enable send log to piGardenWeb +# + +#LOG_URL="http://url_of_your_pigardenweb/api/log" +#LOG_API_TOKEN="token_of_pigardenweb_user" +#LOG_CURL_PARAM="--data-urlencode -k" + # Log file for driver output #LOG_OUTPUT_DRV_FILE="/tmp/piGarden.drv.log" diff --git a/conf/piGarden.conf.sonoff_tasmota_http.example b/conf/piGarden.conf.sonoff_tasmota_http.example index 107a70c..b5972e6 100644 --- a/conf/piGarden.conf.sonoff_tasmota_http.example +++ b/conf/piGarden.conf.sonoff_tasmota_http.example @@ -2,6 +2,14 @@ LOG_FILE="/home/pi/piGarden/log/piGarden.log" LOG_FILE_MAX_SIZE=1048576 # 1MB +# +# Enable send log to piGardenWeb +# + +#LOG_URL="http://url_of_your_pigardenweb/api/log" +#LOG_API_TOKEN="token_of_pigardenweb_user" +#LOG_CURL_PARAM="--data-urlencode -k" + # Log file for driver output #LOG_OUTPUT_DRV_FILE="/tmp/piGarden.drv.log" diff --git a/conf/piGarden.conf.spb16ch.example b/conf/piGarden.conf.spb16ch.example index 7eec298..bf5e3f2 100644 --- a/conf/piGarden.conf.spb16ch.example +++ b/conf/piGarden.conf.spb16ch.example @@ -2,6 +2,14 @@ LOG_FILE="/home/pi/piGarden/log/piGarden.log" LOG_FILE_MAX_SIZE=1048576 # 1MB +# +# Enable send log to piGardenWeb +# + +#LOG_URL="http://url_of_your_pigardenweb/api/log" +#LOG_API_TOKEN="token_of_pigardenweb_user" +#LOG_CURL_PARAM="--data-urlencode -k" + # Log file for driver output #LOG_OUTPUT_DRV_FILE="/tmp/piGarden.drv.log" diff --git a/drv/remote/rele.include.sh b/drv/remote/rele.include.sh index 525bbec..e91c604 100644 --- a/drv/remote/rele.include.sh +++ b/drv/remote/rele.include.sh @@ -35,7 +35,7 @@ function drv_remote_rele_open { error="${error%\"}" error="${error#\"}" echo "error=$error" - log_write "Remote rele open error: $error" + log_write "drv_remote" "error" "Remote rele open error: $error" message_write "warning" "Remote rele open error: $error" return 1 fi @@ -68,7 +68,7 @@ function drv_remote_rele_close { error="${error%\"}" error="${error#\"}" echo "error=$error" - log_write "Remote rele close error: $error" + log_write "drv_remoter" "error" "Remote rele close error: $error" message_write "warning" "Remote rele close error: $error" return 1 fi diff --git a/drv/sonoff_tasmota_http/rele.include.sh b/drv/sonoff_tasmota_http/rele.include.sh index 55a6847..a1e1463 100644 --- a/drv/sonoff_tasmota_http/rele.include.sh +++ b/drv/sonoff_tasmota_http/rele.include.sh @@ -35,7 +35,7 @@ function drv_sonoff_tasmota_http_rele_open { error="${error%\"}" error="${error#\"}" echo "error=$error" - log_write "Remote rele open error: $error" + log_write "drv_sonoff_tasmota_http" "error" "Remote rele open error: $error" message_write "warning" "Remote rele open error: $error" return 1 fi @@ -69,7 +69,7 @@ function drv_sonoff_tasmota_http_rele_close { error="${error%\"}" error="${error#\"}" echo "error=$error" - log_write "Remote rele close error: $error" + log_write "drv_sonoff_tasmota_http" "error" "Remote rele close error: $error" message_write "warning" "Remote rele close error: $error" return 1 fi diff --git a/drv/spb16ch/common.include.sh b/drv/spb16ch/common.include.sh index 9013923..72f3e8f 100644 --- a/drv/spb16ch/common.include.sh +++ b/drv/spb16ch/common.include.sh @@ -74,7 +74,7 @@ function drv_spb16ch_boards_id_load { SPB16CH_USED_ID+=("$board_id") done else - log_write "spb16ch: file $SPB16CH_BOARD_ID_STORE_FILE not found: remember to run 'piGarden init' to generate the file" + log_write "drv_spb16ch" "error" "spb16ch: file $SPB16CH_BOARD_ID_STORE_FILE not found: remember to run 'piGarden init' to generate the file" fi } diff --git a/drv/spb16ch/rele.include.sh b/drv/spb16ch/rele.include.sh index 855151d..193dc7b 100644 --- a/drv/spb16ch/rele.include.sh +++ b/drv/spb16ch/rele.include.sh @@ -19,7 +19,7 @@ function drv_spb16ch_rele_open { local rele_data=${SPB16CH_RELE_MAP[$rele_id]} if [[ -z $rele_data ]]; then local message="Error - Rele map not defined - rele_id=$rele_id - ($1)" - log_write "$message" + log_write "drv_spb16ch" "error" "$message" message_write "warning" "$message" fi local address_num=${rele_data:0:2} @@ -52,7 +52,7 @@ function drv_spb16ch_rele_close { local rele_data=${SPB16CH_RELE_MAP[$rele_id]} if [[ -z $rele_data ]]; then local message="Error - Rele map not defined - rele_id=$rele_id - ($1)" - log_write "$message" + log_write "drv_spb16ch" "error" "$message" message_write "warning" "$message" fi local address_num=${rele_data:0:2} diff --git a/include/cron.include.sh b/include/cron.include.sh index 72a6445..e61b729 100644 --- a/include/cron.include.sh +++ b/include/cron.include.sh @@ -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 diff --git a/include/drv.include.sh b/include/drv.include.sh index b75d862..c81ecb7 100644 --- a/include/drv.include.sh +++ b/include/drv.include.sh @@ -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" diff --git a/include/rain.include.sh b/include/rain.include.sh index 7c1263d..1e151d3 100644 --- a/include/rain.include.sh +++ b/include/rain.include.sh @@ -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 diff --git a/include/socket.include.sh b/include/socket.include.sh index ba72156..040b4e7 100644 --- a/include/socket.include.sh +++ b/include/socket.include.sh @@ -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 diff --git a/piGarden.sh b/piGarden.sh index 55e0fc5..b54059f 100755 --- a/piGarden.sh +++ b/piGarden.sh @@ -10,7 +10,7 @@ # function initialize { - log_write "Run initialize" + log_write "general" "info" "Run initialize" unlock @@ -50,13 +50,13 @@ function initialize { # Inizializza il sensore di rilevamento pioggia if [ -n "$RAIN_GPIO" ]; then drv_rain_sensor_init "$RAIN_GPIO" - log_write "Rain sensor initialized" + log_write "rain" "info" "Rain sensor initialized" else - log_write "Rain sensor not present" + log_write "rain" "info" "Rain sensor not present" fi trigger_event "init_after" "" - log_write "End initialize" + log_write "general" "info" "End initialize" } @@ -98,7 +98,7 @@ function ev_open { message_write "warning" "Solenoid not open for rain" trigger_event "ev_not_open_for_rain_online" "$1" trigger_event "ev_not_open_for_rain" "$1" - log_write "Solenoid '$1' not open for rain (online check)" + log_write "irrigate" "warning" "Solenoid '$1' not open for rain (online check)" return fi fi @@ -113,7 +113,7 @@ function ev_open { message_write "warning" "Solenoid not open for rain" trigger_event "ev_not_open_for_rain_sensor" "$1" trigger_event "ev_not_open_for_rain" "$1" - log_write "Solenoid '$1' not open for rain (sensor check)" + log_write "irrigate" "warning" "Solenoid '$1' not open for rain (sensor check)" return fi fi @@ -126,7 +126,7 @@ function ev_open { trigger_event "ev_open_before" "$1" "$2" if [ $? -ne 0 ]; then - log_write "Solenoid '$1' not open due to external event" + log_write "irrigate" "warning" "Solenoid '$1' not open due to external event" message_write 'warning' "Solenoid not open due to external event" mqtt_status return @@ -150,7 +150,7 @@ function ev_open { ev_set_state $EVNUM $state - log_write "Solenoid '$1' open" + log_write "irrigate" "info" "Solenoid '$1' open" message_write "success" "Solenoid open" trigger_event "ev_open_after" "$1" "$2" @@ -259,7 +259,7 @@ function ev_close { ev_set_state $EVNUM 0 - log_write "Solenoid '$1' close" + log_write "irrigate" "info" "Solenoid '$1' close" message_write "success" "Solenoid close" trigger_event "ev_close_after" "$1" @@ -285,7 +285,9 @@ function supply_negative { # # Scrive un messaggio nel file di log -# $1 log da scrivere +# $1 type +# $2 level +# $3 log da scrivere # function log_write { if [ -e "$LOG_FILE" ]; then @@ -304,7 +306,25 @@ function log_write { fi fi - echo -e "`date`\t\t$1" >> $LOG_FILE + echo -e "`date`\t\t$1\t$2\t$3" >> $LOG_FILE + + log_send "$1" "$2" "`date '+%Y-%m-%d %H:%M:%S'`" "$3" + +} + +# +# Invia un log verso piGardenWeb +# $1 type +# $2 level +# $3 date time +# $4 messaggio +# +function log_send { + + if [[ ! -z "$LOG_URL" ]]; then + $CURL $LOG_CURL_PARAM "$LOG_URL" -d "api_token=$LOG_API_TOKEN&type=$1&level=$2&datetime_log=$3&message=$4" &> /dev/null & + fi + } # @@ -373,7 +393,7 @@ function gpio_alias2number { fi done - log_write "ERROR solenoid alias not found: $1" + log_write "general" "error" "ERROR solenoid alias not found: $1" message_write "warning" "Solenoid alias not found" mqtt_status exit 1 @@ -393,7 +413,7 @@ function ev_alias2number { fi done - log_write "ERROR solenoid alias not found: $1" + log_write "general" "error" "ERROR solenoid alias not found: $1" message_write "warning" "Solenoid alias not found" mqtt_status exit 1 @@ -480,7 +500,7 @@ function close_all { #echo "$al = $state" if [[ "$state" -gt "0" || "$1" = "force" ]]; then ev_close $al - log_write "close_all - Close solenoid '$al' for rain" + log_write "irrigate" "info" "close_all - Close solenoid '$al' for rain" fi done @@ -779,12 +799,12 @@ function lock { local foo=bar else if [ "$current_time" -gt "$max_time" ]; then - log_write "Maximum locked time reached" + log_write "general" "error" "Maximum locked time reached" sleep $max_time unlock exit 1 fi - log_write "Sleep 1 second for locked state" + log_write "general" "info" "Sleep 1 second for locked state" sleep 1 lock $current_time return @@ -833,7 +853,7 @@ function send_identifier { fi echo "$ID" > "$FILE_ID" - log_write "Send installation identifier to collect usage" + log_write "general" "info" "Send installation identifier to collect usage" $CURL https://www.lejubila.net/statistic/collect_usage/piGarden/$ID/$VERSION/$SUB_VERSION/$RELEASE_VERSION > /dev/null 2>&1 @@ -875,7 +895,7 @@ function cmd_pigardensched { if [ $PIGARDENSCHED == 0 ]; then echo "piGardenSched not configured in piGarden" >&2 - log_write "piGardenSched not configured in piGarden" + log_write "piGardenSched" "error" "piGardenSched not configured in piGarden" return fi @@ -1130,7 +1150,7 @@ case "$1" in nohup $0 start_socket_server_daemon > /dev/null 2>&1 & echo "Daemon is started widh pid $!" - log_write "start socket server with pid $!" + log_write "socket_server" "info" "start socket server with pid $!" ;; start_socket_server_daemon)