From fa75480e69b25f015861e5571c236c576000109f Mon Sep 17 00:00:00 2001 From: ShiranAvidov Date: Wed, 17 May 2023 11:34:27 +0300 Subject: [PATCH 1/5] add check --- scripts/linux/agent.bash | 2 ++ scripts/linux/functions.bash | 21 +++++++++++++++++ scripts/mac/agent.bash | 2 ++ scripts/mac/functions.bash | 44 ++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+) diff --git a/scripts/linux/agent.bash b/scripts/linux/agent.bash index 7c527c15d..0fc8986e6 100755 --- a/scripts/linux/agent.bash +++ b/scripts/linux/agent.bash @@ -253,6 +253,8 @@ echo -e '##########################' # Get Linux info execute_task 'get_linux_info' 'Getting Linux info' +# Check if /tmp directory is out of space +execute_task 'is_tmp_directory_out_of_space' # Check if bash version is 4.0 or above execute_task 'is_bash_version_4_or_above' 'Checking if bash version is 4.0 or above' # Get arguments diff --git a/scripts/linux/functions.bash b/scripts/linux/functions.bash index 71baea177..5d584d981 100755 --- a/scripts/linux/functions.bash +++ b/scripts/linux/functions.bash @@ -79,6 +79,27 @@ function is_bash_version_4_or_above { fi } +# Checks if /tmp directory is out of space +# Input: +# --- +# Output: +# --- +function is_tmp_directory_out_of_space { + local func_name="${FUNCNAME[0]}" + + local message="Checking if '/tmp' directory is out of space ..." + send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_PRE_INIT" "$LOG_SCRIPT_AGENT" "$func_name" "$AGENT_ID" + write_log "$LOG_LEVEL_DEBUG" "$message" + + local available_space=$(df -k /tmp | tail -n 1 | tr -s " " | cut -d' ' -f4) + if [[ $available_space -lt 1 ]]; then + message="agent.bash ($EXIT_CODE): '/tmp' must have at least 1GB free space" + send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_PRE_INIT" "$LOG_SCRIPT_AGENT" "$func_name" "$AGENT_ID" + write_task_post_run "write_error \"$message\"" + + return $EXIT_CODE + fi +} # Prints usage # Input: diff --git a/scripts/mac/agent.bash b/scripts/mac/agent.bash index d3451e96b..d04090839 100755 --- a/scripts/mac/agent.bash +++ b/scripts/mac/agent.bash @@ -253,6 +253,8 @@ echo -e '##########################' # Get Mac info execute_task 'get_mac_info' 'Getting Mac info' +# Check if /tmp directory is out of space +execute_task 'is_tmp_directory_out_of_space' # Check if bash version is 4.0 or above execute_task 'is_bash_version_4_or_above' 'Checking if bash version is 4.0 or above' # Get arguments diff --git a/scripts/mac/functions.bash b/scripts/mac/functions.bash index df1341089..6891a8ef2 100755 --- a/scripts/mac/functions.bash +++ b/scripts/mac/functions.bash @@ -79,6 +79,50 @@ function is_bash_version_4_or_above { fi } +# Checks if /tmp directory is out of space +# Input: +# --- +# Output: +# --- +function is_tmp_directory_out_of_space { + local func_name="${FUNCNAME[0]}" + + local message="Checking if '/tmp' directory is out of space ..." + send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_PRE_INIT" "$LOG_SCRIPT_AGENT" "$func_name" "$AGENT_ID" + write_log "$LOG_LEVEL_DEBUG" "$message" + + local use_percentage=$(df /tmp | tail -n 1 | tr -s " " | cut -d' ' -f5 | grep -o [0-9]*) + if [[ $use_percentage -gt 90 ]]; then + message="agent.bash ($EXIT_CODE): '/tmp' is almost out of space - over 90% space in use" + send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_PRE_INIT" "$LOG_SCRIPT_AGENT" "$func_name" "$AGENT_ID" + write_task_post_run "write_error \"$message\"" + + return $EXIT_CODE + fi +} + +# Checks if /tmp directory is out of space +# Input: +# --- +# Output: +# --- +function is_tmp_directory_out_of_space { + local func_name="${FUNCNAME[0]}" + + local message="Checking if '/tmp' directory is out of space ..." + send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_PRE_INIT" "$LOG_SCRIPT_AGENT" "$func_name" "$AGENT_ID" + write_log "$LOG_LEVEL_DEBUG" "$message" + + local available_space=$(df -k /tmp | tail -n 1 | tr -s " " | cut -d' ' -f4) + available_space=$((available_space/1024/1024)) + if [[ $available_space -ls 1 ]]; then + message="agent.bash ($EXIT_CODE): '/tmp' must have at least 1GB free space" + send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_PRE_INIT" "$LOG_SCRIPT_AGENT" "$func_name" "$AGENT_ID" + write_task_post_run "write_error \"$message\"" + + return $EXIT_CODE + fi +} # Prints usage # Input: From ededf507a046b9d157d9d2fc560584bf9004a7fd Mon Sep 17 00:00:00 2001 From: ShiranAvidov Date: Mon, 22 May 2023 16:52:36 +0300 Subject: [PATCH 2/5] fix error regex --- resources-linux/k8s/datasource_installer_utils.bash | 2 +- .../k8s/subtype_postrequisites_utils.bash | 12 ++++++------ resources-linux/k8s/subtype_prerequisites_utils.bash | 12 ++++++------ resources-mac/k8s/datasource_installer_utils.bash | 2 +- resources-mac/k8s/subtype_postrequisites_utils.bash | 12 ++++++------ resources-mac/k8s/subtype_prerequisites_utils.bash | 12 ++++++------ 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/resources-linux/k8s/datasource_installer_utils.bash b/resources-linux/k8s/datasource_installer_utils.bash index 5e0b98501..5eb9fe4b5 100755 --- a/resources-linux/k8s/datasource_installer_utils.bash +++ b/resources-linux/k8s/datasource_installer_utils.bash @@ -87,7 +87,7 @@ function build_tolerations_helm_sets { nodes=$(kubectl get nodes -o json 2>"$TASK_ERROR_FILE") if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then message="installer.bash ($EXIT_CODE): error getting nodes: $err" send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_INSTALLATION" "$LOG_SCRIPT_INSTALLER" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" write_task_post_run "write_error \"$message\"" diff --git a/resources-linux/k8s/subtype_postrequisites_utils.bash b/resources-linux/k8s/subtype_postrequisites_utils.bash index bcd71bb9c..7c9e3d197 100755 --- a/resources-linux/k8s/subtype_postrequisites_utils.bash +++ b/resources-linux/k8s/subtype_postrequisites_utils.bash @@ -22,7 +22,7 @@ function are_all_pods_running_or_completed { pod_statuses=$(kubectl get pods -n monitoring --no-headers -o custom-columns=':.status.phase' 2>"$TASK_ERROR_FILE") if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then message="postrequisites.bash ($EXIT_CODE): error getting pods status: $err" send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_POSTREQUISITES" "$LOG_SCRIPT_POSTREQUISITES" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" write_task_post_run "write_error \"$message\"" @@ -69,7 +69,7 @@ function is_any_pod_pending { pods=$(kubectl get pods -n monitoring --no-headers -o custom-columns=':.metadata.name,:.status.phase' 2>"$TASK_ERROR_FILE" | tr -s ' ') if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then write_task_post_run 'IS_POSTREQUISITES_FAILED=true' message="postrequisites.bash ($EXIT_CODE): error getting pods names and status: $err" @@ -92,7 +92,7 @@ function is_any_pod_pending { event_reason=$(kubectl get event -n monitoring --field-selector involvedObject.name="$pod_name" --no-headers -o custom-columns=':.reason' 2>"$TASK_ERROR_FILE" | head -n 1) if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then write_task_post_run 'IS_POSTREQUISITES_FAILED=true' message="postrequisites.bash ($EXIT_CODE): error getting pending pod '$pod_name' reason: $err" @@ -107,7 +107,7 @@ function is_any_pod_pending { event_message=$(kubectl get event -n monitoring --field-selector involvedObject.name="$pod_name" --no-headers -o custom-columns=':.message' 2>"$TASK_ERROR_FILE" | head -n 1) if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then write_task_post_run 'IS_POSTREQUISITES_FAILED=true' message="postrequisites.bash ($EXIT_CODE): error getting pending pod '$pod_name' message: $(get_task_error_message)" @@ -155,7 +155,7 @@ function is_any_pod_failed { pods=$(kubectl get pods -n monitoring --no-headers -o custom-columns=':.metadata.name,:.status.phase' 2>"$TASK_ERROR_FILE" | tr -s ' ') if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then write_task_post_run "IS_POSTREQUISITES_FAILED=true" message="postrequisites.bash ($EXIT_CODE): error getting pod names and statuses: $err" @@ -178,7 +178,7 @@ function is_any_pod_failed { pod_logs=$(kubectl logs "$pod_name" -n monitoring 2>"$TASK_ERROR_FILE") if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then write_task_post_run "IS_POSTREQUISITES_FAILED=true" message="postrequisites.bash ($EXIT_CODE): error getting pod '$pod_name' logs: $err" diff --git a/resources-linux/k8s/subtype_prerequisites_utils.bash b/resources-linux/k8s/subtype_prerequisites_utils.bash index 575322ecc..c55c03e61 100755 --- a/resources-linux/k8s/subtype_prerequisites_utils.bash +++ b/resources-linux/k8s/subtype_prerequisites_utils.bash @@ -42,7 +42,7 @@ function is_kubectl_connected_to_kubernetes_cluster { cluster_info=$(kubectl cluster-info 2>"$TASK_ERROR_FILE") if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then message="prerequisites.bash ($EXIT_CODE): 'kubectl' is not connected to an active Kubernetes cluster. please configure your computer to access a Kubernetes cluster and rerun the agent: $err" send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_PREREQUISITES" "$LOG_SCRIPT_PREREQUISITES" "$func_name" "$PLATFORM" "$SUB_TYPE" write_task_post_run "write_error \"$message\"" @@ -163,7 +163,7 @@ function can_kubernetes_cluster_connect_to_logzio { kubectl apply -f "$KUBERNETES_RESOURCES_DIR/$yaml_file" >/dev/null 2>"$TASK_ERROR_FILE" if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then echo -e "prerequisites.bash ($EXIT_CODE): error creating '$pod_name' pod: $err" >"$TASK_ERROR_FILE" return 1 fi @@ -176,7 +176,7 @@ function can_kubernetes_cluster_connect_to_logzio { pod_status=$(kubectl get pods 2>"$TASK_ERROR_FILE" | grep "$pod_name" 2>"$TASK_ERROR_FILE" | tr -s ' ' | cut -d ' ' -f3) if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then echo -e "prerequisites.bash ($EXIT_CODE): error getting '$pod_name' pod status: $err" >"$TASK_ERROR_FILE" return 2 fi @@ -197,7 +197,7 @@ function can_kubernetes_cluster_connect_to_logzio { pod_logs=$(kubectl logs "$pod_name" 2>"$TASK_ERROR_FILE") if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then echo -e "prerequisites.bash ($EXIT_CODE): error getting logs of '$pod_name' pod: $err" >"$TASK_ERROR_FILE" fi fi @@ -211,7 +211,7 @@ function can_kubernetes_cluster_connect_to_logzio { pod_logs=$(kubectl logs "$pod_name" 2>"$TASK_ERROR_FILE") if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then echo -e "prerequisites.bash ($EXIT_CODE): error getting logs of '$pod_name' pod: $err" >"$TASK_ERROR_FILE" delete_test_pod "$pod_name" @@ -240,7 +240,7 @@ function delete_test_pod { kubectl delete pod "$pod_name" >/dev/null 2>"$TASK_ERROR_FILE" if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then write_task_post_run "write_warning \"failed to delete '$pod_name' pod: $err\"" fi fi diff --git a/resources-mac/k8s/datasource_installer_utils.bash b/resources-mac/k8s/datasource_installer_utils.bash index 2f9fd4095..d998b7b7d 100755 --- a/resources-mac/k8s/datasource_installer_utils.bash +++ b/resources-mac/k8s/datasource_installer_utils.bash @@ -87,7 +87,7 @@ function build_tolerations_helm_sets { nodes=$(kubectl get nodes -o json 2>"$TASK_ERROR_FILE") if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then message="installer.bash ($EXIT_CODE): error getting nodes: $err" send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_INSTALLATION" "$LOG_SCRIPT_INSTALLER" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" write_task_post_run "write_error \"$message\"" diff --git a/resources-mac/k8s/subtype_postrequisites_utils.bash b/resources-mac/k8s/subtype_postrequisites_utils.bash index b649eb0b6..96feed35f 100755 --- a/resources-mac/k8s/subtype_postrequisites_utils.bash +++ b/resources-mac/k8s/subtype_postrequisites_utils.bash @@ -22,7 +22,7 @@ function are_all_pods_running_or_completed { pod_statuses=$(kubectl get pods -n monitoring --no-headers -o custom-columns=':.status.phase' 2>"$TASK_ERROR_FILE") if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then message="postrequisites.bash ($EXIT_CODE): error getting pods status: $err" send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_POSTREQUISITES" "$LOG_SCRIPT_POSTREQUISITES" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" write_task_post_run "write_error \"$message\"" @@ -69,7 +69,7 @@ function is_any_pod_pending { pods=$(kubectl get pods -n monitoring --no-headers -o custom-columns=':.metadata.name,:.status.phase' 2>"$TASK_ERROR_FILE" | tr -s ' ') if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then write_task_post_run 'IS_POSTREQUISITES_FAILED=true' message="postrequisites.bash ($EXIT_CODE): error getting pods names and status: $err" @@ -92,7 +92,7 @@ function is_any_pod_pending { event_reason=$(kubectl get event -n monitoring --field-selector involvedObject.name="$pod_name" --no-headers -o custom-columns=':.reason' 2>"$TASK_ERROR_FILE" | head -n 1) if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then write_task_post_run 'IS_POSTREQUISITES_FAILED=true' message="postrequisites.bash ($EXIT_CODE): error getting pending pod '$pod_name' reason: $err" @@ -107,7 +107,7 @@ function is_any_pod_pending { event_message=$(kubectl get event -n monitoring --field-selector involvedObject.name="$pod_name" --no-headers -o custom-columns=':.message' 2>"$TASK_ERROR_FILE" | head -n 1) if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then write_task_post_run 'IS_POSTREQUISITES_FAILED=true' message="postrequisites.bash ($EXIT_CODE): error getting pending pod '$pod_name' message: $(get_task_error_message)" @@ -155,7 +155,7 @@ function is_any_pod_failed { pods=$(kubectl get pods -n monitoring --no-headers -o custom-columns=':.metadata.name,:.status.phase' 2>"$TASK_ERROR_FILE" | tr -s ' ') if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then write_task_post_run "IS_POSTREQUISITES_FAILED=true" message="postrequisites.bash ($EXIT_CODE): error getting pods names and status: $err" @@ -178,7 +178,7 @@ function is_any_pod_failed { pod_logs=$(kubectl logs "$pod_name" -n monitoring 2>"$TASK_ERROR_FILE") if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then write_task_post_run "IS_POSTREQUISITES_FAILED=true" message="postrequisites.bash ($EXIT_CODE): error getting pod '$pod_name' logs: $err" diff --git a/resources-mac/k8s/subtype_prerequisites_utils.bash b/resources-mac/k8s/subtype_prerequisites_utils.bash index 28c9e9f12..b7d55f936 100755 --- a/resources-mac/k8s/subtype_prerequisites_utils.bash +++ b/resources-mac/k8s/subtype_prerequisites_utils.bash @@ -42,7 +42,7 @@ function is_kubectl_connected_to_kubernetes_cluster { cluster_info=$(kubectl cluster-info 2>"$TASK_ERROR_FILE") if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then message="prerequisites.bash ($EXIT_CODE): 'kubectl' is not connected to an active Kubernetes cluster. please configure your computer to access a Kubernetes cluster and rerun the agent: $err" send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_PREREQUISITES" "$LOG_SCRIPT_PREREQUISITES" "$func_name" "$PLATFORM" "$SUB_TYPE" write_task_post_run "write_error \"$message\"" @@ -163,7 +163,7 @@ function can_kubernetes_cluster_connect_to_logzio { kubectl apply -f "$KUBERNETES_RESOURCES_DIR/$yaml_file" >/dev/null 2>"$TASK_ERROR_FILE" if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then echo -e "prerequisites.bash ($EXIT_CODE): error creating '$pod_name' pod: $err" >"$TASK_ERROR_FILE" return 1 fi @@ -176,7 +176,7 @@ function can_kubernetes_cluster_connect_to_logzio { pod_status=$(kubectl get pods 2>"$TASK_ERROR_FILE" | grep "$pod_name" 2>"$TASK_ERROR_FILE" | tr -s ' ' | cut -d ' ' -f3) if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then echo -e "prerequisites.bash ($EXIT_CODE): error getting '$pod_name' pod status: $err" >"$TASK_ERROR_FILE" return 2 fi @@ -197,7 +197,7 @@ function can_kubernetes_cluster_connect_to_logzio { pod_logs=$(kubectl logs "$pod_name" 2>"$TASK_ERROR_FILE") if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then echo -e "prerequisites.bash ($EXIT_CODE): error getting logs of '$pod_name' pod: $err" >"$TASK_ERROR_FILE" fi fi @@ -211,7 +211,7 @@ function can_kubernetes_cluster_connect_to_logzio { pod_logs=$(kubectl logs "$pod_name" 2>"$TASK_ERROR_FILE") if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then echo -e "prerequisites.bash ($EXIT_CODE): error getting logs of '$pod_name' pod: $err" >"$TASK_ERROR_FILE" delete_test_pod "$pod_name" @@ -240,7 +240,7 @@ function delete_test_pod { kubectl delete pod "$pod_name" >/dev/null 2>"$TASK_ERROR_FILE" if [[ $? -ne 0 ]]; then local err=$(get_task_error_message) - if [[ "$err" == *"ERROR"* ]]; then + if [[ "$err" == *"ERROR"* || "$err" == *"error"* ]]; then write_task_post_run "write_warning \"failed to delete '$pod_name' pod: $err\"" fi fi From d5eb30b74b9b20cc5eb635507ea490ec9427cd00 Mon Sep 17 00:00:00 2001 From: ShiranAvidov Date: Mon, 22 May 2023 17:05:38 +0300 Subject: [PATCH 3/5] fix checking tmp space --- scripts/linux/functions.bash | 4 ++-- scripts/mac/functions.bash | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/linux/functions.bash b/scripts/linux/functions.bash index 5d584d981..12706c0fa 100755 --- a/scripts/linux/functions.bash +++ b/scripts/linux/functions.bash @@ -91,8 +91,8 @@ function is_tmp_directory_out_of_space { send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_PRE_INIT" "$LOG_SCRIPT_AGENT" "$func_name" "$AGENT_ID" write_log "$LOG_LEVEL_DEBUG" "$message" - local available_space=$(df -k /tmp | tail -n 1 | tr -s " " | cut -d' ' -f4) - if [[ $available_space -lt 1 ]]; then + local available_space=$(df -m /tmp | tail -n 1 | tr -s " " | cut -d' ' -f4) + if [[ $available_space -lt 750 ]]; then message="agent.bash ($EXIT_CODE): '/tmp' must have at least 1GB free space" send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_PRE_INIT" "$LOG_SCRIPT_AGENT" "$func_name" "$AGENT_ID" write_task_post_run "write_error \"$message\"" diff --git a/scripts/mac/functions.bash b/scripts/mac/functions.bash index 6891a8ef2..e3fe4ac1e 100755 --- a/scripts/mac/functions.bash +++ b/scripts/mac/functions.bash @@ -91,8 +91,8 @@ function is_tmp_directory_out_of_space { send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_PRE_INIT" "$LOG_SCRIPT_AGENT" "$func_name" "$AGENT_ID" write_log "$LOG_LEVEL_DEBUG" "$message" - local use_percentage=$(df /tmp | tail -n 1 | tr -s " " | cut -d' ' -f5 | grep -o [0-9]*) - if [[ $use_percentage -gt 90 ]]; then + local available_space=$(df -m /tmp | tail -n 1 | tr -s " " | cut -d' ' -f4) + if [[ $available_space -lt 750 ]]; then message="agent.bash ($EXIT_CODE): '/tmp' is almost out of space - over 90% space in use" send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_PRE_INIT" "$LOG_SCRIPT_AGENT" "$func_name" "$AGENT_ID" write_task_post_run "write_error \"$message\"" From c49f313878dc20340bf0c99a1f246f1d4873dda6 Mon Sep 17 00:00:00 2001 From: ShiranAvidov Date: Mon, 22 May 2023 17:10:23 +0300 Subject: [PATCH 4/5] fix --- scripts/mac/functions.bash | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/scripts/mac/functions.bash b/scripts/mac/functions.bash index e3fe4ac1e..4cad53597 100755 --- a/scripts/mac/functions.bash +++ b/scripts/mac/functions.bash @@ -93,30 +93,7 @@ function is_tmp_directory_out_of_space { local available_space=$(df -m /tmp | tail -n 1 | tr -s " " | cut -d' ' -f4) if [[ $available_space -lt 750 ]]; then - message="agent.bash ($EXIT_CODE): '/tmp' is almost out of space - over 90% space in use" - send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_PRE_INIT" "$LOG_SCRIPT_AGENT" "$func_name" "$AGENT_ID" - write_task_post_run "write_error \"$message\"" - - return $EXIT_CODE - fi -} - -# Checks if /tmp directory is out of space -# Input: -# --- -# Output: -# --- -function is_tmp_directory_out_of_space { - local func_name="${FUNCNAME[0]}" - - local message="Checking if '/tmp' directory is out of space ..." - send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_PRE_INIT" "$LOG_SCRIPT_AGENT" "$func_name" "$AGENT_ID" - write_log "$LOG_LEVEL_DEBUG" "$message" - - local available_space=$(df -k /tmp | tail -n 1 | tr -s " " | cut -d' ' -f4) - available_space=$((available_space/1024/1024)) - if [[ $available_space -ls 1 ]]; then - message="agent.bash ($EXIT_CODE): '/tmp' must have at least 1GB free space" + message="agent.bash ($EXIT_CODE): '/tmp' must have at least 750MB free space" send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_PRE_INIT" "$LOG_SCRIPT_AGENT" "$func_name" "$AGENT_ID" write_task_post_run "write_error \"$message\"" From 6b9aff84652a647b79c2d9624201f74435559439 Mon Sep 17 00:00:00 2001 From: ShiranAvidov Date: Mon, 22 May 2023 17:10:44 +0300 Subject: [PATCH 5/5] fix --- scripts/linux/functions.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/linux/functions.bash b/scripts/linux/functions.bash index 12706c0fa..4878f3e1a 100755 --- a/scripts/linux/functions.bash +++ b/scripts/linux/functions.bash @@ -93,7 +93,7 @@ function is_tmp_directory_out_of_space { local available_space=$(df -m /tmp | tail -n 1 | tr -s " " | cut -d' ' -f4) if [[ $available_space -lt 750 ]]; then - message="agent.bash ($EXIT_CODE): '/tmp' must have at least 1GB free space" + message="agent.bash ($EXIT_CODE): '/tmp' must have at least 750MB free space" send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_PRE_INIT" "$LOG_SCRIPT_AGENT" "$func_name" "$AGENT_ID" write_task_post_run "write_error \"$message\""