Skip to content

Commit

Permalink
Add deploy events agent scripts
Browse files Browse the repository at this point in the history
- Added deploy events datasource scripts per platform and sub type.
  - Gets token, listener, env_id from agent.
  - Checks which options were chose.
  • Loading branch information
ralongit committed Nov 7, 2023
1 parent 3823c78 commit 010264b
Show file tree
Hide file tree
Showing 74 changed files with 3,744 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash

#################################################################################################################################
############################################ LINUX Datasource Installer Functions ###############################################
#################################################################################################################################

# Loads datasource installer utils functions
# Input:
# ---
# Output:
# ---
function load_installer_utils {
local func_name="${FUNCNAME[0]}"

local message='Loading installer utils functions ...'
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_log "$LOG_LEVEL_DEBUG" "$message"

source "$ALL_RESOURCES_LINUX_DIR/datasource_installer_utils.bash" 2>"$TASK_ERROR_FILE"
if [[ $? -ne 0 ]]; then
message="installer.bash ($EXIT_CODE): error loading installer utils functions: $(get_task_error_message)"
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_error "$message"

IS_AGENT_FAILED=true
run_final
exit $EXIT_CODE
fi

source "$KUBERNETES_RESOURCES_LINUX_DIR/datasource_installer_utils.bash" 2>"$TASK_ERROR_FILE"
if [[ $? -ne 0 ]]; then
message="installer.bash ($EXIT_CODE): error loading installer utils functions: $(get_task_error_message)"
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_error "$message"

IS_AGENT_FAILED=true
run_final
exit $EXIT_CODE
fi

((EXIT_CODE++))
}

