From 010264b9110e77360bf38f8636d20313a1959daf Mon Sep 17 00:00:00 2001 From: ralongit Date: Tue, 7 Nov 2023 17:46:22 +0200 Subject: [PATCH] Add deploy events agent scripts - Added deploy events datasource scripts per platform and sub type. - Gets token, listener, env_id from agent. - Checks which options were chose. --- .../aks/deployevents/installer/functions.bash | 83 +++++++ .../aks/deployevents/installer/installer.bash | 30 +++ .../deployevents/prerequisites/functions.bash | 5 + .../prerequisites/prerequisites.bash | 5 + .../telemetry/logs/functions.bash | 42 ++++ .../aks/deployevents/telemetry/logs/logs.bash | 27 ++ .../deployevents/installer/functions.bash | 83 +++++++ .../deployevents/installer/installer.bash | 30 +++ .../deployevents/prerequisites/functions.bash | 5 + .../prerequisites/prerequisites.bash | 5 + .../telemetry/logs/functions.bash | 42 ++++ .../deployevents/telemetry/logs/logs.bash | 27 ++ .../eks/deployevents/installer/functions.bash | 86 +++++++ .../eks/deployevents/installer/installer.bash | 30 +++ .../deployevents/prerequisites/functions.bash | 5 + .../prerequisites/prerequisites.bash | 5 + .../telemetry/logs/functions.bash | 42 ++++ .../eks/deployevents/telemetry/logs/logs.bash | 27 ++ .../gke/deployevents/installer/functions.bash | 86 +++++++ .../gke/deployevents/installer/installer.bash | 30 +++ .../deployevents/prerequisites/functions.bash | 5 + .../prerequisites/prerequisites.bash | 5 + .../telemetry/logs/functions.bash | 42 ++++ .../gke/deployevents/telemetry/logs/logs.bash | 27 ++ .../aks/deployevents/installer/functions.bash | 83 +++++++ .../aks/deployevents/installer/installer.bash | 30 +++ .../deployevents/prerequisites/functions.bash | 5 + .../prerequisites/prerequisites.bash | 5 + .../telemetry/logs/functions.bash | 42 ++++ .../aks/deployevents/telemetry/logs/logs.bash | 27 ++ .../deployevents/installer/functions.bash | 83 +++++++ .../deployevents/installer/installer.bash | 30 +++ .../deployevents/prerequisites/functions.bash | 5 + .../prerequisites/prerequisites.bash | 5 + .../telemetry/logs/functions.bash | 42 ++++ .../deployevents/telemetry/logs/logs.bash | 27 ++ .../eks/deployevents/installer/functions.bash | 86 +++++++ .../eks/deployevents/installer/installer.bash | 30 +++ .../deployevents/prerequisites/functions.bash | 5 + .../prerequisites/prerequisites.bash | 5 + .../telemetry/logs/functions.bash | 42 ++++ .../eks/deployevents/telemetry/logs/logs.bash | 27 ++ .../gke/deployevents/installer/functions.bash | 86 +++++++ .../gke/deployevents/installer/installer.bash | 30 +++ .../deployevents/prerequisites/functions.bash | 5 + .../prerequisites/prerequisites.bash | 5 + .../telemetry/logs/functions.bash | 42 ++++ .../gke/deployevents/telemetry/logs/logs.bash | 27 ++ .../aks/deployevents/installer/functions.ps1 | 229 +++++++++++++++++ .../aks/deployevents/installer/installer.ps1 | 55 +++++ .../deployevents/prerequisites/functions.ps1 | 3 + .../prerequisites/prerequisites.ps1 | 6 + .../deployevents/telemetry/logs/functions.ps1 | 182 ++++++++++++++ .../aks/deployevents/telemetry/logs/logs.ps1 | 27 ++ .../deployevents/installer/functions.ps1 | 229 +++++++++++++++++ .../deployevents/installer/installer.ps1 | 55 +++++ .../deployevents/prerequisites/functions.ps1 | 3 + .../prerequisites/prerequisites.ps1 | 6 + .../deployevents/telemetry/logs/functions.ps1 | 182 ++++++++++++++ .../deployevents/telemetry/logs/logs.ps1 | 27 ++ .../eks/deployevents/installer/functions.ps1 | 231 ++++++++++++++++++ .../eks/deployevents/installer/installer.ps1 | 55 +++++ .../deployevents/prerequisites/functions.ps1 | 3 + .../prerequisites/prerequisites.ps1 | 6 + .../deployevents/telemetry/logs/functions.ps1 | 182 ++++++++++++++ .../eks/deployevents/telemetry/logs/logs.ps1 | 27 ++ .../gke/deployevents/installer/functions.ps1 | 231 ++++++++++++++++++ .../gke/deployevents/installer/installer.ps1 | 55 +++++ .../deployevents/prerequisites/functions.ps1 | 3 + .../prerequisites/prerequisites.ps1 | 6 + .../deployevents/telemetry/logs/functions.ps1 | 182 ++++++++++++++ .../gke/deployevents/telemetry/logs/logs.ps1 | 27 ++ .../k8s/datasource_logs_utils.bash | 92 +++++++ resources-mac/k8s/datasource_logs_utils.bash | 92 +++++++ 74 files changed, 3744 insertions(+) create mode 100755 datasources/linux/kubernetes/aks/deployevents/installer/functions.bash create mode 100755 datasources/linux/kubernetes/aks/deployevents/installer/installer.bash create mode 100755 datasources/linux/kubernetes/aks/deployevents/prerequisites/functions.bash create mode 100644 datasources/linux/kubernetes/aks/deployevents/prerequisites/prerequisites.bash create mode 100755 datasources/linux/kubernetes/aks/deployevents/telemetry/logs/functions.bash create mode 100755 datasources/linux/kubernetes/aks/deployevents/telemetry/logs/logs.bash create mode 100755 datasources/linux/kubernetes/digitalocean/deployevents/installer/functions.bash create mode 100755 datasources/linux/kubernetes/digitalocean/deployevents/installer/installer.bash create mode 100755 datasources/linux/kubernetes/digitalocean/deployevents/prerequisites/functions.bash create mode 100644 datasources/linux/kubernetes/digitalocean/deployevents/prerequisites/prerequisites.bash create mode 100755 datasources/linux/kubernetes/digitalocean/deployevents/telemetry/logs/functions.bash create mode 100755 datasources/linux/kubernetes/digitalocean/deployevents/telemetry/logs/logs.bash create mode 100755 datasources/linux/kubernetes/eks/deployevents/installer/functions.bash create mode 100755 datasources/linux/kubernetes/eks/deployevents/installer/installer.bash create mode 100755 datasources/linux/kubernetes/eks/deployevents/prerequisites/functions.bash create mode 100644 datasources/linux/kubernetes/eks/deployevents/prerequisites/prerequisites.bash create mode 100755 datasources/linux/kubernetes/eks/deployevents/telemetry/logs/functions.bash create mode 100755 datasources/linux/kubernetes/eks/deployevents/telemetry/logs/logs.bash create mode 100755 datasources/linux/kubernetes/gke/deployevents/installer/functions.bash create mode 100755 datasources/linux/kubernetes/gke/deployevents/installer/installer.bash create mode 100755 datasources/linux/kubernetes/gke/deployevents/prerequisites/functions.bash create mode 100644 datasources/linux/kubernetes/gke/deployevents/prerequisites/prerequisites.bash create mode 100755 datasources/linux/kubernetes/gke/deployevents/telemetry/logs/functions.bash create mode 100755 datasources/linux/kubernetes/gke/deployevents/telemetry/logs/logs.bash create mode 100755 datasources/mac/kubernetes/aks/deployevents/installer/functions.bash create mode 100755 datasources/mac/kubernetes/aks/deployevents/installer/installer.bash create mode 100755 datasources/mac/kubernetes/aks/deployevents/prerequisites/functions.bash create mode 100644 datasources/mac/kubernetes/aks/deployevents/prerequisites/prerequisites.bash create mode 100755 datasources/mac/kubernetes/aks/deployevents/telemetry/logs/functions.bash create mode 100755 datasources/mac/kubernetes/aks/deployevents/telemetry/logs/logs.bash create mode 100755 datasources/mac/kubernetes/digitalocean/deployevents/installer/functions.bash create mode 100755 datasources/mac/kubernetes/digitalocean/deployevents/installer/installer.bash create mode 100755 datasources/mac/kubernetes/digitalocean/deployevents/prerequisites/functions.bash create mode 100644 datasources/mac/kubernetes/digitalocean/deployevents/prerequisites/prerequisites.bash create mode 100755 datasources/mac/kubernetes/digitalocean/deployevents/telemetry/logs/functions.bash create mode 100755 datasources/mac/kubernetes/digitalocean/deployevents/telemetry/logs/logs.bash create mode 100755 datasources/mac/kubernetes/eks/deployevents/installer/functions.bash create mode 100755 datasources/mac/kubernetes/eks/deployevents/installer/installer.bash create mode 100755 datasources/mac/kubernetes/eks/deployevents/prerequisites/functions.bash create mode 100644 datasources/mac/kubernetes/eks/deployevents/prerequisites/prerequisites.bash create mode 100755 datasources/mac/kubernetes/eks/deployevents/telemetry/logs/functions.bash create mode 100755 datasources/mac/kubernetes/eks/deployevents/telemetry/logs/logs.bash create mode 100755 datasources/mac/kubernetes/gke/deployevents/installer/functions.bash create mode 100755 datasources/mac/kubernetes/gke/deployevents/installer/installer.bash create mode 100755 datasources/mac/kubernetes/gke/deployevents/prerequisites/functions.bash create mode 100644 datasources/mac/kubernetes/gke/deployevents/prerequisites/prerequisites.bash create mode 100755 datasources/mac/kubernetes/gke/deployevents/telemetry/logs/functions.bash create mode 100755 datasources/mac/kubernetes/gke/deployevents/telemetry/logs/logs.bash create mode 100755 datasources/windows/kubernetes/aks/deployevents/installer/functions.ps1 create mode 100755 datasources/windows/kubernetes/aks/deployevents/installer/installer.ps1 create mode 100755 datasources/windows/kubernetes/aks/deployevents/prerequisites/functions.ps1 create mode 100644 datasources/windows/kubernetes/aks/deployevents/prerequisites/prerequisites.ps1 create mode 100755 datasources/windows/kubernetes/aks/deployevents/telemetry/logs/functions.ps1 create mode 100755 datasources/windows/kubernetes/aks/deployevents/telemetry/logs/logs.ps1 create mode 100755 datasources/windows/kubernetes/digitalocean/deployevents/installer/functions.ps1 create mode 100755 datasources/windows/kubernetes/digitalocean/deployevents/installer/installer.ps1 create mode 100755 datasources/windows/kubernetes/digitalocean/deployevents/prerequisites/functions.ps1 create mode 100644 datasources/windows/kubernetes/digitalocean/deployevents/prerequisites/prerequisites.ps1 create mode 100755 datasources/windows/kubernetes/digitalocean/deployevents/telemetry/logs/functions.ps1 create mode 100755 datasources/windows/kubernetes/digitalocean/deployevents/telemetry/logs/logs.ps1 create mode 100755 datasources/windows/kubernetes/eks/deployevents/installer/functions.ps1 create mode 100755 datasources/windows/kubernetes/eks/deployevents/installer/installer.ps1 create mode 100755 datasources/windows/kubernetes/eks/deployevents/prerequisites/functions.ps1 create mode 100644 datasources/windows/kubernetes/eks/deployevents/prerequisites/prerequisites.ps1 create mode 100755 datasources/windows/kubernetes/eks/deployevents/telemetry/logs/functions.ps1 create mode 100755 datasources/windows/kubernetes/eks/deployevents/telemetry/logs/logs.ps1 create mode 100755 datasources/windows/kubernetes/gke/deployevents/installer/functions.ps1 create mode 100755 datasources/windows/kubernetes/gke/deployevents/installer/installer.ps1 create mode 100755 datasources/windows/kubernetes/gke/deployevents/prerequisites/functions.ps1 create mode 100644 datasources/windows/kubernetes/gke/deployevents/prerequisites/prerequisites.ps1 create mode 100755 datasources/windows/kubernetes/gke/deployevents/telemetry/logs/functions.ps1 create mode 100755 datasources/windows/kubernetes/gke/deployevents/telemetry/logs/logs.ps1 diff --git a/datasources/linux/kubernetes/aks/deployevents/installer/functions.bash b/datasources/linux/kubernetes/aks/deployevents/installer/functions.bash new file mode 100755 index 000000000..dde70ce21 --- /dev/null +++ b/datasources/linux/kubernetes/aks/deployevents/installer/functions.bash @@ -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'" +} diff --git a/datasources/linux/kubernetes/aks/deployevents/installer/installer.bash b/datasources/linux/kubernetes/aks/deployevents/installer/installer.bash new file mode 100755 index 000000000..3e6e16145 --- /dev/null +++ b/datasources/linux/kubernetes/aks/deployevents/installer/installer.bash @@ -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 diff --git a/datasources/linux/kubernetes/aks/deployevents/prerequisites/functions.bash b/datasources/linux/kubernetes/aks/deployevents/prerequisites/functions.bash new file mode 100755 index 000000000..7229d31f7 --- /dev/null +++ b/datasources/linux/kubernetes/aks/deployevents/prerequisites/functions.bash @@ -0,0 +1,5 @@ +#!/bin/bash + +################################################################################################################################# +########################################## LINUX Datasource Prerequisites Functions ############################################# +################################################################################################################################# diff --git a/datasources/linux/kubernetes/aks/deployevents/prerequisites/prerequisites.bash b/datasources/linux/kubernetes/aks/deployevents/prerequisites/prerequisites.bash new file mode 100644 index 000000000..4269857ef --- /dev/null +++ b/datasources/linux/kubernetes/aks/deployevents/prerequisites/prerequisites.bash @@ -0,0 +1,5 @@ +#!/bin/bash + +################################################################################################################################# +############################################ LINUX Datasource Prerequisites Script ############################################## +################################################################################################################################# diff --git a/datasources/linux/kubernetes/aks/deployevents/telemetry/logs/functions.bash b/datasources/linux/kubernetes/aks/deployevents/telemetry/logs/functions.bash new file mode 100755 index 000000000..9cc5b4176 --- /dev/null +++ b/datasources/linux/kubernetes/aks/deployevents/telemetry/logs/functions.bash @@ -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++)) +} diff --git a/datasources/linux/kubernetes/aks/deployevents/telemetry/logs/logs.bash b/datasources/linux/kubernetes/aks/deployevents/telemetry/logs/logs.bash new file mode 100755 index 000000000..983d6318f --- /dev/null +++ b/datasources/linux/kubernetes/aks/deployevents/telemetry/logs/logs.bash @@ -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" diff --git a/datasources/linux/kubernetes/digitalocean/deployevents/installer/functions.bash b/datasources/linux/kubernetes/digitalocean/deployevents/installer/functions.bash new file mode 100755 index 000000000..dde70ce21 --- /dev/null +++ b/datasources/linux/kubernetes/digitalocean/deployevents/installer/functions.bash @@ -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'" +} diff --git a/datasources/linux/kubernetes/digitalocean/deployevents/installer/installer.bash b/datasources/linux/kubernetes/digitalocean/deployevents/installer/installer.bash new file mode 100755 index 000000000..3e6e16145 --- /dev/null +++ b/datasources/linux/kubernetes/digitalocean/deployevents/installer/installer.bash @@ -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 diff --git a/datasources/linux/kubernetes/digitalocean/deployevents/prerequisites/functions.bash b/datasources/linux/kubernetes/digitalocean/deployevents/prerequisites/functions.bash new file mode 100755 index 000000000..7229d31f7 --- /dev/null +++ b/datasources/linux/kubernetes/digitalocean/deployevents/prerequisites/functions.bash @@ -0,0 +1,5 @@ +#!/bin/bash + +################################################################################################################################# +########################################## LINUX Datasource Prerequisites Functions ############################################# +################################################################################################################################# diff --git a/datasources/linux/kubernetes/digitalocean/deployevents/prerequisites/prerequisites.bash b/datasources/linux/kubernetes/digitalocean/deployevents/prerequisites/prerequisites.bash new file mode 100644 index 000000000..4269857ef --- /dev/null +++ b/datasources/linux/kubernetes/digitalocean/deployevents/prerequisites/prerequisites.bash @@ -0,0 +1,5 @@ +#!/bin/bash + +################################################################################################################################# +############################################ LINUX Datasource Prerequisites Script ############################################## +################################################################################################################################# diff --git a/datasources/linux/kubernetes/digitalocean/deployevents/telemetry/logs/functions.bash b/datasources/linux/kubernetes/digitalocean/deployevents/telemetry/logs/functions.bash new file mode 100755 index 000000000..9cc5b4176 --- /dev/null +++ b/datasources/linux/kubernetes/digitalocean/deployevents/telemetry/logs/functions.bash @@ -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++)) +} diff --git a/datasources/linux/kubernetes/digitalocean/deployevents/telemetry/logs/logs.bash b/datasources/linux/kubernetes/digitalocean/deployevents/telemetry/logs/logs.bash new file mode 100755 index 000000000..983d6318f --- /dev/null +++ b/datasources/linux/kubernetes/digitalocean/deployevents/telemetry/logs/logs.bash @@ -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" diff --git a/datasources/linux/kubernetes/eks/deployevents/installer/functions.bash b/datasources/linux/kubernetes/eks/deployevents/installer/functions.bash new file mode 100755 index 000000000..8208afe4a --- /dev/null +++ b/datasources/linux/kubernetes/eks/deployevents/installer/functions.bash @@ -0,0 +1,86 @@ +#!/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 + local cluster_name + cluster_name=$(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 + else + env_id=$(echo "$cluster_name" | cut -d'/' -f2) + 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'" +} diff --git a/datasources/linux/kubernetes/eks/deployevents/installer/installer.bash b/datasources/linux/kubernetes/eks/deployevents/installer/installer.bash new file mode 100755 index 000000000..8999e1b65 --- /dev/null +++ b/datasources/linux/kubernetes/eks/deployevents/installer/installer.bash @@ -0,0 +1,30 @@ +#!/bin/bash + +################################################################################################################################# +############################################## LINUX Datasource Installer Script ################################################ +################################################################################################################################# + +# Print title +echo +echo -e '########################################' +echo -e "###$PURPLE_COLOR Deploy Events 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 diff --git a/datasources/linux/kubernetes/eks/deployevents/prerequisites/functions.bash b/datasources/linux/kubernetes/eks/deployevents/prerequisites/functions.bash new file mode 100755 index 000000000..7229d31f7 --- /dev/null +++ b/datasources/linux/kubernetes/eks/deployevents/prerequisites/functions.bash @@ -0,0 +1,5 @@ +#!/bin/bash + +################################################################################################################################# +########################################## LINUX Datasource Prerequisites Functions ############################################# +################################################################################################################################# diff --git a/datasources/linux/kubernetes/eks/deployevents/prerequisites/prerequisites.bash b/datasources/linux/kubernetes/eks/deployevents/prerequisites/prerequisites.bash new file mode 100644 index 000000000..4269857ef --- /dev/null +++ b/datasources/linux/kubernetes/eks/deployevents/prerequisites/prerequisites.bash @@ -0,0 +1,5 @@ +#!/bin/bash + +################################################################################################################################# +############################################ LINUX Datasource Prerequisites Script ############################################## +################################################################################################################################# diff --git a/datasources/linux/kubernetes/eks/deployevents/telemetry/logs/functions.bash b/datasources/linux/kubernetes/eks/deployevents/telemetry/logs/functions.bash new file mode 100755 index 000000000..9cc5b4176 --- /dev/null +++ b/datasources/linux/kubernetes/eks/deployevents/telemetry/logs/functions.bash @@ -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++)) +} diff --git a/datasources/linux/kubernetes/eks/deployevents/telemetry/logs/logs.bash b/datasources/linux/kubernetes/eks/deployevents/telemetry/logs/logs.bash new file mode 100755 index 000000000..983d6318f --- /dev/null +++ b/datasources/linux/kubernetes/eks/deployevents/telemetry/logs/logs.bash @@ -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" diff --git a/datasources/linux/kubernetes/gke/deployevents/installer/functions.bash b/datasources/linux/kubernetes/gke/deployevents/installer/functions.bash new file mode 100755 index 000000000..6e580a30e --- /dev/null +++ b/datasources/linux/kubernetes/gke/deployevents/installer/functions.bash @@ -0,0 +1,86 @@ +#!/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 + local cluster_name + cluster_name=$(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 + else + env_id=$(echo "$cluster_name" | cut -d'_' -f2) + 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'" +} diff --git a/datasources/linux/kubernetes/gke/deployevents/installer/installer.bash b/datasources/linux/kubernetes/gke/deployevents/installer/installer.bash new file mode 100755 index 000000000..8999e1b65 --- /dev/null +++ b/datasources/linux/kubernetes/gke/deployevents/installer/installer.bash @@ -0,0 +1,30 @@ +#!/bin/bash + +################################################################################################################################# +############################################## LINUX Datasource Installer Script ################################################ +################################################################################################################################# + +# Print title +echo +echo -e '########################################' +echo -e "###$PURPLE_COLOR Deploy Events 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 diff --git a/datasources/linux/kubernetes/gke/deployevents/prerequisites/functions.bash b/datasources/linux/kubernetes/gke/deployevents/prerequisites/functions.bash new file mode 100755 index 000000000..7229d31f7 --- /dev/null +++ b/datasources/linux/kubernetes/gke/deployevents/prerequisites/functions.bash @@ -0,0 +1,5 @@ +#!/bin/bash + +################################################################################################################################# +########################################## LINUX Datasource Prerequisites Functions ############################################# +################################################################################################################################# diff --git a/datasources/linux/kubernetes/gke/deployevents/prerequisites/prerequisites.bash b/datasources/linux/kubernetes/gke/deployevents/prerequisites/prerequisites.bash new file mode 100644 index 000000000..4269857ef --- /dev/null +++ b/datasources/linux/kubernetes/gke/deployevents/prerequisites/prerequisites.bash @@ -0,0 +1,5 @@ +#!/bin/bash + +################################################################################################################################# +############################################ LINUX Datasource Prerequisites Script ############################################## +################################################################################################################################# diff --git a/datasources/linux/kubernetes/gke/deployevents/telemetry/logs/functions.bash b/datasources/linux/kubernetes/gke/deployevents/telemetry/logs/functions.bash new file mode 100755 index 000000000..9cc5b4176 --- /dev/null +++ b/datasources/linux/kubernetes/gke/deployevents/telemetry/logs/functions.bash @@ -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++)) +} diff --git a/datasources/linux/kubernetes/gke/deployevents/telemetry/logs/logs.bash b/datasources/linux/kubernetes/gke/deployevents/telemetry/logs/logs.bash new file mode 100755 index 000000000..983d6318f --- /dev/null +++ b/datasources/linux/kubernetes/gke/deployevents/telemetry/logs/logs.bash @@ -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" diff --git a/datasources/mac/kubernetes/aks/deployevents/installer/functions.bash b/datasources/mac/kubernetes/aks/deployevents/installer/functions.bash new file mode 100755 index 000000000..5903bf8f7 --- /dev/null +++ b/datasources/mac/kubernetes/aks/deployevents/installer/functions.bash @@ -0,0 +1,83 @@ +#!/bin/bash + +################################################################################################################################# +############################################# MAC 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_MAC_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_MAC_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'" +} diff --git a/datasources/mac/kubernetes/aks/deployevents/installer/installer.bash b/datasources/mac/kubernetes/aks/deployevents/installer/installer.bash new file mode 100755 index 000000000..b4d7f28ff --- /dev/null +++ b/datasources/mac/kubernetes/aks/deployevents/installer/installer.bash @@ -0,0 +1,30 @@ +#!/bin/bash + +################################################################################################################################# +############################################### MAC 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 diff --git a/datasources/mac/kubernetes/aks/deployevents/prerequisites/functions.bash b/datasources/mac/kubernetes/aks/deployevents/prerequisites/functions.bash new file mode 100755 index 000000000..ef1d48bd8 --- /dev/null +++ b/datasources/mac/kubernetes/aks/deployevents/prerequisites/functions.bash @@ -0,0 +1,5 @@ +#!/bin/bash + +################################################################################################################################# +########################################### MAC Datasource Prerequisites Functions ############################################## +################################################################################################################################# diff --git a/datasources/mac/kubernetes/aks/deployevents/prerequisites/prerequisites.bash b/datasources/mac/kubernetes/aks/deployevents/prerequisites/prerequisites.bash new file mode 100644 index 000000000..5ee978f21 --- /dev/null +++ b/datasources/mac/kubernetes/aks/deployevents/prerequisites/prerequisites.bash @@ -0,0 +1,5 @@ +#!/bin/bash + +################################################################################################################################# +############################################# MAC Datasource Prerequisites Script ############################################### +################################################################################################################################# diff --git a/datasources/mac/kubernetes/aks/deployevents/telemetry/logs/functions.bash b/datasources/mac/kubernetes/aks/deployevents/telemetry/logs/functions.bash new file mode 100755 index 000000000..3a7e56b02 --- /dev/null +++ b/datasources/mac/kubernetes/aks/deployevents/telemetry/logs/functions.bash @@ -0,0 +1,42 @@ +#!/bin/bash + +################################################################################################################################# +############################################### MAC 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_MAC_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_MAC_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++)) +} diff --git a/datasources/mac/kubernetes/aks/deployevents/telemetry/logs/logs.bash b/datasources/mac/kubernetes/aks/deployevents/telemetry/logs/logs.bash new file mode 100755 index 000000000..983d6318f --- /dev/null +++ b/datasources/mac/kubernetes/aks/deployevents/telemetry/logs/logs.bash @@ -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" diff --git a/datasources/mac/kubernetes/digitalocean/deployevents/installer/functions.bash b/datasources/mac/kubernetes/digitalocean/deployevents/installer/functions.bash new file mode 100755 index 000000000..5903bf8f7 --- /dev/null +++ b/datasources/mac/kubernetes/digitalocean/deployevents/installer/functions.bash @@ -0,0 +1,83 @@ +#!/bin/bash + +################################################################################################################################# +############################################# MAC 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_MAC_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_MAC_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'" +} diff --git a/datasources/mac/kubernetes/digitalocean/deployevents/installer/installer.bash b/datasources/mac/kubernetes/digitalocean/deployevents/installer/installer.bash new file mode 100755 index 000000000..6c4bd1273 --- /dev/null +++ b/datasources/mac/kubernetes/digitalocean/deployevents/installer/installer.bash @@ -0,0 +1,30 @@ +#!/bin/bash + +################################################################################################################################# +############################################### MAC Datasource Installer Script ################################################# +################################################################################################################################# + +# Print title +echo +echo -e '########################################' +echo -e "###$PURPLE_COLOR Deploy Events 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 diff --git a/datasources/mac/kubernetes/digitalocean/deployevents/prerequisites/functions.bash b/datasources/mac/kubernetes/digitalocean/deployevents/prerequisites/functions.bash new file mode 100755 index 000000000..ef1d48bd8 --- /dev/null +++ b/datasources/mac/kubernetes/digitalocean/deployevents/prerequisites/functions.bash @@ -0,0 +1,5 @@ +#!/bin/bash + +################################################################################################################################# +########################################### MAC Datasource Prerequisites Functions ############################################## +################################################################################################################################# diff --git a/datasources/mac/kubernetes/digitalocean/deployevents/prerequisites/prerequisites.bash b/datasources/mac/kubernetes/digitalocean/deployevents/prerequisites/prerequisites.bash new file mode 100644 index 000000000..5ee978f21 --- /dev/null +++ b/datasources/mac/kubernetes/digitalocean/deployevents/prerequisites/prerequisites.bash @@ -0,0 +1,5 @@ +#!/bin/bash + +################################################################################################################################# +############################################# MAC Datasource Prerequisites Script ############################################### +################################################################################################################################# diff --git a/datasources/mac/kubernetes/digitalocean/deployevents/telemetry/logs/functions.bash b/datasources/mac/kubernetes/digitalocean/deployevents/telemetry/logs/functions.bash new file mode 100755 index 000000000..3a7e56b02 --- /dev/null +++ b/datasources/mac/kubernetes/digitalocean/deployevents/telemetry/logs/functions.bash @@ -0,0 +1,42 @@ +#!/bin/bash + +################################################################################################################################# +############################################### MAC 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_MAC_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_MAC_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++)) +} diff --git a/datasources/mac/kubernetes/digitalocean/deployevents/telemetry/logs/logs.bash b/datasources/mac/kubernetes/digitalocean/deployevents/telemetry/logs/logs.bash new file mode 100755 index 000000000..01ace77ff --- /dev/null +++ b/datasources/mac/kubernetes/digitalocean/deployevents/telemetry/logs/logs.bash @@ -0,0 +1,27 @@ +#!/bin/bash + +################################################################################################################################# +################################################ MAC 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" diff --git a/datasources/mac/kubernetes/eks/deployevents/installer/functions.bash b/datasources/mac/kubernetes/eks/deployevents/installer/functions.bash new file mode 100755 index 000000000..748c8e6a3 --- /dev/null +++ b/datasources/mac/kubernetes/eks/deployevents/installer/functions.bash @@ -0,0 +1,86 @@ +#!/bin/bash + +################################################################################################################################# +############################################# MAC 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_MAC_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_MAC_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 + local cluster_name + cluster_name=$(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 + else + env_id=$(echo "$cluster_name" | cut -d'/' -f2) + 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'" +} diff --git a/datasources/mac/kubernetes/eks/deployevents/installer/installer.bash b/datasources/mac/kubernetes/eks/deployevents/installer/installer.bash new file mode 100755 index 000000000..6c4bd1273 --- /dev/null +++ b/datasources/mac/kubernetes/eks/deployevents/installer/installer.bash @@ -0,0 +1,30 @@ +#!/bin/bash + +################################################################################################################################# +############################################### MAC Datasource Installer Script ################################################# +################################################################################################################################# + +# Print title +echo +echo -e '########################################' +echo -e "###$PURPLE_COLOR Deploy Events 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 diff --git a/datasources/mac/kubernetes/eks/deployevents/prerequisites/functions.bash b/datasources/mac/kubernetes/eks/deployevents/prerequisites/functions.bash new file mode 100755 index 000000000..ef1d48bd8 --- /dev/null +++ b/datasources/mac/kubernetes/eks/deployevents/prerequisites/functions.bash @@ -0,0 +1,5 @@ +#!/bin/bash + +################################################################################################################################# +########################################### MAC Datasource Prerequisites Functions ############################################## +################################################################################################################################# diff --git a/datasources/mac/kubernetes/eks/deployevents/prerequisites/prerequisites.bash b/datasources/mac/kubernetes/eks/deployevents/prerequisites/prerequisites.bash new file mode 100644 index 000000000..5ee978f21 --- /dev/null +++ b/datasources/mac/kubernetes/eks/deployevents/prerequisites/prerequisites.bash @@ -0,0 +1,5 @@ +#!/bin/bash + +################################################################################################################################# +############################################# MAC Datasource Prerequisites Script ############################################### +################################################################################################################################# diff --git a/datasources/mac/kubernetes/eks/deployevents/telemetry/logs/functions.bash b/datasources/mac/kubernetes/eks/deployevents/telemetry/logs/functions.bash new file mode 100755 index 000000000..3a7e56b02 --- /dev/null +++ b/datasources/mac/kubernetes/eks/deployevents/telemetry/logs/functions.bash @@ -0,0 +1,42 @@ +#!/bin/bash + +################################################################################################################################# +############################################### MAC 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_MAC_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_MAC_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++)) +} diff --git a/datasources/mac/kubernetes/eks/deployevents/telemetry/logs/logs.bash b/datasources/mac/kubernetes/eks/deployevents/telemetry/logs/logs.bash new file mode 100755 index 000000000..01ace77ff --- /dev/null +++ b/datasources/mac/kubernetes/eks/deployevents/telemetry/logs/logs.bash @@ -0,0 +1,27 @@ +#!/bin/bash + +################################################################################################################################# +################################################ MAC 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" diff --git a/datasources/mac/kubernetes/gke/deployevents/installer/functions.bash b/datasources/mac/kubernetes/gke/deployevents/installer/functions.bash new file mode 100755 index 000000000..fb165c554 --- /dev/null +++ b/datasources/mac/kubernetes/gke/deployevents/installer/functions.bash @@ -0,0 +1,86 @@ +#!/bin/bash + +################################################################################################################################# +############################################# MAC 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_MAC_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_MAC_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 + local cluster_name + cluster_name=$(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 + else + env_id=$(echo "$cluster_name" | cut -d'_' -f2) + 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'" +} diff --git a/datasources/mac/kubernetes/gke/deployevents/installer/installer.bash b/datasources/mac/kubernetes/gke/deployevents/installer/installer.bash new file mode 100755 index 000000000..6c4bd1273 --- /dev/null +++ b/datasources/mac/kubernetes/gke/deployevents/installer/installer.bash @@ -0,0 +1,30 @@ +#!/bin/bash + +################################################################################################################################# +############################################### MAC Datasource Installer Script ################################################# +################################################################################################################################# + +# Print title +echo +echo -e '########################################' +echo -e "###$PURPLE_COLOR Deploy Events 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 diff --git a/datasources/mac/kubernetes/gke/deployevents/prerequisites/functions.bash b/datasources/mac/kubernetes/gke/deployevents/prerequisites/functions.bash new file mode 100755 index 000000000..ef1d48bd8 --- /dev/null +++ b/datasources/mac/kubernetes/gke/deployevents/prerequisites/functions.bash @@ -0,0 +1,5 @@ +#!/bin/bash + +################################################################################################################################# +########################################### MAC Datasource Prerequisites Functions ############################################## +################################################################################################################################# diff --git a/datasources/mac/kubernetes/gke/deployevents/prerequisites/prerequisites.bash b/datasources/mac/kubernetes/gke/deployevents/prerequisites/prerequisites.bash new file mode 100644 index 000000000..5ee978f21 --- /dev/null +++ b/datasources/mac/kubernetes/gke/deployevents/prerequisites/prerequisites.bash @@ -0,0 +1,5 @@ +#!/bin/bash + +################################################################################################################################# +############################################# MAC Datasource Prerequisites Script ############################################### +################################################################################################################################# diff --git a/datasources/mac/kubernetes/gke/deployevents/telemetry/logs/functions.bash b/datasources/mac/kubernetes/gke/deployevents/telemetry/logs/functions.bash new file mode 100755 index 000000000..3a7e56b02 --- /dev/null +++ b/datasources/mac/kubernetes/gke/deployevents/telemetry/logs/functions.bash @@ -0,0 +1,42 @@ +#!/bin/bash + +################################################################################################################################# +############################################### MAC 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_MAC_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_MAC_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++)) +} diff --git a/datasources/mac/kubernetes/gke/deployevents/telemetry/logs/logs.bash b/datasources/mac/kubernetes/gke/deployevents/telemetry/logs/logs.bash new file mode 100755 index 000000000..01ace77ff --- /dev/null +++ b/datasources/mac/kubernetes/gke/deployevents/telemetry/logs/logs.bash @@ -0,0 +1,27 @@ +#!/bin/bash + +################################################################################################################################# +################################################ MAC 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" diff --git a/datasources/windows/kubernetes/aks/deployevents/installer/functions.ps1 b/datasources/windows/kubernetes/aks/deployevents/installer/functions.ps1 new file mode 100755 index 000000000..b52a03570 --- /dev/null +++ b/datasources/windows/kubernetes/aks/deployevents/installer/functions.ps1 @@ -0,0 +1,229 @@ +################################################################################################################################# +################################################# WINDOWS Installer Functions ################################################### +################################################################################################################################# + +# Gets the selected products (logs/metrics/traces) +# Input: +# --- +# Output: +# IsLogsOptionSelected - Tells if logs option was selected (true/false) +# LogsTelemetry - The logs telemetry if logs option was selected +# LogsParams - The logs params if logs option was selected +# IsMetricsOptionSelected - Tells if metrics option was selected (true/false) +# MetricsTelemetry - The metrics telemetry if metrics option was selected +# MetricsParams - The metrics params if metrics option was selected +# IsTracesOptionSelected - Tells if traces option was selected (true/false) +# TracesTelemetry - The traces telemetry if traces option was selected +# TracesParams - The traces params if traces option was selected +function Get-SelectedProducts { + $local:ExitCode = 1 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting the selected products ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:DataSourceIndex = 0 + foreach ($DataSource in $script:DataSources) { + if ($Datasource.Equals($script:CurrentDataSource)) { + break + } + + $DataSourceIndex++ + } + + $local:Err = Get-JsonFileFieldValueList $script:AgentJson ".configuration.subtypes[0].datasources[$DataSourceIndex].telemetries[]" + if ($Err.Count -ne 0) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:Telemetries = $script:JsonValue + + $local:IsLogsOptionSelected = $false + $local:IsMetricsOptionSelected = $false + $local:IsTracesOptionSelected = $false + + $local:TelemetryIndex = 0 + foreach ($Telemetry in $Telemetries) { + $Err = Get-JsonStrFieldValue $Telemetry '.type' + if ($Err.Count -ne 0) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:Type = $script:JsonValue + $local:Params = $null + + $Err = Get-JsonStrFieldValueList $Telemetry '.params[]' + if ($Err.Count -ne 0 -and $Err[1] -ne 2) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + if ($Err.Count -ne 0) { + $Params = '' + } + else { + $Params = $script:JsonValue + } + + $local:ParamsStr = Convert-ListToStr $Params + + if ($Type.Equals('LOG_ANALYTICS')) { + $Message = 'Logs option was selected' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Logs telemetry is '$Telemetry'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Logs params are '$Params'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $IsLogsOptionSelected = $true + Write-TaskPostRun "`$script:LogsTelemetry = '$Telemetry'" + Write-TaskPostRun "`$script:LogsParams = $ParamsStr" + } + elseif ($Type.Equals('METRICS')) { + $Message = 'Metrics option was selected' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Metrics telemetry is '$Telemetry'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Metrics params are '$Params'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $IsMetricsOptionSelected = $true + Write-TaskPostRun "`$script:MetricsTelemetry = '$Telemetry'" + Write-TaskPostRun "`$script:MetricsParams = $ParamsStr" + } + elseif ($Type.Equals('TRACING')) { + $Message = 'Traces option was selected' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Traces telemetry is '$Telemetry'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Traces params are '$Params'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $IsTracesOptionSelected = $true + Write-TaskPostRun "`$script:TracesTelemetry = '$Telemetry'" + Write-TaskPostRun "`$script:TracesParams = $ParamsStr" + } + + $TelemetryIndex++ + } + + Write-TaskPostRun "`$script:IsLogsOptionSelected = `$$IsLogsOptionSelected" + Write-TaskPostRun "`$script:IsMetricsOptionSelected = `$$IsMetricsOptionSelected" + Write-TaskPostRun "`$script:IsTracesOptionSelected = `$$IsTracesOptionSelected" +} + +# Gets general params (params under datasource) +# Input: +# --- +# Output: +# GeneralParams - The params under datasource +function Get-GeneralParams { + $local:ExitCode = 2 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting general params ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:DataSourceIndex = 0 + foreach ($DataSource in $script:DataSources) { + if ($Datasource.Equals($script:CurrentDataSource)) { + break + } + + $DataSourceIndex++ + } + + $local:Err = Get-JsonFileFieldValueList $script:AgentJson ".configuration.subtypes[0].datasources[$DataSourceIndex].params[]" + if ($Err.Count -ne 0) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:Params = $script:JsonValue + + $Message = "General params are '$Params'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:ParamsStr = Convert-ListToStr $Params + + Write-TaskPostRun "`$script:GeneralParams = $ParamsStr" +} + +# Gets environment id +# Input: +# FuncArgs - Hashtable {GeneralParams = $script:GeneralParams; DefaultEnvId = $script:DefaultEnvId} +# Output: +# EnvId - The environment id +function Get-EnvironmentID { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 4 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting environment id ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('GeneralParams', 'DefaultEnvId') + if ($Err.Count -ne 0) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:GeneralParams = $FuncArgs.GeneralParams + $local:DefaultEnvId = $FuncArgs.DefaultEnvId + + $Err = Get-ParamValue $GeneralParams 'envID' + if ($Err.Count -ne 0) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:EnvId = $script:ParamValue + + if ([string]::IsNullOrEmpty($EnvId)) { + $EnvId = kubectl config current-context 2>$Null + if ($LASTEXITCODE -ne 0) { + $EnvId = $DefaultEnvId + } + } + + $Message = "Environment id is '$EnvId'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:EnvId = '$EnvId'" +} diff --git a/datasources/windows/kubernetes/aks/deployevents/installer/installer.ps1 b/datasources/windows/kubernetes/aks/deployevents/installer/installer.ps1 new file mode 100755 index 000000000..c69b0ca19 --- /dev/null +++ b/datasources/windows/kubernetes/aks/deployevents/installer/installer.ps1 @@ -0,0 +1,55 @@ +################################################################################################################################# +################################################### WINDOWS Installer Script #################################################### +################################################################################################################################# + +# Runs logs script +# Input: +# --- +# Output: +# --- +function Invoke-Logs { + $local:ExitCode = 8 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = "Running $CurrentDataSource datasource logs script ..." + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + try { + . "$script:LogzioTempDir\$script:Platform\$script:SubType\$($script:CurrentDataSource.ToLower())\$script:LogsFile" -ErrorAction Stop + if ($LASTEXITCODE -ne 0) { + Exit $LASTEXITCODE + } + } + catch { + $local:Message = "installer.ps1 ($ExitCode): error running $CurrentDataSource datasource logs script: $_" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Error $Message + + $script:IsAgentFailed = $true + Exit $ExitCode + } +} + + +$local:InstallerFunctionsScript = "$script:LogzioTempDir\$script:Platform\$script:SubType\$($script:CurrentDataSource.ToLower())\$script:InstallerFunctionsFile" + +# Print title +Write-Host +Write-Host '##########################################' +Write-Host '### ' -NoNewline +Write-Host 'Security Datasource Installation' -ForegroundColor Magenta -NoNewline +Write-Host ' ###' +Write-Host '##########################################' + +# Get the selected products +Invoke-Task 'Get-SelectedProducts' @{} 'Getting the selected products' @($InstallerFunctionsScript) +# Get general params +Invoke-Task 'Get-GeneralParams' @{} 'Getting general params' @($InstallerFunctionsScript) +# Get environment id +Invoke-Task 'Get-EnvironmentID' @{GeneralParams = $script:GeneralParams; DefaultEnvId = $script:DefaultEnvId} 'Getting environment id' @($InstallerFunctionsScript) +# Run logs script +Invoke-Logs + +# Finished successfully +Exit 0 diff --git a/datasources/windows/kubernetes/aks/deployevents/prerequisites/functions.ps1 b/datasources/windows/kubernetes/aks/deployevents/prerequisites/functions.ps1 new file mode 100755 index 000000000..95845e48b --- /dev/null +++ b/datasources/windows/kubernetes/aks/deployevents/prerequisites/functions.ps1 @@ -0,0 +1,3 @@ +################################################################################################################################# +############################################### WINDOWS Prerequisites Functions ################################################# +################################################################################################################################# diff --git a/datasources/windows/kubernetes/aks/deployevents/prerequisites/prerequisites.ps1 b/datasources/windows/kubernetes/aks/deployevents/prerequisites/prerequisites.ps1 new file mode 100644 index 000000000..a532fb1a5 --- /dev/null +++ b/datasources/windows/kubernetes/aks/deployevents/prerequisites/prerequisites.ps1 @@ -0,0 +1,6 @@ +################################################################################################################################# +################################################# WINDOWS Prerequisites Script ################################################## +################################################################################################################################# + +# Finished successfully +Exit 0 diff --git a/datasources/windows/kubernetes/aks/deployevents/telemetry/logs/functions.ps1 b/datasources/windows/kubernetes/aks/deployevents/telemetry/logs/functions.ps1 new file mode 100755 index 000000000..257cff67a --- /dev/null +++ b/datasources/windows/kubernetes/aks/deployevents/telemetry/logs/functions.ps1 @@ -0,0 +1,182 @@ +################################################################################################################################# +################################################### WINDOWS Logs Functions ###################################################### +################################################################################################################################# + +# Gets Logz.io logs token +# Input: +# --- +# Output: +# LogsToken - Logz.io logs token +function Get-LogzioLogsToken { + $local:ExitCode = 1 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting Logz.io logs token ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Get-JsonFileFieldValue $script:AgentJson '.shippingTokens.LOG_ANALYTICS' + if ($Err.Count -ne 0) { + $Message = "logs.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:ShippingToken = $script:JsonValue + + $Message = "Logz.io logs token is '$ShippingToken'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogsToken = '$ShippingToken'" +} + +# Builds enable deploy events Helm set +# Input: +# --- +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# helmSets - Contains all the Helm sets +function Build-EnableDeployEventsHelmSet { + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building enable deploy events Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:HelmSet = " --set deployEvents.enabled=true" + + $Message = "Enable deploy events Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} + +# Builds Logz.io deploy events logs listener url Helm set +# Input: +# FuncArgs - Hashtable {ListenerUrl = $script:ListenerUrl} +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# HelmSets - Contains all the Helm sets +function Build-LogzioDeployEventsLogsListenerUrlHelmSet { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 6 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building Logz.io deploy events logs listener URL Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('ListenerUrl') + if ($Err.Count -ne 0) { + $Message = "logs.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:ListenerUrl = $FuncArgs.ListenerUrl + + $local:HelmSet = " --set logzio-k8s-events.secrets.logzioListener=$ListenerUrl" + + $Message = "Logz.io deploy events logs listener url Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} + +# Builds Logz.io deploy events logs token Helm set +# Input: +# FuncArgs - Hashtable {LogsToken = $script:LogsToken} +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# helmSets - Contains all the Helm sets +function Build-LogzioDeployEventsLogsTokenHelmSet { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 7 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building Logz.io deploy events logs token Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('LogsToken') + if ($Err.Count -ne 0) { + $Message = "logs.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:LogsToken = $FuncArgs.LogsToken + + $local:HelmSet = " --set logzio-k8s-events.secrets.logzioShippingToken=$LogsToken" + + $Message = "Logz.io deploy events logs token Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} + +# Builds Deploy events environment id Helm set +# Input: +# FuncArgs - Hashtable {EnvId = $script:EnvId} +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# helmSets - Contains all the Helm sets +function Build-DeployEventsEnvironmentIdHelmSet { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 8 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building deploy events environment id Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('EnvId') + if ($Err.Count -ne 0) { + $Message = "logs.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:EnvId = $FuncArgs.EnvId + + if ([string]::IsNullOrEmpty($EnvId)) { + $Message = 'Environment id is empty. Default value will be used' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + return + } + + $local:HelmSet = " --set logzio-k8s-events.secrets.env_id=$EnvId" + + $Message = "Deploy events Environment id Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} diff --git a/datasources/windows/kubernetes/aks/deployevents/telemetry/logs/logs.ps1 b/datasources/windows/kubernetes/aks/deployevents/telemetry/logs/logs.ps1 new file mode 100755 index 000000000..b212d5482 --- /dev/null +++ b/datasources/windows/kubernetes/aks/deployevents/telemetry/logs/logs.ps1 @@ -0,0 +1,27 @@ +################################################################################################################################# +##################################################### WINDOWS Logs Script ####################################################### +################################################################################################################################# + +$local:LogsFunctionsScript = "$script:LogzioTempDir\$script:Platform\$script:SubType\$($script:CurrentDataSource.ToLower())\$script:LogsFunctionsFile" + +# Print headline +Write-Host +Write-Host '############' +Write-Host '### ' -NoNewline +Write-Host 'Logs' -ForegroundColor Magenta -NoNewline +Write-Host ' ###' +Write-Host '############' + +# Get Logz.io logs token +Invoke-Task 'Get-LogzioLogsToken' @{} 'Getting Logz.io logs token' @($LogsFunctionsScript) +# Build enable security report Helm set +Invoke-Task 'Build-EnableDeployEventsHelmSet' @{} 'Building enable security report Helm set' @($LogsFunctionsScript) +# Build Logz.io Deploy events logs listener url Helm set +Invoke-Task 'Build-LogzioDeployEventsLogsListenerUrlHelmSet' @{ListenerUrl = $script:ListenerUrl} 'Building Logz.io deploy events logs listener url Helm set' @($LogsFunctionsScript) +# Build Logz.io Deploy events logs token Helm set +Invoke-Task 'Build-LogzioDeployEventsLogsTokenHelmSet' @{LogsToken = $script:LogsToken} 'Building Logz.io deploy events logs token Helm set' @($LogsFunctionsScript) +# Build Deploy events environment id Helm set +Invoke-Task 'Build-DeployEventsEnvironmentIdHelmSet' @{EnvId = $script:EnvId} 'Building Deploy events environment id Helm set' @($LogsFunctionsScript) + +# Finished successfully +Exit 0 diff --git a/datasources/windows/kubernetes/digitalocean/deployevents/installer/functions.ps1 b/datasources/windows/kubernetes/digitalocean/deployevents/installer/functions.ps1 new file mode 100755 index 000000000..b52a03570 --- /dev/null +++ b/datasources/windows/kubernetes/digitalocean/deployevents/installer/functions.ps1 @@ -0,0 +1,229 @@ +################################################################################################################################# +################################################# WINDOWS Installer Functions ################################################### +################################################################################################################################# + +# Gets the selected products (logs/metrics/traces) +# Input: +# --- +# Output: +# IsLogsOptionSelected - Tells if logs option was selected (true/false) +# LogsTelemetry - The logs telemetry if logs option was selected +# LogsParams - The logs params if logs option was selected +# IsMetricsOptionSelected - Tells if metrics option was selected (true/false) +# MetricsTelemetry - The metrics telemetry if metrics option was selected +# MetricsParams - The metrics params if metrics option was selected +# IsTracesOptionSelected - Tells if traces option was selected (true/false) +# TracesTelemetry - The traces telemetry if traces option was selected +# TracesParams - The traces params if traces option was selected +function Get-SelectedProducts { + $local:ExitCode = 1 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting the selected products ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:DataSourceIndex = 0 + foreach ($DataSource in $script:DataSources) { + if ($Datasource.Equals($script:CurrentDataSource)) { + break + } + + $DataSourceIndex++ + } + + $local:Err = Get-JsonFileFieldValueList $script:AgentJson ".configuration.subtypes[0].datasources[$DataSourceIndex].telemetries[]" + if ($Err.Count -ne 0) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:Telemetries = $script:JsonValue + + $local:IsLogsOptionSelected = $false + $local:IsMetricsOptionSelected = $false + $local:IsTracesOptionSelected = $false + + $local:TelemetryIndex = 0 + foreach ($Telemetry in $Telemetries) { + $Err = Get-JsonStrFieldValue $Telemetry '.type' + if ($Err.Count -ne 0) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:Type = $script:JsonValue + $local:Params = $null + + $Err = Get-JsonStrFieldValueList $Telemetry '.params[]' + if ($Err.Count -ne 0 -and $Err[1] -ne 2) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + if ($Err.Count -ne 0) { + $Params = '' + } + else { + $Params = $script:JsonValue + } + + $local:ParamsStr = Convert-ListToStr $Params + + if ($Type.Equals('LOG_ANALYTICS')) { + $Message = 'Logs option was selected' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Logs telemetry is '$Telemetry'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Logs params are '$Params'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $IsLogsOptionSelected = $true + Write-TaskPostRun "`$script:LogsTelemetry = '$Telemetry'" + Write-TaskPostRun "`$script:LogsParams = $ParamsStr" + } + elseif ($Type.Equals('METRICS')) { + $Message = 'Metrics option was selected' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Metrics telemetry is '$Telemetry'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Metrics params are '$Params'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $IsMetricsOptionSelected = $true + Write-TaskPostRun "`$script:MetricsTelemetry = '$Telemetry'" + Write-TaskPostRun "`$script:MetricsParams = $ParamsStr" + } + elseif ($Type.Equals('TRACING')) { + $Message = 'Traces option was selected' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Traces telemetry is '$Telemetry'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Traces params are '$Params'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $IsTracesOptionSelected = $true + Write-TaskPostRun "`$script:TracesTelemetry = '$Telemetry'" + Write-TaskPostRun "`$script:TracesParams = $ParamsStr" + } + + $TelemetryIndex++ + } + + Write-TaskPostRun "`$script:IsLogsOptionSelected = `$$IsLogsOptionSelected" + Write-TaskPostRun "`$script:IsMetricsOptionSelected = `$$IsMetricsOptionSelected" + Write-TaskPostRun "`$script:IsTracesOptionSelected = `$$IsTracesOptionSelected" +} + +# Gets general params (params under datasource) +# Input: +# --- +# Output: +# GeneralParams - The params under datasource +function Get-GeneralParams { + $local:ExitCode = 2 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting general params ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:DataSourceIndex = 0 + foreach ($DataSource in $script:DataSources) { + if ($Datasource.Equals($script:CurrentDataSource)) { + break + } + + $DataSourceIndex++ + } + + $local:Err = Get-JsonFileFieldValueList $script:AgentJson ".configuration.subtypes[0].datasources[$DataSourceIndex].params[]" + if ($Err.Count -ne 0) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:Params = $script:JsonValue + + $Message = "General params are '$Params'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:ParamsStr = Convert-ListToStr $Params + + Write-TaskPostRun "`$script:GeneralParams = $ParamsStr" +} + +# Gets environment id +# Input: +# FuncArgs - Hashtable {GeneralParams = $script:GeneralParams; DefaultEnvId = $script:DefaultEnvId} +# Output: +# EnvId - The environment id +function Get-EnvironmentID { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 4 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting environment id ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('GeneralParams', 'DefaultEnvId') + if ($Err.Count -ne 0) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:GeneralParams = $FuncArgs.GeneralParams + $local:DefaultEnvId = $FuncArgs.DefaultEnvId + + $Err = Get-ParamValue $GeneralParams 'envID' + if ($Err.Count -ne 0) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:EnvId = $script:ParamValue + + if ([string]::IsNullOrEmpty($EnvId)) { + $EnvId = kubectl config current-context 2>$Null + if ($LASTEXITCODE -ne 0) { + $EnvId = $DefaultEnvId + } + } + + $Message = "Environment id is '$EnvId'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:EnvId = '$EnvId'" +} diff --git a/datasources/windows/kubernetes/digitalocean/deployevents/installer/installer.ps1 b/datasources/windows/kubernetes/digitalocean/deployevents/installer/installer.ps1 new file mode 100755 index 000000000..c69b0ca19 --- /dev/null +++ b/datasources/windows/kubernetes/digitalocean/deployevents/installer/installer.ps1 @@ -0,0 +1,55 @@ +################################################################################################################################# +################################################### WINDOWS Installer Script #################################################### +################################################################################################################################# + +# Runs logs script +# Input: +# --- +# Output: +# --- +function Invoke-Logs { + $local:ExitCode = 8 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = "Running $CurrentDataSource datasource logs script ..." + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + try { + . "$script:LogzioTempDir\$script:Platform\$script:SubType\$($script:CurrentDataSource.ToLower())\$script:LogsFile" -ErrorAction Stop + if ($LASTEXITCODE -ne 0) { + Exit $LASTEXITCODE + } + } + catch { + $local:Message = "installer.ps1 ($ExitCode): error running $CurrentDataSource datasource logs script: $_" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Error $Message + + $script:IsAgentFailed = $true + Exit $ExitCode + } +} + + +$local:InstallerFunctionsScript = "$script:LogzioTempDir\$script:Platform\$script:SubType\$($script:CurrentDataSource.ToLower())\$script:InstallerFunctionsFile" + +# Print title +Write-Host +Write-Host '##########################################' +Write-Host '### ' -NoNewline +Write-Host 'Security Datasource Installation' -ForegroundColor Magenta -NoNewline +Write-Host ' ###' +Write-Host '##########################################' + +# Get the selected products +Invoke-Task 'Get-SelectedProducts' @{} 'Getting the selected products' @($InstallerFunctionsScript) +# Get general params +Invoke-Task 'Get-GeneralParams' @{} 'Getting general params' @($InstallerFunctionsScript) +# Get environment id +Invoke-Task 'Get-EnvironmentID' @{GeneralParams = $script:GeneralParams; DefaultEnvId = $script:DefaultEnvId} 'Getting environment id' @($InstallerFunctionsScript) +# Run logs script +Invoke-Logs + +# Finished successfully +Exit 0 diff --git a/datasources/windows/kubernetes/digitalocean/deployevents/prerequisites/functions.ps1 b/datasources/windows/kubernetes/digitalocean/deployevents/prerequisites/functions.ps1 new file mode 100755 index 000000000..95845e48b --- /dev/null +++ b/datasources/windows/kubernetes/digitalocean/deployevents/prerequisites/functions.ps1 @@ -0,0 +1,3 @@ +################################################################################################################################# +############################################### WINDOWS Prerequisites Functions ################################################# +################################################################################################################################# diff --git a/datasources/windows/kubernetes/digitalocean/deployevents/prerequisites/prerequisites.ps1 b/datasources/windows/kubernetes/digitalocean/deployevents/prerequisites/prerequisites.ps1 new file mode 100644 index 000000000..a532fb1a5 --- /dev/null +++ b/datasources/windows/kubernetes/digitalocean/deployevents/prerequisites/prerequisites.ps1 @@ -0,0 +1,6 @@ +################################################################################################################################# +################################################# WINDOWS Prerequisites Script ################################################## +################################################################################################################################# + +# Finished successfully +Exit 0 diff --git a/datasources/windows/kubernetes/digitalocean/deployevents/telemetry/logs/functions.ps1 b/datasources/windows/kubernetes/digitalocean/deployevents/telemetry/logs/functions.ps1 new file mode 100755 index 000000000..257cff67a --- /dev/null +++ b/datasources/windows/kubernetes/digitalocean/deployevents/telemetry/logs/functions.ps1 @@ -0,0 +1,182 @@ +################################################################################################################################# +################################################### WINDOWS Logs Functions ###################################################### +################################################################################################################################# + +# Gets Logz.io logs token +# Input: +# --- +# Output: +# LogsToken - Logz.io logs token +function Get-LogzioLogsToken { + $local:ExitCode = 1 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting Logz.io logs token ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Get-JsonFileFieldValue $script:AgentJson '.shippingTokens.LOG_ANALYTICS' + if ($Err.Count -ne 0) { + $Message = "logs.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:ShippingToken = $script:JsonValue + + $Message = "Logz.io logs token is '$ShippingToken'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogsToken = '$ShippingToken'" +} + +# Builds enable deploy events Helm set +# Input: +# --- +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# helmSets - Contains all the Helm sets +function Build-EnableDeployEventsHelmSet { + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building enable deploy events Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:HelmSet = " --set deployEvents.enabled=true" + + $Message = "Enable deploy events Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} + +# Builds Logz.io deploy events logs listener url Helm set +# Input: +# FuncArgs - Hashtable {ListenerUrl = $script:ListenerUrl} +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# HelmSets - Contains all the Helm sets +function Build-LogzioDeployEventsLogsListenerUrlHelmSet { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 6 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building Logz.io deploy events logs listener URL Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('ListenerUrl') + if ($Err.Count -ne 0) { + $Message = "logs.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:ListenerUrl = $FuncArgs.ListenerUrl + + $local:HelmSet = " --set logzio-k8s-events.secrets.logzioListener=$ListenerUrl" + + $Message = "Logz.io deploy events logs listener url Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} + +# Builds Logz.io deploy events logs token Helm set +# Input: +# FuncArgs - Hashtable {LogsToken = $script:LogsToken} +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# helmSets - Contains all the Helm sets +function Build-LogzioDeployEventsLogsTokenHelmSet { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 7 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building Logz.io deploy events logs token Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('LogsToken') + if ($Err.Count -ne 0) { + $Message = "logs.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:LogsToken = $FuncArgs.LogsToken + + $local:HelmSet = " --set logzio-k8s-events.secrets.logzioShippingToken=$LogsToken" + + $Message = "Logz.io deploy events logs token Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} + +# Builds Deploy events environment id Helm set +# Input: +# FuncArgs - Hashtable {EnvId = $script:EnvId} +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# helmSets - Contains all the Helm sets +function Build-DeployEventsEnvironmentIdHelmSet { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 8 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building deploy events environment id Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('EnvId') + if ($Err.Count -ne 0) { + $Message = "logs.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:EnvId = $FuncArgs.EnvId + + if ([string]::IsNullOrEmpty($EnvId)) { + $Message = 'Environment id is empty. Default value will be used' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + return + } + + $local:HelmSet = " --set logzio-k8s-events.secrets.env_id=$EnvId" + + $Message = "Deploy events Environment id Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} diff --git a/datasources/windows/kubernetes/digitalocean/deployevents/telemetry/logs/logs.ps1 b/datasources/windows/kubernetes/digitalocean/deployevents/telemetry/logs/logs.ps1 new file mode 100755 index 000000000..b212d5482 --- /dev/null +++ b/datasources/windows/kubernetes/digitalocean/deployevents/telemetry/logs/logs.ps1 @@ -0,0 +1,27 @@ +################################################################################################################################# +##################################################### WINDOWS Logs Script ####################################################### +################################################################################################################################# + +$local:LogsFunctionsScript = "$script:LogzioTempDir\$script:Platform\$script:SubType\$($script:CurrentDataSource.ToLower())\$script:LogsFunctionsFile" + +# Print headline +Write-Host +Write-Host '############' +Write-Host '### ' -NoNewline +Write-Host 'Logs' -ForegroundColor Magenta -NoNewline +Write-Host ' ###' +Write-Host '############' + +# Get Logz.io logs token +Invoke-Task 'Get-LogzioLogsToken' @{} 'Getting Logz.io logs token' @($LogsFunctionsScript) +# Build enable security report Helm set +Invoke-Task 'Build-EnableDeployEventsHelmSet' @{} 'Building enable security report Helm set' @($LogsFunctionsScript) +# Build Logz.io Deploy events logs listener url Helm set +Invoke-Task 'Build-LogzioDeployEventsLogsListenerUrlHelmSet' @{ListenerUrl = $script:ListenerUrl} 'Building Logz.io deploy events logs listener url Helm set' @($LogsFunctionsScript) +# Build Logz.io Deploy events logs token Helm set +Invoke-Task 'Build-LogzioDeployEventsLogsTokenHelmSet' @{LogsToken = $script:LogsToken} 'Building Logz.io deploy events logs token Helm set' @($LogsFunctionsScript) +# Build Deploy events environment id Helm set +Invoke-Task 'Build-DeployEventsEnvironmentIdHelmSet' @{EnvId = $script:EnvId} 'Building Deploy events environment id Helm set' @($LogsFunctionsScript) + +# Finished successfully +Exit 0 diff --git a/datasources/windows/kubernetes/eks/deployevents/installer/functions.ps1 b/datasources/windows/kubernetes/eks/deployevents/installer/functions.ps1 new file mode 100755 index 000000000..147aa3713 --- /dev/null +++ b/datasources/windows/kubernetes/eks/deployevents/installer/functions.ps1 @@ -0,0 +1,231 @@ +################################################################################################################################# +################################################# WINDOWS Installer Functions ################################################### +################################################################################################################################# + +# Gets the selected products (logs/metrics/traces) +# Input: +# --- +# Output: +# IsLogsOptionSelected - Tells if logs option was selected (true/false) +# LogsTelemetry - The logs telemetry if logs option was selected +# LogsParams - The logs params if logs option was selected +# IsMetricsOptionSelected - Tells if metrics option was selected (true/false) +# MetricsTelemetry - The metrics telemetry if metrics option was selected +# MetricsParams - The metrics params if metrics option was selected +# IsTracesOptionSelected - Tells if traces option was selected (true/false) +# TracesTelemetry - The traces telemetry if traces option was selected +# TracesParams - The traces params if traces option was selected +function Get-SelectedProducts { + $local:ExitCode = 1 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting the selected products ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:DataSourceIndex = 0 + foreach ($DataSource in $script:DataSources) { + if ($Datasource.Equals($script:CurrentDataSource)) { + break + } + + $DataSourceIndex++ + } + + $local:Err = Get-JsonFileFieldValueList $script:AgentJson ".configuration.subtypes[0].datasources[$DataSourceIndex].telemetries[]" + if ($Err.Count -ne 0) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:Telemetries = $script:JsonValue + + $local:IsLogsOptionSelected = $false + $local:IsMetricsOptionSelected = $false + $local:IsTracesOptionSelected = $false + + $local:TelemetryIndex = 0 + foreach ($Telemetry in $Telemetries) { + $Err = Get-JsonStrFieldValue $Telemetry '.type' + if ($Err.Count -ne 0) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:Type = $script:JsonValue + $local:Params = $null + + $Err = Get-JsonStrFieldValueList $Telemetry '.params[]' + if ($Err.Count -ne 0 -and $Err[1] -ne 2) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + if ($Err.Count -ne 0) { + $Params = '' + } + else { + $Params = $script:JsonValue + } + + $local:ParamsStr = Convert-ListToStr $Params + + if ($Type.Equals('LOG_ANALYTICS')) { + $Message = 'Logs option was selected' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Logs telemetry is '$Telemetry'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Logs params are '$Params'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $IsLogsOptionSelected = $true + Write-TaskPostRun "`$script:LogsTelemetry = '$Telemetry'" + Write-TaskPostRun "`$script:LogsParams = $ParamsStr" + } + elseif ($Type.Equals('METRICS')) { + $Message = 'Metrics option was selected' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Metrics telemetry is '$Telemetry'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Metrics params are '$Params'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $IsMetricsOptionSelected = $true + Write-TaskPostRun "`$script:MetricsTelemetry = '$Telemetry'" + Write-TaskPostRun "`$script:MetricsParams = $ParamsStr" + } + elseif ($Type.Equals('TRACING')) { + $Message = 'Traces option was selected' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Traces telemetry is '$Telemetry'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Traces params are '$Params'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $IsTracesOptionSelected = $true + Write-TaskPostRun "`$script:TracesTelemetry = '$Telemetry'" + Write-TaskPostRun "`$script:TracesParams = $ParamsStr" + } + + $TelemetryIndex++ + } + + Write-TaskPostRun "`$script:IsLogsOptionSelected = `$$IsLogsOptionSelected" + Write-TaskPostRun "`$script:IsMetricsOptionSelected = `$$IsMetricsOptionSelected" + Write-TaskPostRun "`$script:IsTracesOptionSelected = `$$IsTracesOptionSelected" +} + +# Gets general params (params under datasource) +# Input: +# --- +# Output: +# GeneralParams - The params under datasource +function Get-GeneralParams { + $local:ExitCode = 2 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting general params ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:DataSourceIndex = 0 + foreach ($DataSource in $script:DataSources) { + if ($Datasource.Equals($script:CurrentDataSource)) { + break + } + + $DataSourceIndex++ + } + + $local:Err = Get-JsonFileFieldValueList $script:AgentJson ".configuration.subtypes[0].datasources[$DataSourceIndex].params[]" + if ($Err.Count -ne 0) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:Params = $script:JsonValue + + $Message = "General params are '$Params'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:ParamsStr = Convert-ListToStr $Params + + Write-TaskPostRun "`$script:GeneralParams = $ParamsStr" +} + +# Gets environment id +# Input: +# FuncArgs - Hashtable {GeneralParams = $script:GeneralParams; DefaultEnvId = $script:DefaultEnvId} +# Output: +# EnvId - The environment id +function Get-EnvironmentID { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 4 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting environment id ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('GeneralParams', 'DefaultEnvId') + if ($Err.Count -ne 0) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:GeneralParams = $FuncArgs.GeneralParams + $local:DefaultEnvId = $FuncArgs.DefaultEnvId + + $Err = Get-ParamValue $GeneralParams 'envID' + if ($Err.Count -ne 0) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:EnvId = $script:ParamValue + + if ([string]::IsNullOrEmpty($EnvId)) { + $local:ClusterName = kubectl config current-context 2>$Null + if ($LASTEXITCODE -ne 0) { + $EnvId = $DefaultEnvId + } else { + $EnvId = $ClusterName.Split('/')[1] + } + } + + $Message = "Environment id is '$EnvId'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:EnvId = '$EnvId'" +} diff --git a/datasources/windows/kubernetes/eks/deployevents/installer/installer.ps1 b/datasources/windows/kubernetes/eks/deployevents/installer/installer.ps1 new file mode 100755 index 000000000..4d2d33191 --- /dev/null +++ b/datasources/windows/kubernetes/eks/deployevents/installer/installer.ps1 @@ -0,0 +1,55 @@ +################################################################################################################################# +################################################### WINDOWS Installer Script #################################################### +################################################################################################################################# + +# Runs logs script +# Input: +# --- +# Output: +# --- +function Invoke-Logs { + $local:ExitCode = 8 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = "Running $CurrentDataSource datasource logs script ..." + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + try { + . "$script:LogzioTempDir\$script:Platform\$script:SubType\$($script:CurrentDataSource.ToLower())\$script:LogsFile" -ErrorAction Stop + if ($LASTEXITCODE -ne 0) { + Exit $LASTEXITCODE + } + } + catch { + $local:Message = "installer.ps1 ($ExitCode): error running $CurrentDataSource datasource logs script: $_" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Error $Message + + $script:IsAgentFailed = $true + Exit $ExitCode + } +} + + +$local:InstallerFunctionsScript = "$script:LogzioTempDir\$script:Platform\$script:SubType\$($script:CurrentDataSource.ToLower())\$script:InstallerFunctionsFile" + +# Print title +Write-Host +Write-Host '##########################################' +Write-Host '### ' -NoNewline +Write-Host 'Deploy Events Datasource Installation' -ForegroundColor Magenta -NoNewline +Write-Host ' ###' +Write-Host '##########################################' + +# Get the selected products +Invoke-Task 'Get-SelectedProducts' @{} 'Getting the selected products' @($InstallerFunctionsScript) +# Get general params +Invoke-Task 'Get-GeneralParams' @{} 'Getting general params' @($InstallerFunctionsScript) +# Get environment id +Invoke-Task 'Get-EnvironmentID' @{GeneralParams = $script:GeneralParams; DefaultEnvId = $script:DefaultEnvId} 'Getting environment id' @($InstallerFunctionsScript) +# Run logs script +Invoke-Logs + +# Finished successfully +Exit 0 diff --git a/datasources/windows/kubernetes/eks/deployevents/prerequisites/functions.ps1 b/datasources/windows/kubernetes/eks/deployevents/prerequisites/functions.ps1 new file mode 100755 index 000000000..95845e48b --- /dev/null +++ b/datasources/windows/kubernetes/eks/deployevents/prerequisites/functions.ps1 @@ -0,0 +1,3 @@ +################################################################################################################################# +############################################### WINDOWS Prerequisites Functions ################################################# +################################################################################################################################# diff --git a/datasources/windows/kubernetes/eks/deployevents/prerequisites/prerequisites.ps1 b/datasources/windows/kubernetes/eks/deployevents/prerequisites/prerequisites.ps1 new file mode 100644 index 000000000..a532fb1a5 --- /dev/null +++ b/datasources/windows/kubernetes/eks/deployevents/prerequisites/prerequisites.ps1 @@ -0,0 +1,6 @@ +################################################################################################################################# +################################################# WINDOWS Prerequisites Script ################################################## +################################################################################################################################# + +# Finished successfully +Exit 0 diff --git a/datasources/windows/kubernetes/eks/deployevents/telemetry/logs/functions.ps1 b/datasources/windows/kubernetes/eks/deployevents/telemetry/logs/functions.ps1 new file mode 100755 index 000000000..257cff67a --- /dev/null +++ b/datasources/windows/kubernetes/eks/deployevents/telemetry/logs/functions.ps1 @@ -0,0 +1,182 @@ +################################################################################################################################# +################################################### WINDOWS Logs Functions ###################################################### +################################################################################################################################# + +# Gets Logz.io logs token +# Input: +# --- +# Output: +# LogsToken - Logz.io logs token +function Get-LogzioLogsToken { + $local:ExitCode = 1 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting Logz.io logs token ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Get-JsonFileFieldValue $script:AgentJson '.shippingTokens.LOG_ANALYTICS' + if ($Err.Count -ne 0) { + $Message = "logs.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:ShippingToken = $script:JsonValue + + $Message = "Logz.io logs token is '$ShippingToken'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogsToken = '$ShippingToken'" +} + +# Builds enable deploy events Helm set +# Input: +# --- +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# helmSets - Contains all the Helm sets +function Build-EnableDeployEventsHelmSet { + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building enable deploy events Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:HelmSet = " --set deployEvents.enabled=true" + + $Message = "Enable deploy events Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} + +# Builds Logz.io deploy events logs listener url Helm set +# Input: +# FuncArgs - Hashtable {ListenerUrl = $script:ListenerUrl} +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# HelmSets - Contains all the Helm sets +function Build-LogzioDeployEventsLogsListenerUrlHelmSet { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 6 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building Logz.io deploy events logs listener URL Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('ListenerUrl') + if ($Err.Count -ne 0) { + $Message = "logs.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:ListenerUrl = $FuncArgs.ListenerUrl + + $local:HelmSet = " --set logzio-k8s-events.secrets.logzioListener=$ListenerUrl" + + $Message = "Logz.io deploy events logs listener url Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} + +# Builds Logz.io deploy events logs token Helm set +# Input: +# FuncArgs - Hashtable {LogsToken = $script:LogsToken} +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# helmSets - Contains all the Helm sets +function Build-LogzioDeployEventsLogsTokenHelmSet { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 7 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building Logz.io deploy events logs token Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('LogsToken') + if ($Err.Count -ne 0) { + $Message = "logs.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:LogsToken = $FuncArgs.LogsToken + + $local:HelmSet = " --set logzio-k8s-events.secrets.logzioShippingToken=$LogsToken" + + $Message = "Logz.io deploy events logs token Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} + +# Builds Deploy events environment id Helm set +# Input: +# FuncArgs - Hashtable {EnvId = $script:EnvId} +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# helmSets - Contains all the Helm sets +function Build-DeployEventsEnvironmentIdHelmSet { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 8 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building deploy events environment id Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('EnvId') + if ($Err.Count -ne 0) { + $Message = "logs.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:EnvId = $FuncArgs.EnvId + + if ([string]::IsNullOrEmpty($EnvId)) { + $Message = 'Environment id is empty. Default value will be used' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + return + } + + $local:HelmSet = " --set logzio-k8s-events.secrets.env_id=$EnvId" + + $Message = "Deploy events Environment id Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} diff --git a/datasources/windows/kubernetes/eks/deployevents/telemetry/logs/logs.ps1 b/datasources/windows/kubernetes/eks/deployevents/telemetry/logs/logs.ps1 new file mode 100755 index 000000000..b212d5482 --- /dev/null +++ b/datasources/windows/kubernetes/eks/deployevents/telemetry/logs/logs.ps1 @@ -0,0 +1,27 @@ +################################################################################################################################# +##################################################### WINDOWS Logs Script ####################################################### +################################################################################################################################# + +$local:LogsFunctionsScript = "$script:LogzioTempDir\$script:Platform\$script:SubType\$($script:CurrentDataSource.ToLower())\$script:LogsFunctionsFile" + +# Print headline +Write-Host +Write-Host '############' +Write-Host '### ' -NoNewline +Write-Host 'Logs' -ForegroundColor Magenta -NoNewline +Write-Host ' ###' +Write-Host '############' + +# Get Logz.io logs token +Invoke-Task 'Get-LogzioLogsToken' @{} 'Getting Logz.io logs token' @($LogsFunctionsScript) +# Build enable security report Helm set +Invoke-Task 'Build-EnableDeployEventsHelmSet' @{} 'Building enable security report Helm set' @($LogsFunctionsScript) +# Build Logz.io Deploy events logs listener url Helm set +Invoke-Task 'Build-LogzioDeployEventsLogsListenerUrlHelmSet' @{ListenerUrl = $script:ListenerUrl} 'Building Logz.io deploy events logs listener url Helm set' @($LogsFunctionsScript) +# Build Logz.io Deploy events logs token Helm set +Invoke-Task 'Build-LogzioDeployEventsLogsTokenHelmSet' @{LogsToken = $script:LogsToken} 'Building Logz.io deploy events logs token Helm set' @($LogsFunctionsScript) +# Build Deploy events environment id Helm set +Invoke-Task 'Build-DeployEventsEnvironmentIdHelmSet' @{EnvId = $script:EnvId} 'Building Deploy events environment id Helm set' @($LogsFunctionsScript) + +# Finished successfully +Exit 0 diff --git a/datasources/windows/kubernetes/gke/deployevents/installer/functions.ps1 b/datasources/windows/kubernetes/gke/deployevents/installer/functions.ps1 new file mode 100755 index 000000000..121c5e53e --- /dev/null +++ b/datasources/windows/kubernetes/gke/deployevents/installer/functions.ps1 @@ -0,0 +1,231 @@ +################################################################################################################################# +################################################# WINDOWS Installer Functions ################################################### +################################################################################################################################# + +# Gets the selected products (logs/metrics/traces) +# Input: +# --- +# Output: +# IsLogsOptionSelected - Tells if logs option was selected (true/false) +# LogsTelemetry - The logs telemetry if logs option was selected +# LogsParams - The logs params if logs option was selected +# IsMetricsOptionSelected - Tells if metrics option was selected (true/false) +# MetricsTelemetry - The metrics telemetry if metrics option was selected +# MetricsParams - The metrics params if metrics option was selected +# IsTracesOptionSelected - Tells if traces option was selected (true/false) +# TracesTelemetry - The traces telemetry if traces option was selected +# TracesParams - The traces params if traces option was selected +function Get-SelectedProducts { + $local:ExitCode = 1 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting the selected products ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:DataSourceIndex = 0 + foreach ($DataSource in $script:DataSources) { + if ($Datasource.Equals($script:CurrentDataSource)) { + break + } + + $DataSourceIndex++ + } + + $local:Err = Get-JsonFileFieldValueList $script:AgentJson ".configuration.subtypes[0].datasources[$DataSourceIndex].telemetries[]" + if ($Err.Count -ne 0) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:Telemetries = $script:JsonValue + + $local:IsLogsOptionSelected = $false + $local:IsMetricsOptionSelected = $false + $local:IsTracesOptionSelected = $false + + $local:TelemetryIndex = 0 + foreach ($Telemetry in $Telemetries) { + $Err = Get-JsonStrFieldValue $Telemetry '.type' + if ($Err.Count -ne 0) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:Type = $script:JsonValue + $local:Params = $null + + $Err = Get-JsonStrFieldValueList $Telemetry '.params[]' + if ($Err.Count -ne 0 -and $Err[1] -ne 2) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + if ($Err.Count -ne 0) { + $Params = '' + } + else { + $Params = $script:JsonValue + } + + $local:ParamsStr = Convert-ListToStr $Params + + if ($Type.Equals('LOG_ANALYTICS')) { + $Message = 'Logs option was selected' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Logs telemetry is '$Telemetry'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Logs params are '$Params'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $IsLogsOptionSelected = $true + Write-TaskPostRun "`$script:LogsTelemetry = '$Telemetry'" + Write-TaskPostRun "`$script:LogsParams = $ParamsStr" + } + elseif ($Type.Equals('METRICS')) { + $Message = 'Metrics option was selected' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Metrics telemetry is '$Telemetry'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Metrics params are '$Params'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $IsMetricsOptionSelected = $true + Write-TaskPostRun "`$script:MetricsTelemetry = '$Telemetry'" + Write-TaskPostRun "`$script:MetricsParams = $ParamsStr" + } + elseif ($Type.Equals('TRACING')) { + $Message = 'Traces option was selected' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Traces telemetry is '$Telemetry'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + $Message = "Traces params are '$Params'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $IsTracesOptionSelected = $true + Write-TaskPostRun "`$script:TracesTelemetry = '$Telemetry'" + Write-TaskPostRun "`$script:TracesParams = $ParamsStr" + } + + $TelemetryIndex++ + } + + Write-TaskPostRun "`$script:IsLogsOptionSelected = `$$IsLogsOptionSelected" + Write-TaskPostRun "`$script:IsMetricsOptionSelected = `$$IsMetricsOptionSelected" + Write-TaskPostRun "`$script:IsTracesOptionSelected = `$$IsTracesOptionSelected" +} + +# Gets general params (params under datasource) +# Input: +# --- +# Output: +# GeneralParams - The params under datasource +function Get-GeneralParams { + $local:ExitCode = 2 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting general params ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:DataSourceIndex = 0 + foreach ($DataSource in $script:DataSources) { + if ($Datasource.Equals($script:CurrentDataSource)) { + break + } + + $DataSourceIndex++ + } + + $local:Err = Get-JsonFileFieldValueList $script:AgentJson ".configuration.subtypes[0].datasources[$DataSourceIndex].params[]" + if ($Err.Count -ne 0) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:Params = $script:JsonValue + + $Message = "General params are '$Params'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:ParamsStr = Convert-ListToStr $Params + + Write-TaskPostRun "`$script:GeneralParams = $ParamsStr" +} + +# Gets environment id +# Input: +# FuncArgs - Hashtable {GeneralParams = $script:GeneralParams; DefaultEnvId = $script:DefaultEnvId} +# Output: +# EnvId - The environment id +function Get-EnvironmentID { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 4 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting environment id ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('GeneralParams', 'DefaultEnvId') + if ($Err.Count -ne 0) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:GeneralParams = $FuncArgs.GeneralParams + $local:DefaultEnvId = $FuncArgs.DefaultEnvId + + $Err = Get-ParamValue $GeneralParams 'envID' + if ($Err.Count -ne 0) { + $Message = "installer.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:EnvId = $script:ParamValue + + if ([string]::IsNullOrEmpty($EnvId)) { + $local:ClusterName = kubectl config current-context 2>$Null + if ($LASTEXITCODE -ne 0) { + $EnvId = $DefaultEnvId + } else { + $EnvId = $ClusterName.Split('_')[1] + } + } + + $Message = "Environment id is '$EnvId'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:EnvId = '$EnvId'" +} diff --git a/datasources/windows/kubernetes/gke/deployevents/installer/installer.ps1 b/datasources/windows/kubernetes/gke/deployevents/installer/installer.ps1 new file mode 100755 index 000000000..c69b0ca19 --- /dev/null +++ b/datasources/windows/kubernetes/gke/deployevents/installer/installer.ps1 @@ -0,0 +1,55 @@ +################################################################################################################################# +################################################### WINDOWS Installer Script #################################################### +################################################################################################################################# + +# Runs logs script +# Input: +# --- +# Output: +# --- +function Invoke-Logs { + $local:ExitCode = 8 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = "Running $CurrentDataSource datasource logs script ..." + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + try { + . "$script:LogzioTempDir\$script:Platform\$script:SubType\$($script:CurrentDataSource.ToLower())\$script:LogsFile" -ErrorAction Stop + if ($LASTEXITCODE -ne 0) { + Exit $LASTEXITCODE + } + } + catch { + $local:Message = "installer.ps1 ($ExitCode): error running $CurrentDataSource datasource logs script: $_" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepInstallation $script:LogScriptInstaller $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Error $Message + + $script:IsAgentFailed = $true + Exit $ExitCode + } +} + + +$local:InstallerFunctionsScript = "$script:LogzioTempDir\$script:Platform\$script:SubType\$($script:CurrentDataSource.ToLower())\$script:InstallerFunctionsFile" + +# Print title +Write-Host +Write-Host '##########################################' +Write-Host '### ' -NoNewline +Write-Host 'Security Datasource Installation' -ForegroundColor Magenta -NoNewline +Write-Host ' ###' +Write-Host '##########################################' + +# Get the selected products +Invoke-Task 'Get-SelectedProducts' @{} 'Getting the selected products' @($InstallerFunctionsScript) +# Get general params +Invoke-Task 'Get-GeneralParams' @{} 'Getting general params' @($InstallerFunctionsScript) +# Get environment id +Invoke-Task 'Get-EnvironmentID' @{GeneralParams = $script:GeneralParams; DefaultEnvId = $script:DefaultEnvId} 'Getting environment id' @($InstallerFunctionsScript) +# Run logs script +Invoke-Logs + +# Finished successfully +Exit 0 diff --git a/datasources/windows/kubernetes/gke/deployevents/prerequisites/functions.ps1 b/datasources/windows/kubernetes/gke/deployevents/prerequisites/functions.ps1 new file mode 100755 index 000000000..95845e48b --- /dev/null +++ b/datasources/windows/kubernetes/gke/deployevents/prerequisites/functions.ps1 @@ -0,0 +1,3 @@ +################################################################################################################################# +############################################### WINDOWS Prerequisites Functions ################################################# +################################################################################################################################# diff --git a/datasources/windows/kubernetes/gke/deployevents/prerequisites/prerequisites.ps1 b/datasources/windows/kubernetes/gke/deployevents/prerequisites/prerequisites.ps1 new file mode 100644 index 000000000..a532fb1a5 --- /dev/null +++ b/datasources/windows/kubernetes/gke/deployevents/prerequisites/prerequisites.ps1 @@ -0,0 +1,6 @@ +################################################################################################################################# +################################################# WINDOWS Prerequisites Script ################################################## +################################################################################################################################# + +# Finished successfully +Exit 0 diff --git a/datasources/windows/kubernetes/gke/deployevents/telemetry/logs/functions.ps1 b/datasources/windows/kubernetes/gke/deployevents/telemetry/logs/functions.ps1 new file mode 100755 index 000000000..257cff67a --- /dev/null +++ b/datasources/windows/kubernetes/gke/deployevents/telemetry/logs/functions.ps1 @@ -0,0 +1,182 @@ +################################################################################################################################# +################################################### WINDOWS Logs Functions ###################################################### +################################################################################################################################# + +# Gets Logz.io logs token +# Input: +# --- +# Output: +# LogsToken - Logz.io logs token +function Get-LogzioLogsToken { + $local:ExitCode = 1 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting Logz.io logs token ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Get-JsonFileFieldValue $script:AgentJson '.shippingTokens.LOG_ANALYTICS' + if ($Err.Count -ne 0) { + $Message = "logs.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:ShippingToken = $script:JsonValue + + $Message = "Logz.io logs token is '$ShippingToken'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogsToken = '$ShippingToken'" +} + +# Builds enable deploy events Helm set +# Input: +# --- +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# helmSets - Contains all the Helm sets +function Build-EnableDeployEventsHelmSet { + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building enable deploy events Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:HelmSet = " --set deployEvents.enabled=true" + + $Message = "Enable deploy events Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} + +# Builds Logz.io deploy events logs listener url Helm set +# Input: +# FuncArgs - Hashtable {ListenerUrl = $script:ListenerUrl} +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# HelmSets - Contains all the Helm sets +function Build-LogzioDeployEventsLogsListenerUrlHelmSet { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 6 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building Logz.io deploy events logs listener URL Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('ListenerUrl') + if ($Err.Count -ne 0) { + $Message = "logs.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:ListenerUrl = $FuncArgs.ListenerUrl + + $local:HelmSet = " --set logzio-k8s-events.secrets.logzioListener=$ListenerUrl" + + $Message = "Logz.io deploy events logs listener url Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} + +# Builds Logz.io deploy events logs token Helm set +# Input: +# FuncArgs - Hashtable {LogsToken = $script:LogsToken} +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# helmSets - Contains all the Helm sets +function Build-LogzioDeployEventsLogsTokenHelmSet { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 7 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building Logz.io deploy events logs token Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('LogsToken') + if ($Err.Count -ne 0) { + $Message = "logs.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:LogsToken = $FuncArgs.LogsToken + + $local:HelmSet = " --set logzio-k8s-events.secrets.logzioShippingToken=$LogsToken" + + $Message = "Logz.io deploy events logs token Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} + +# Builds Deploy events environment id Helm set +# Input: +# FuncArgs - Hashtable {EnvId = $script:EnvId} +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# helmSets - Contains all the Helm sets +function Build-DeployEventsEnvironmentIdHelmSet { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 8 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building deploy events environment id Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('EnvId') + if ($Err.Count -ne 0) { + $Message = "logs.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:EnvId = $FuncArgs.EnvId + + if ([string]::IsNullOrEmpty($EnvId)) { + $Message = 'Environment id is empty. Default value will be used' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + return + } + + $local:HelmSet = " --set logzio-k8s-events.secrets.env_id=$EnvId" + + $Message = "Deploy events Environment id Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} diff --git a/datasources/windows/kubernetes/gke/deployevents/telemetry/logs/logs.ps1 b/datasources/windows/kubernetes/gke/deployevents/telemetry/logs/logs.ps1 new file mode 100755 index 000000000..b212d5482 --- /dev/null +++ b/datasources/windows/kubernetes/gke/deployevents/telemetry/logs/logs.ps1 @@ -0,0 +1,27 @@ +################################################################################################################################# +##################################################### WINDOWS Logs Script ####################################################### +################################################################################################################################# + +$local:LogsFunctionsScript = "$script:LogzioTempDir\$script:Platform\$script:SubType\$($script:CurrentDataSource.ToLower())\$script:LogsFunctionsFile" + +# Print headline +Write-Host +Write-Host '############' +Write-Host '### ' -NoNewline +Write-Host 'Logs' -ForegroundColor Magenta -NoNewline +Write-Host ' ###' +Write-Host '############' + +# Get Logz.io logs token +Invoke-Task 'Get-LogzioLogsToken' @{} 'Getting Logz.io logs token' @($LogsFunctionsScript) +# Build enable security report Helm set +Invoke-Task 'Build-EnableDeployEventsHelmSet' @{} 'Building enable security report Helm set' @($LogsFunctionsScript) +# Build Logz.io Deploy events logs listener url Helm set +Invoke-Task 'Build-LogzioDeployEventsLogsListenerUrlHelmSet' @{ListenerUrl = $script:ListenerUrl} 'Building Logz.io deploy events logs listener url Helm set' @($LogsFunctionsScript) +# Build Logz.io Deploy events logs token Helm set +Invoke-Task 'Build-LogzioDeployEventsLogsTokenHelmSet' @{LogsToken = $script:LogsToken} 'Building Logz.io deploy events logs token Helm set' @($LogsFunctionsScript) +# Build Deploy events environment id Helm set +Invoke-Task 'Build-DeployEventsEnvironmentIdHelmSet' @{EnvId = $script:EnvId} 'Building Deploy events environment id Helm set' @($LogsFunctionsScript) + +# Finished successfully +Exit 0 diff --git a/resources-linux/k8s/datasource_logs_utils.bash b/resources-linux/k8s/datasource_logs_utils.bash index 6462ae044..d8829a182 100755 --- a/resources-linux/k8s/datasource_logs_utils.bash +++ b/resources-linux/k8s/datasource_logs_utils.bash @@ -187,3 +187,95 @@ function build_trivy_environment_id_helm_set { write_task_post_run "LOG_HELM_SETS+='$helm_set'" write_task_post_run "HELM_SETS+='$helm_set'" } + +# Builds enable deploy events Helm set +# Input: +# --- +# Output: +# LOG_HELM_SETS - Contains all the Helm sets for logging +# HELM_SETS - Contains all the Helm sets +function build_enable_deploy_events_helm_set { + local func_name="${FUNCNAME[0]}" + + local message='Building enable deploy events Helm set ...' + 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" + + local helm_set=" --set deployEvents.enabled=true" + + message="Enable deploy events Helm set is '$helm_set'" + 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" + + write_task_post_run "LOG_HELM_SETS+='$helm_set'" + write_task_post_run "HELM_SETS+='$helm_set'" +} + +# Builds Logz.io deploy events logs listener URL Helm set +# Input: +# --- +# Output: +# LOG_HELM_SETS - Contains all the Helm sets for logging +# HELM_SETS - Contains all the Helm sets +function build_logzio_deploy_events_logs_listener_url_helm_set { + local func_name="${FUNCNAME[0]}" + + local message='Building Logz.io deploy events logs listener url Helm set ...' + 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" + + local helm_set=" --set logzio-k8s-events.secrets.logzioListener=$LISTENER_URL" + + message="Logz.io deploy events logs listener url Helm set is '$helm_set'" + 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" + + write_task_post_run "LOG_HELM_SETS+='$helm_set'" + write_task_post_run "HELM_SETS+='$helm_set'" +} + +# Builds Logz.io deploy events logs token Helm set +# Input: +# --- +# Output: +# LOG_HELM_SETS - Contains all the Helm sets for logging +# HELM_SETS - Contains all the Helm sets +function build_logzio_deploy_events_logs_token_helm_set { + local func_name="${FUNCNAME[0]}" + + local message='Building Logz.io deploy events logs token Helm set ...' + 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" + + local helm_set=" --set logzio-k8s-events.secrets.logzioShippingToken=$LOGS_TOKEN" + + message="Logz.io deploy events logs token Helm set is '$helm_set'" + 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" + + write_task_post_run "LOG_HELM_SETS+='$helm_set'" + write_task_post_run "HELM_SETS+='$helm_set'" +} + +# Builds deploy events environment id helm set +# Input: +# --- +# Output: +# LOG_HELM_SETS - Contains all the Helm sets for logging +# HELM_SETS - Contains all the Helm sets +function build_deploy_events_environment_id_helm_set { + local func_name="${FUNCNAME[0]}" + + local message='Building deploy events environment id Helm set ...' + 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" + + local helm_set=" --set logzio-k8s-events.secrets.env_id=$ENV_ID" + + message="Deploy events environment id Helm set is '$helm_set'" + 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" + + write_task_post_run "LOG_HELM_SETS+='$helm_set'" + write_task_post_run "HELM_SETS+='$helm_set'" +} diff --git a/resources-mac/k8s/datasource_logs_utils.bash b/resources-mac/k8s/datasource_logs_utils.bash index e3b78686e..f9f12e892 100755 --- a/resources-mac/k8s/datasource_logs_utils.bash +++ b/resources-mac/k8s/datasource_logs_utils.bash @@ -187,3 +187,95 @@ function build_trivy_environment_id_helm_set { write_task_post_run "LOG_HELM_SETS+='$helm_set'" write_task_post_run "HELM_SETS+='$helm_set'" } + +# Builds enable deploy events Helm set +# Input: +# --- +# Output: +# LOG_HELM_SETS - Contains all the Helm sets for logging +# HELM_SETS - Contains all the Helm sets +function build_enable_deploy_events_helm_set { + local func_name="${FUNCNAME[0]}" + + local message='Building enable deploy events Helm set ...' + 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" + + local helm_set=" --set deployEvents.enabled=true" + + message="Enable deploy events Helm set is '$helm_set'" + 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" + + write_task_post_run "LOG_HELM_SETS+='$helm_set'" + write_task_post_run "HELM_SETS+='$helm_set'" +} + +# Builds Logz.io deploy events logs listener URL Helm set +# Input: +# --- +# Output: +# LOG_HELM_SETS - Contains all the Helm sets for logging +# HELM_SETS - Contains all the Helm sets +function build_logzio_deploy_events_logs_listener_url_helm_set { + local func_name="${FUNCNAME[0]}" + + local message='Building Logz.io deploy events logs listener url Helm set ...' + 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" + + local helm_set=" --set logzio-k8s-events.secrets.logzioListener=$LISTENER_URL" + + message="Logz.io deploy events logs listener url Helm set is '$helm_set'" + 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" + + write_task_post_run "LOG_HELM_SETS+='$helm_set'" + write_task_post_run "HELM_SETS+='$helm_set'" +} + +# Builds Logz.io deploy events logs token Helm set +# Input: +# --- +# Output: +# LOG_HELM_SETS - Contains all the Helm sets for logging +# HELM_SETS - Contains all the Helm sets +function build_logzio_deploy_events_logs_token_helm_set { + local func_name="${FUNCNAME[0]}" + + local message='Building Logz.io deploy events logs token Helm set ...' + 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" + + local helm_set=" --set logzio-k8s-events.secrets.logzioShippingToken=$LOGS_TOKEN" + + message="Logz.io deploy events logs token Helm set is '$helm_set'" + 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" + + write_task_post_run "LOG_HELM_SETS+='$helm_set'" + write_task_post_run "HELM_SETS+='$helm_set'" +} + +# Builds deploy events environment id helm set +# Input: +# --- +# Output: +# LOG_HELM_SETS - Contains all the Helm sets for logging +# HELM_SETS - Contains all the Helm sets +function build_deploy_events_environment_id_helm_set { + local func_name="${FUNCNAME[0]}" + + local message='Building deploy events environment id Helm set ...' + 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" + + local helm_set=" --set logzio-k8s-events.secrets.env_id=$ENV_ID" + + message="Deploy events environment id Helm set is '$helm_set'" + 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" + + write_task_post_run "LOG_HELM_SETS+='$helm_set'" + write_task_post_run "HELM_SETS+='$helm_set'" +}