Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add Kubernetes deploy events #143

Merged
merged 16 commits into from
Dec 5, 2023
Merged
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,4 @@ bash <(curl -sSL https://github.com/logzio/logzio-agent-manifest/releases/downlo
```PowerShell
powershell { iex “& { $(irm https://github.com/logzio/logzio-agent-manifest/releases/download/latest/run_prerequisites_windows.ps1) } --path=LOGZIO_REPO_DATASOURCE_PATH” }
```

17 changes: 17 additions & 0 deletions config-templates/helm.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,22 @@
}
]
},
{
"template": " --set deployEvents.enabled=true \\",
"targetElement": "datasources[?(@.name=='DeployEvents')]",
"conditionalTemplates": [
{
"template": " --set logzio-k8s-events.secrets.env_id='{{value}}' \\",
"targetElement": "datasources[?(@.name=='DeployEvents')].params[?(@.name=='envID')].value",
"keepAsPlaceholder": true
},
{
"template": " --set logzio-k8s-events.secrets.logzioShippingToken='<<LOGZIO_LOGS_SHIPPING_TOKEN>>' \\"
},
{
"template": " --set logzio-k8s-events.secrets.logzioListener='<<LOGZIO_LISTENER_ADDRESS>>' \\"
}
]
},
{ "template": "logzio-monitoring logzio-helm/logzio-monitoring" }
]
25 changes: 25 additions & 0 deletions configs/2-1-k8s-eks.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,31 @@
"params": []
}
]
},
{
"name": "DeployEvents",
"logo": "https://dytvr9ot2sszz.cloudfront.net/logz-docs/shipper-logos/kubernetes.svg",
ralongit marked this conversation as resolved.
Show resolved Hide resolved
"label": "Deploy Events",
ralongit marked this conversation as resolved.
Show resolved Hide resolved
"description": "Logz.io uses Kubernetes official SDK to detect deploy events that occur in your cluster and allows you to view the changes.",
"params": [
{
"type": "text",
"name": "envID",
"label": "Environment Name",
"description": "The name for your environments identifier, to easily identify the telemetry data for each environment.",
"hint": "By typing an environment name, the name will be added as a label to the telemetry data of your environment.",
"value": "",
"pattern": "^[a-zA-Z0-9_-]*$",
"patternError": "Only letters, numbers, dashes and underscores are allowed"
}
],
"telemetries": [
{
"type": "LOG_ANALYTICS",
"hint": "Switch the toggle on if you want Logz.io Telemetry Collector to collect deploy events from your Kubernetes cluster components.",
"params": []
}
]
}
]
}
Expand Down
27 changes: 26 additions & 1 deletion configs/2-2-k8s-aks.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,32 @@
"params": []
}
]
}
},
{
"name": "DeployEvents",
"logo": "https://dytvr9ot2sszz.cloudfront.net/logz-docs/shipper-logos/kubernetes.svg",
"label": "Deploy Events",
"description": "Logz.io uses Kubernetes official SDK to detect deploy events that occur in your cluster and allows you to view the changes.",
"params": [
{
"type": "text",
"name": "envID",
"label": "Environment Name",
"description": "The name for your environments identifier, to easily identify the telemetry data for each environment.",
"hint": "By typing an environment name, the name will be added as a label to the telemetry data of your environment.",
"value": "",
"pattern": "^[a-zA-Z0-9_-]*$",
"patternError": "Only letters, numbers, dashes and underscores are allowed"
}
],
"telemetries": [
{
"type": "LOG_ANALYTICS",
"hint": "Switch the toggle on if you want Logz.io Telemetry Collector to collect deploy events from your Kubernetes cluster components.",
"params": []
}
]
}
]
}
]
Expand Down
27 changes: 26 additions & 1 deletion configs/2-3-k8s-gke.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,32 @@
"params": []
}
]
}
},
{
"name": "DeployEvents",
"logo": "https://dytvr9ot2sszz.cloudfront.net/logz-docs/shipper-logos/kubernetes.svg",
"label": "Deploy Events",
"description": "Logz.io uses Kubernetes official SDK to detect deploy events that occur in your cluster and allows you to view the changes.",
"params": [
{
"type": "text",
"name": "envID",
"label": "Environment Name",
"description": "The name for your environments identifier, to easily identify the telemetry data for each environment.",
"hint": "By typing an environment name, the name will be added as a label to the telemetry data of your environment.",
"value": "",
"pattern": "^[a-zA-Z0-9_-]*$",
"patternError": "Only letters, numbers, dashes and underscores are allowed"
}
],
"telemetries": [
{
"type": "LOG_ANALYTICS",
"hint": "Switch the toggle on if you want Logz.io Telemetry Collector to collect deploy events from your Kubernetes cluster components.",
"params": []
}
]
}
]
}
]
Expand Down
27 changes: 26 additions & 1 deletion configs/2-4-k8s-digitalocean.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,32 @@
"params": []
}
]
}
},
{
"name": "DeployEvents",
"logo": "https://dytvr9ot2sszz.cloudfront.net/logz-docs/shipper-logos/kubernetes.svg",
"label": "Deploy Events",
"description": "Logz.io uses Kubernetes official SDK to detect deploy events that occur in your cluster and allows you to view the changes.",
"params": [
{
"type": "text",
"name": "envID",
"label": "Environment Name",
"description": "The name for your environments identifier, to easily identify the telemetry data for each environment.",
"hint": "By typing an environment name, the name will be added as a label to the telemetry data of your environment.",
"value": "",
"pattern": "^[a-zA-Z0-9_-]*$",
"patternError": "Only letters, numbers, dashes and underscores are allowed"
}
],
"telemetries": [
{
"type": "LOG_ANALYTICS",
"hint": "Switch the toggle on if you want Logz.io Telemetry Collector to collect deploy events from your Kubernetes cluster components.",
"params": []
}
]
}
]
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash

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

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

local message='Loading installer utils functions ...'
send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_INSTALLATION" "$LOG_SCRIPT_INSTALLER" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
write_log "$LOG_LEVEL_DEBUG" "$message"

source "$ALL_RESOURCES_LINUX_DIR/datasource_installer_utils.bash" 2>"$TASK_ERROR_FILE"
if [[ $? -ne 0 ]]; then
message="installer.bash ($EXIT_CODE): error loading installer utils functions: $(get_task_error_message)"
send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_INSTALLATION" "$LOG_SCRIPT_INSTALLER" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
write_error "$message"

IS_AGENT_FAILED=true
run_final
exit $EXIT_CODE
fi

source "$KUBERNETES_RESOURCES_LINUX_DIR/datasource_installer_utils.bash" 2>"$TASK_ERROR_FILE"
if [[ $? -ne 0 ]]; then
message="installer.bash ($EXIT_CODE): error loading installer utils functions: $(get_task_error_message)"
send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_INSTALLATION" "$LOG_SCRIPT_INSTALLER" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
write_error "$message"

IS_AGENT_FAILED=true
run_final
exit $EXIT_CODE
fi

((EXIT_CODE++))
}

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

local message='Getting environment id ...'
send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_INSTALLATION" "$LOG_SCRIPT_INSTALLER" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
write_log "$LOG_LEVEL_DEBUG" "$message"

PARAMS=("${GENERAL_PARAMS[@]}")
get_param_value 'envID'
if [[ $? -ne 0 ]]; then
message="installer.bash ($EXIT_CODE): $(get_task_error_message)"
send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_INSTALLATION" "$LOG_SCRIPT_INSTALLER" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
write_task_post_run "write_error \"$message\""

return $EXIT_CODE
fi

local env_id="$PARAM_VALUE"

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

message="Environment id is '$env_id'"
send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_INSTALLATION" "$LOG_SCRIPT_INSTALLER" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
write_log "$LOG_LEVEL_DEBUG" "$message"

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

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

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

EXIT_CODE=1

# Load datasource installer utils functions
load_installer_utils

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

DATA_SOURCE_INSTALLER_EXIT_CODE=$EXIT_CODE

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

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

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

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

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

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

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

IS_AGENT_FAILED=true
run_final
exit $EXIT_CODE
fi

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

IS_AGENT_FAILED=true
run_final
exit $EXIT_CODE
fi

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

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

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

EXIT_CODE=1

# Load datasource logs utils functions
load_logs_utils

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