# Gets environment id
# Input:
# ---
# Output:
# ENV_ID - The environment id
function get_environment_id {
local func_name="${FUNCNAME[0]}"

local message='Getting environment id ...'
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_log "$LOG_LEVEL_DEBUG" "$message"

PARAMS=("${GENERAL_PARAMS[@]}")
get_param_value 'envID'
if [[ $? -ne 0 ]]; then
message="installer.bash ($EXIT_CODE): $(get_task_error_message)"
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\""

return $EXIT_CODE
fi

local env_id="$PARAM_VALUE"

if [[ "$env_id" == '' ]]; then
env_id=$(kubectl config current-context 2>"$TASK_ERROR_FILE")
if [[ $? -ne 0 ]]; then
local err=$(get_task_error_message)
if [[ "$err" == *"ERROR"* ]]; then
env_id=$(echo "$RANDOM" | md5sum | cut -c 1-32)
fi
fi
fi

message="Environment id is '$env_id'"
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_log "$LOG_LEVEL_DEBUG" "$message"

write_task_post_run "ENV_ID='$env_id'"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

#################################################################################################################################
############################################## LINUX Datasource Installer Script ################################################
#################################################################################################################################

# Print title
echo
echo -e '########################################'
echo -e "###$PURPLE_COLOR Security Datasource Installation $WHITE_COLOR###"
echo -e '########################################'

EXIT_CODE=1

# Load datasource installer utils functions
load_installer_utils

# Get the selected products
execute_task 'get_selected_products' 'Getting selected products'
# Get general params
execute_task 'get_general_params' 'Getting general params'
# Get environment id
execute_task 'get_environment_id' 'Getting environment id'

DATA_SOURCE_INSTALLER_EXIT_CODE=$EXIT_CODE

if $IS_LOGS_OPTION_WAS_SELECTED; then
# Run logs script
run_logs
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

#################################################################################################################################
########################################## LINUX Datasource Prerequisites Functions #############################################
#################################################################################################################################
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

#################################################################################################################################
############################################ LINUX Datasource Prerequisites Script ##############################################
#################################################################################################################################
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

#################################################################################################################################
############################################## LINUX Datasource Logs Functions ##################################################
#################################################################################################################################

# Loads datasource logs utils functions
# Input:
# ---
# Output:
# ---
function load_logs_utils {
local func_name="${FUNCNAME[0]}"

local message='Loading logs utils functions ...'
send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_LOGS" "$LOG_SCRIPT_LOGS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
write_log "$LOG_LEVEL_DEBUG" "$message"

source "$ALL_RESOURCES_LINUX_DIR/datasource_logs_utils.bash" 2>"$TASK_ERROR_FILE"
if [[ $? -ne 0 ]]; then
message="logs.bash ($EXIT_CODE): error loading logs utils functions: $(get_task_error_message)"
send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_LOGS" "$LOG_SCRIPT_LOGS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
write_error "$message"

IS_AGENT_FAILED=true
run_final
exit $EXIT_CODE
fi

source "$KUBERNETES_RESOURCES_LINUX_DIR/datasource_logs_utils.bash" 2>"$TASK_ERROR_FILE"
if [[ $? -ne 0 ]]; then
message="logs.bash ($EXIT_CODE): error loading logs utils functions: $(get_task_error_message)"
send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_LOGS" "$LOG_SCRIPT_LOGS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
write_error "$message"

IS_AGENT_FAILED=true
run_final
exit $EXIT_CODE
fi

((EXIT_CODE++))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

#################################################################################################################################
################################################ LINUX Datasource Logs Script ###################################################
#################################################################################################################################

# Print title
echo
echo -e '############'
echo -e "###$PURPLE_COLOR Logs $WHITE_COLOR###"
echo -e '############'

EXIT_CODE=1

# Load datasource logs utils functions
load_logs_utils

# Get Logz.io logs token
execute_task 'get_logzio_logs_token' 'Getting Logz.io logs token'
# Build enable deploy events Helm set
execute_task "build_enable_deploy_events_helm_set" "Building enable deploy events Helm set"
# Build Logz.io deploy events logs listener URL Helm set
execute_task "build_logzio_deploy_events_logs_listener_url_helm_set" "Building Logz.io deploy events logs listener URL Helm set"
# Build Logz.io deploy events logs token Helm set
execute_task "build_logzio_deploy_events_logs_token_helm_set" "Building Logz.io deploy events logs token Helm set"
# Build Deploy events environment id Helm set
execute_task "build_deploy_events_environment_id_helm_set" "Building deploy events environment id Helm set"
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash

#################################################################################################################################
############################################ LINUX Datasource Installer Functions ###############################################
#################################################################################################################################

# Loads datasource installer utils functions
# Input:
# ---
# Output:
# ---
function load_installer_utils {
local func_name="${FUNCNAME[0]}"

local message='Loading installer utils functions ...'
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_log "$LOG_LEVEL_DEBUG" "$message"

source "$ALL_RESOURCES_LINUX_DIR/datasource_installer_utils.bash" 2>"$TASK_ERROR_FILE"
if [[ $? -ne 0 ]]; then
message="installer.bash ($EXIT_CODE): error loading installer utils functions: $(get_task_error_message)"
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_error "$message"

IS_AGENT_FAILED=true
run_final
exit $EXIT_CODE
fi

source "$KUBERNETES_RESOURCES_LINUX_DIR/datasource_installer_utils.bash" 2>"$TASK_ERROR_FILE"
if [[ $? -ne 0 ]]; then
message="installer.bash ($EXIT_CODE): error loading installer utils functions: $(get_task_error_message)"
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_error "$message"

IS_AGENT_FAILED=true
run_final
exit $EXIT_CODE
fi

((EXIT_CODE++))
}

# Gets environment id
# Input:
# ---
# Output:
# ENV_ID - The environment id
function get_environment_id {
local func_name="${FUNCNAME[0]}"

local message='Getting environment id ...'
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_log "$LOG_LEVEL_DEBUG" "$message"

PARAMS=("${GENERAL_PARAMS[@]}")
get_param_value 'envID'
if [[ $? -ne 0 ]]; then
message="installer.bash ($EXIT_CODE): $(get_task_error_message)"
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\""

return $EXIT_CODE
fi

local env_id="$PARAM_VALUE"

if [[ "$env_id" == '' ]]; then
env_id=$(kubectl config current-context 2>"$TASK_ERROR_FILE")
if [[ $? -ne 0 ]]; then
local err=$(get_task_error_message)
if [[ "$err" == *"ERROR"* ]]; then
env_id=$(echo "$RANDOM" | md5sum | cut -c 1-32)
fi
fi
fi

message="Environment id is '$env_id'"
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_log "$LOG_LEVEL_DEBUG" "$message"

write_task_post_run "ENV_ID='$env_id'"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

#################################################################################################################################
############################################## LINUX Datasource Installer Script ################################################
#################################################################################################################################

# Print title
echo
echo -e '########################################'
echo -e "###$PURPLE_COLOR Security Datasource Installation $WHITE_COLOR###"
echo -e '########################################'

EXIT_CODE=1

# Load datasource installer utils functions
load_installer_utils

# Get the selected products
execute_task 'get_selected_products' 'Getting selected products'
# Get general params
execute_task 'get_general_params' 'Getting general params'
# Get environment id
execute_task 'get_environment_id' 'Getting environment id'

DATA_SOURCE_INSTALLER_EXIT_CODE=$EXIT_CODE

if $IS_LOGS_OPTION_WAS_SELECTED; then
# Run logs script
run_logs
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

#################################################################################################################################
########################################## LINUX Datasource Prerequisites Functions #############################################
#################################################################################################################################
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

#################################################################################################################################
############################################ LINUX Datasource Prerequisites Script ##############################################
#################################################################################################################################
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

#################################################################################################################################
############################################## LINUX Datasource Logs Functions ##################################################
#################################################################################################################################

# Loads datasource logs utils functions
# Input:
# ---
# Output:
# ---
function load_logs_utils {
local func_name="${FUNCNAME[0]}"

local message='Loading logs utils functions ...'
send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_LOGS" "$LOG_SCRIPT_LOGS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
write_log "$LOG_LEVEL_DEBUG" "$message"

source "$ALL_RESOURCES_LINUX_DIR/datasource_logs_utils.bash" 2>"$TASK_ERROR_FILE"
if [[ $? -ne 0 ]]; then
message="logs.bash ($EXIT_CODE): error loading logs utils functions: $(get_task_error_message)"
send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_LOGS" "$LOG_SCRIPT_LOGS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
write_error "$message"

IS_AGENT_FAILED=true
run_final
exit $EXIT_CODE
fi

source "$KUBERNETES_RESOURCES_LINUX_DIR/datasource_logs_utils.bash" 2>"$TASK_ERROR_FILE"
if [[ $? -ne 0 ]]; then
message="logs.bash ($EXIT_CODE): error loading logs utils functions: $(get_task_error_message)"
send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_LOGS" "$LOG_SCRIPT_LOGS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
write_error "$message"

IS_AGENT_FAILED=true
run_final
exit $EXIT_CODE
fi

((EXIT_CODE++))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

#################################################################################################################################
################################################ LINUX Datasource Logs Script ###################################################
#################################################################################################################################

# Print title
echo
echo -e '############'
echo -e "###$PURPLE_COLOR Logs $WHITE_COLOR###"
echo -e '############'

EXIT_CODE=1

# Load datasource logs utils functions
load_logs_utils

# Get Logz.io logs token
execute_task 'get_logzio_logs_token' 'Getting Logz.io logs token'
# Build enable deploy events Helm set
execute_task "build_enable_deploy_events_helm_set" "Building enable deploy events Helm set"
# Build Logz.io deploy events logs listener URL Helm set
execute_task "build_logzio_deploy_events_logs_listener_url_helm_set" "Building Logz.io deploy events logs listener URL Helm set"
# Build Logz.io deploy events logs token Helm set
execute_task "build_logzio_deploy_events_logs_token_helm_set" "Building Logz.io deploy events logs token Helm set"
# Build Deploy events environment id Helm set
execute_task "build_deploy_events_environment_id_helm_set" "Building deploy events environment id Helm set"
Loading

0 comments on commit 010264b

Please sign in to comment.