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 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..4878f3e1a 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 -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 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\"" + + 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..4cad53597 100755 --- a/scripts/mac/functions.bash +++ b/scripts/mac/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 -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 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\"" + + return $EXIT_CODE + fi +} # Prints usage # Input: