Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check tmp size + fix error regex #92

Open
wants to merge 6 commits into
base: v1.0.11
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources-linux/k8s/datasource_installer_utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
Expand Down
12 changes: 6 additions & 6 deletions resources-linux/k8s/subtype_postrequisites_utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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)"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions resources-linux/k8s/subtype_prerequisites_utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion resources-mac/k8s/datasource_installer_utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
Expand Down
12 changes: 6 additions & 6 deletions resources-mac/k8s/subtype_postrequisites_utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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)"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions resources-mac/k8s/subtype_prerequisites_utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions scripts/linux/agent.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions scripts/linux/functions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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 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:
Expand Down
2 changes: 2 additions & 0 deletions scripts/mac/agent.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions scripts/mac/functions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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 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"
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:
Expand Down