From 44dcf6cfe676570a4691af65f8df3e66c27ba284 Mon Sep 17 00:00:00 2001 From: Alexey Pustovalov Date: Tue, 31 Dec 2024 02:36:07 +0900 Subject: [PATCH] Updated dependencies for Windows containers --- Dockerfiles/agent/alpine/Dockerfile | 2 +- Dockerfiles/agent/centos/Dockerfile | 2 +- Dockerfiles/agent/ol/Dockerfile | 2 +- Dockerfiles/agent/rhel/Dockerfile | 2 +- Dockerfiles/agent/ubuntu/Dockerfile | 2 +- .../agent/windows/docker-entrypoint.ps1 | 61 +++---- Dockerfiles/agent2/alpine/Dockerfile | 2 +- .../agent2/alpine/docker-entrypoint.sh | 4 +- Dockerfiles/agent2/centos/Dockerfile | 2 +- .../agent2/centos/docker-entrypoint.sh | 4 +- Dockerfiles/agent2/ol/Dockerfile | 2 +- Dockerfiles/agent2/ol/docker-entrypoint.sh | 4 +- Dockerfiles/agent2/rhel/Dockerfile | 2 +- Dockerfiles/agent2/rhel/docker-entrypoint.sh | 4 +- Dockerfiles/agent2/ubuntu/Dockerfile | 2 +- .../agent2/ubuntu/docker-entrypoint.sh | 4 +- Dockerfiles/agent2/windows/Dockerfile | 23 ++- .../agent2/windows/docker-entrypoint.ps1 | 165 +++++++++--------- .../build-mysql/windows/Dockerfile.agent2 | 2 +- 19 files changed, 149 insertions(+), 142 deletions(-) diff --git a/Dockerfiles/agent/alpine/Dockerfile b/Dockerfiles/agent/alpine/Dockerfile index b0b2b8d7b..12f4f5921 100644 --- a/Dockerfiles/agent/alpine/Dockerfile +++ b/Dockerfiles/agent/alpine/Dockerfile @@ -69,7 +69,7 @@ RUN set -eux && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/enc && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/enc_internal && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/modules && \ - mkdir -p ${ZABBIX_USER_HOME_DIR}/user_scripts && \ + mkdir -p ${ZBX_USERPARAMETERDIR} && \ chown --quiet -R zabbix:root ${ZABBIX_CONF_DIR}/zabbix_agentd_modules.conf \ ${ZABBIX_CONF_DIR}/zabbix_agentd_item_keys.conf \ ${ZABBIX_CONF_DIR}/zabbix_agentd.d/ \ diff --git a/Dockerfiles/agent/centos/Dockerfile b/Dockerfiles/agent/centos/Dockerfile index f981e4f25..733839bf1 100644 --- a/Dockerfiles/agent/centos/Dockerfile +++ b/Dockerfiles/agent/centos/Dockerfile @@ -87,7 +87,7 @@ RUN --mount=type=tmpfs,target=/var/lib/dnf/ \ mkdir -p ${ZABBIX_USER_HOME_DIR}/enc && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/enc_internal && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/modules && \ - mkdir -p ${ZABBIX_USER_HOME_DIR}/user_scripts && \ + mkdir -p ${ZBX_USERPARAMETERDIR} && \ chown --quiet -R zabbix:root ${ZABBIX_CONF_DIR}/zabbix_agentd_modules.conf \ ${ZABBIX_CONF_DIR}/zabbix_agentd_item_keys.conf \ ${ZABBIX_CONF_DIR}/zabbix_agentd.d/ \ diff --git a/Dockerfiles/agent/ol/Dockerfile b/Dockerfiles/agent/ol/Dockerfile index dfbc62595..6f20ce4bf 100644 --- a/Dockerfiles/agent/ol/Dockerfile +++ b/Dockerfiles/agent/ol/Dockerfile @@ -74,7 +74,7 @@ RUN --mount=type=tmpfs,target=/var/lib/dnf/ \ mkdir -p ${ZABBIX_USER_HOME_DIR}/enc && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/enc_internal && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/modules && \ - mkdir -p ${ZABBIX_USER_HOME_DIR}/user_scripts && \ + mkdir -p ${ZBX_USERPARAMETERDIR} && \ chown --quiet -R zabbix:root ${ZABBIX_CONF_DIR}/zabbix_agentd_modules.conf \ ${ZABBIX_CONF_DIR}/zabbix_agentd_item_keys.conf \ ${ZABBIX_CONF_DIR}/zabbix_agentd.d/ \ diff --git a/Dockerfiles/agent/rhel/Dockerfile b/Dockerfiles/agent/rhel/Dockerfile index 3b80569d3..ee0e52d90 100644 --- a/Dockerfiles/agent/rhel/Dockerfile +++ b/Dockerfiles/agent/rhel/Dockerfile @@ -112,7 +112,7 @@ RUN --mount=type=tmpfs,target=/var/lib/dnf/ \ mkdir -p ${ZABBIX_USER_HOME_DIR}/enc && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/enc_internal && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/modules && \ - mkdir -p ${ZABBIX_USER_HOME_DIR}/user_scripts && \ + mkdir -p ${ZBX_USERPARAMETERDIR} && \ chown --quiet -R zabbix:root ${ZABBIX_CONF_DIR}/zabbix_agentd_modules.conf \ ${ZABBIX_CONF_DIR}/zabbix_agentd_item_keys.conf \ ${ZABBIX_CONF_DIR}/zabbix_agentd.d/ \ diff --git a/Dockerfiles/agent/ubuntu/Dockerfile b/Dockerfiles/agent/ubuntu/Dockerfile index fc96260bc..9121b1558 100644 --- a/Dockerfiles/agent/ubuntu/Dockerfile +++ b/Dockerfiles/agent/ubuntu/Dockerfile @@ -70,7 +70,7 @@ RUN --mount=type=cache,target=/var/cache/apt/,sharing=locked \ mkdir -p ${ZABBIX_USER_HOME_DIR}/enc && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/enc_internal && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/modules && \ - mkdir -p ${ZABBIX_USER_HOME_DIR}/user_scripts && \ + mkdir -p ${ZBX_USERPARAMETERDIR} && \ chown --quiet -R zabbix:root ${ZABBIX_CONF_DIR}/zabbix_agentd_modules.conf \ ${ZABBIX_CONF_DIR}/zabbix_agentd_item_keys.conf \ ${ZABBIX_CONF_DIR}/zabbix_agentd.d/ \ diff --git a/Dockerfiles/agent/windows/docker-entrypoint.ps1 b/Dockerfiles/agent/windows/docker-entrypoint.ps1 index b56c397ed..22b981e92 100644 --- a/Dockerfiles/agent/windows/docker-entrypoint.ps1 +++ b/Dockerfiles/agent/windows/docker-entrypoint.ps1 @@ -4,7 +4,6 @@ if ($env:DEBUG_MODE -eq "true") { Set-PSDebug -trace 1 } -# Default Zabbix installation name # Default Zabbix server host if ($env:ZBX_SERVER_HOST -eq $null) { $env:ZBX_SERVER_HOST="zabbix-server" @@ -129,27 +128,27 @@ function File-Process-From-Env { ) if (![string]::IsNullOrEmpty($VarValue)) { - $VarValue | Set-Content "$ZabbixInternalEncDir\VarName" - $FileName="$ZabbixInternalEncDir\VarName" - } + $VarValue | Set-Content "$ZabbixInternalEncDir\VarName" + $FileName="$ZabbixInternalEncDir\VarName" + } - if (![string]::IsNullOrEmpty($FileName)) { - Set-Item env:$VarName -Value $FileName - } + if (![string]::IsNullOrEmpty($FileName)) { + Set-Item env:$VarName -Value $FileName + } - $VarName=$VarName -replace 'FILE$' - Write-Host "** $VarName" - Set-Item env:$VarName -Value $null + $VarName=$VarName -replace 'FILE$' + Set-Item env:$VarName -Value $null } function Prepare-Zbx-Agent-Config { $ZbxAgentConfig="$env:ZABBIX_CONF_DIR\zabbix_agentd.conf" - if ($env:ZBX_PASSIVESERVERS -eq $null) { - $env:ZBX_PASSIVESERVERS="" - } - if ($env:ZBX_ACTIVESERVERS -eq $null) { - $env:ZBX_ACTIVESERVERS="" - } + + if ($env:ZBX_PASSIVESERVERS -eq $null) { + $env:ZBX_PASSIVESERVERS="" + } + if ($env:ZBX_ACTIVESERVERS -eq $null) { + $env:ZBX_ACTIVESERVERS="" + } if (![string]::IsNullOrEmpty($env:ZBX_SERVER_HOST) -And ![string]::IsNullOrEmpty($env:ZBX_PASSIVESERVERS)) { $env:ZBX_PASSIVESERVERS="$env:ZBX_SERVER_HOST,$env:ZBX_PASSIVESERVERS" @@ -158,24 +157,24 @@ function Prepare-Zbx-Agent-Config { $env:ZBX_PASSIVESERVERS=$env:ZBX_SERVER_HOST } - if (![string]::IsNullOrEmpty($env:ZBX_SERVER_HOST)) { - if (![string]::IsNullOrEmpty($env:ZBX_SERVER_PORT) -And $env:ZBX_SERVER_PORT -ne "10051") { - $env:ZBX_SERVER_HOST="$env:ZBX_SERVER_HOST:$env:ZBX_SERVER_PORT" - } - if (![string]::IsNullOrEmpty($env:ZBX_ACTIVESERVERS)) { - $env:ZBX_ACTIVESERVERS="$env:ZBX_SERVER_HOST,$env:ZBX_ACTIVESERVERS" - } - else { - $env:ZBX_ACTIVESERVERS=$env:ZBX_SERVER_HOST - } - } + if (![string]::IsNullOrEmpty($env:ZBX_SERVER_HOST)) { + if (![string]::IsNullOrEmpty($env:ZBX_SERVER_PORT) -And $env:ZBX_SERVER_PORT -ne "10051") { + $env:ZBX_SERVER_HOST="$env:ZBX_SERVER_HOST:$env:ZBX_SERVER_PORT" + } + if (![string]::IsNullOrEmpty($env:ZBX_ACTIVESERVERS)) { + $env:ZBX_ACTIVESERVERS="$env:ZBX_SERVER_HOST,$env:ZBX_ACTIVESERVERS" + } + else { + $env:ZBX_ACTIVESERVERS=$env:ZBX_SERVER_HOST + } + } if ([string]::IsNullOrWhitespace($env:ZBX_PASSIVE_ALLOW)) { $env:ZBX_PASSIVE_ALLOW="true" } if ($env:ZBX_PASSIVE_ALLOW -eq "true") { - Write-Host "** Using '$env:ZBX_PASSIVESERVERS' servers for passive checks" + Write-Host "** Using '$env:ZBX_PASSIVESERVERS' servers for passive checks" } else { Set-Item env:ZBX_PASSIVESERVERS -Value $null @@ -192,10 +191,8 @@ function Prepare-Zbx-Agent-Config { Set-Item env:ZBX_ACTIVESERVERS -Value $null } - Update-Config-Multiple-Var "$env:ZABBIX_CONF_DIR\zabbix_agentd_item_keys.conf" "DenyKey" "$env:ZBX_DENYKEY" - Update-Config-Multiple-Var "$env:ZABBIX_CONF_DIR\zabbix_agentd_item_keys.conf" "AllowKey" "$env:ZBX_ALLOWKEY" - -# Update-Config-Multiple-Var "$env:ZABBIX_CONF_DIR\zabbix_agentd_modules.conf" "LoadModule" "$env:LOADMODULE" + Update-Config-Multiple-Var "$env:ZABBIX_CONF_DIR\zabbix_agent2_item_keys.conf" "DenyKey" "$env:ZBX_DENYKEY" + Update-Config-Multiple-Var "$env:ZABBIX_CONF_DIR\zabbix_agent2_item_keys.conf" "AllowKey" "$env:ZBX_ALLOWKEY" File-Process-From-Env "ZBX_TLSCAFILE" "$env:ZBX_TLSCAFILE" "$env:ZBX_TLSCA" File-Process-From-Env "ZBX_TLSCRLFILE" "$env:ZBX_TLSCRLFILE" "$env:ZBX_TLSCRL" diff --git a/Dockerfiles/agent2/alpine/Dockerfile b/Dockerfiles/agent2/alpine/Dockerfile index 7a9db1d86..426281025 100644 --- a/Dockerfiles/agent2/alpine/Dockerfile +++ b/Dockerfiles/agent2/alpine/Dockerfile @@ -68,7 +68,7 @@ RUN set -eux && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/enc && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/enc_internal && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/buffer && \ - mkdir -p ${ZABBIX_USER_HOME_DIR}/user_scripts && \ + mkdir -p ${ZBX_USERPARAMETERDIR} && \ chown --quiet -R zabbix:root ${ZABBIX_CONF_DIR}/zabbix_agent2_item_keys.conf \ ${ZABBIX_CONF_DIR}/zabbix_agentd.d/ \ ${ZABBIX_CONF_DIR}/zabbix_agent2.d/ \ diff --git a/Dockerfiles/agent2/alpine/docker-entrypoint.sh b/Dockerfiles/agent2/alpine/docker-entrypoint.sh index 858335b9b..c27bb2f3c 100755 --- a/Dockerfiles/agent2/alpine/docker-entrypoint.sh +++ b/Dockerfiles/agent2/alpine/docker-entrypoint.sh @@ -175,12 +175,14 @@ prepare_zbx_agent_config() { if [ "${ZBX_ENABLEPERSISTENTBUFFER,,}" == "true" ]; then export ZBX_ENABLEPERSISTENTBUFFER=1 + else + unset ZBX_ENABLEPERSISTENTBUFFER fi if [ "${ZBX_ENABLESTATUSPORT,,}" == "true" ]; then export ZBX_STATUSPORT=${ZBX_STATUSPORT="31999"} else - unset ZBX_PERSISTENTBUFFERFILE + unset ZBX_STATUSPORT fi update_config_multiple_var "${ZABBIX_CONF_DIR}/zabbix_agentd_item_keys.conf" "DenyKey" "${ZBX_DENYKEY}" diff --git a/Dockerfiles/agent2/centos/Dockerfile b/Dockerfiles/agent2/centos/Dockerfile index 3f7575fc8..ceaec702b 100644 --- a/Dockerfiles/agent2/centos/Dockerfile +++ b/Dockerfiles/agent2/centos/Dockerfile @@ -89,7 +89,7 @@ RUN --mount=type=tmpfs,target=/var/lib/dnf/ \ mkdir -p ${ZABBIX_USER_HOME_DIR}/enc && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/enc_internal && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/buffer && \ - mkdir -p ${ZABBIX_USER_HOME_DIR}/user_scripts && \ + mkdir -p ${ZBX_USERPARAMETERDIR} && \ chown --quiet -R zabbix:root ${ZABBIX_CONF_DIR}/zabbix_agent2_item_keys.conf \ ${ZABBIX_CONF_DIR}/zabbix_agentd.d/ \ ${ZABBIX_CONF_DIR}/zabbix_agent2.d/ \ diff --git a/Dockerfiles/agent2/centos/docker-entrypoint.sh b/Dockerfiles/agent2/centos/docker-entrypoint.sh index 858335b9b..c27bb2f3c 100755 --- a/Dockerfiles/agent2/centos/docker-entrypoint.sh +++ b/Dockerfiles/agent2/centos/docker-entrypoint.sh @@ -175,12 +175,14 @@ prepare_zbx_agent_config() { if [ "${ZBX_ENABLEPERSISTENTBUFFER,,}" == "true" ]; then export ZBX_ENABLEPERSISTENTBUFFER=1 + else + unset ZBX_ENABLEPERSISTENTBUFFER fi if [ "${ZBX_ENABLESTATUSPORT,,}" == "true" ]; then export ZBX_STATUSPORT=${ZBX_STATUSPORT="31999"} else - unset ZBX_PERSISTENTBUFFERFILE + unset ZBX_STATUSPORT fi update_config_multiple_var "${ZABBIX_CONF_DIR}/zabbix_agentd_item_keys.conf" "DenyKey" "${ZBX_DENYKEY}" diff --git a/Dockerfiles/agent2/ol/Dockerfile b/Dockerfiles/agent2/ol/Dockerfile index e2bc76045..bc26c6b30 100644 --- a/Dockerfiles/agent2/ol/Dockerfile +++ b/Dockerfiles/agent2/ol/Dockerfile @@ -76,7 +76,7 @@ RUN --mount=type=tmpfs,target=/var/lib/dnf/ \ mkdir -p ${ZABBIX_USER_HOME_DIR}/enc && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/enc_internal && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/buffer && \ - mkdir -p ${ZABBIX_USER_HOME_DIR}/user_scripts && \ + mkdir -p ${ZBX_USERPARAMETERDIR} && \ chown --quiet -R zabbix:root ${ZABBIX_CONF_DIR}/zabbix_agent2_item_keys.conf \ ${ZABBIX_CONF_DIR}/zabbix_agentd.d/ \ ${ZABBIX_CONF_DIR}/zabbix_agent2.d/ \ diff --git a/Dockerfiles/agent2/ol/docker-entrypoint.sh b/Dockerfiles/agent2/ol/docker-entrypoint.sh index 858335b9b..c27bb2f3c 100755 --- a/Dockerfiles/agent2/ol/docker-entrypoint.sh +++ b/Dockerfiles/agent2/ol/docker-entrypoint.sh @@ -175,12 +175,14 @@ prepare_zbx_agent_config() { if [ "${ZBX_ENABLEPERSISTENTBUFFER,,}" == "true" ]; then export ZBX_ENABLEPERSISTENTBUFFER=1 + else + unset ZBX_ENABLEPERSISTENTBUFFER fi if [ "${ZBX_ENABLESTATUSPORT,,}" == "true" ]; then export ZBX_STATUSPORT=${ZBX_STATUSPORT="31999"} else - unset ZBX_PERSISTENTBUFFERFILE + unset ZBX_STATUSPORT fi update_config_multiple_var "${ZABBIX_CONF_DIR}/zabbix_agentd_item_keys.conf" "DenyKey" "${ZBX_DENYKEY}" diff --git a/Dockerfiles/agent2/rhel/Dockerfile b/Dockerfiles/agent2/rhel/Dockerfile index aa4946b55..268b6c303 100644 --- a/Dockerfiles/agent2/rhel/Dockerfile +++ b/Dockerfiles/agent2/rhel/Dockerfile @@ -110,7 +110,7 @@ RUN --mount=type=tmpfs,target=/var/lib/dnf/ \ mkdir -p ${ZABBIX_USER_HOME_DIR}/enc && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/enc_internal && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/buffer && \ - mkdir -p ${ZABBIX_USER_HOME_DIR}/user_scripts && \ + mkdir -p ${ZBX_USERPARAMETERDIR} && \ chown --quiet -R zabbix:root ${ZABBIX_CONF_DIR}/zabbix_agent2_item_keys.conf \ ${ZABBIX_CONF_DIR}/zabbix_agentd.d/ \ ${ZABBIX_CONF_DIR}/zabbix_agent2.d/ \ diff --git a/Dockerfiles/agent2/rhel/docker-entrypoint.sh b/Dockerfiles/agent2/rhel/docker-entrypoint.sh index 858335b9b..c27bb2f3c 100755 --- a/Dockerfiles/agent2/rhel/docker-entrypoint.sh +++ b/Dockerfiles/agent2/rhel/docker-entrypoint.sh @@ -175,12 +175,14 @@ prepare_zbx_agent_config() { if [ "${ZBX_ENABLEPERSISTENTBUFFER,,}" == "true" ]; then export ZBX_ENABLEPERSISTENTBUFFER=1 + else + unset ZBX_ENABLEPERSISTENTBUFFER fi if [ "${ZBX_ENABLESTATUSPORT,,}" == "true" ]; then export ZBX_STATUSPORT=${ZBX_STATUSPORT="31999"} else - unset ZBX_PERSISTENTBUFFERFILE + unset ZBX_STATUSPORT fi update_config_multiple_var "${ZABBIX_CONF_DIR}/zabbix_agentd_item_keys.conf" "DenyKey" "${ZBX_DENYKEY}" diff --git a/Dockerfiles/agent2/ubuntu/Dockerfile b/Dockerfiles/agent2/ubuntu/Dockerfile index ab572d55b..cb754299d 100644 --- a/Dockerfiles/agent2/ubuntu/Dockerfile +++ b/Dockerfiles/agent2/ubuntu/Dockerfile @@ -72,7 +72,7 @@ RUN --mount=type=cache,target=/var/cache/apt/,sharing=locked \ mkdir -p ${ZABBIX_USER_HOME_DIR}/enc && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/enc_internal && \ mkdir -p ${ZABBIX_USER_HOME_DIR}/buffer && \ - mkdir -p ${ZABBIX_USER_HOME_DIR}/user_scripts && \ + mkdir -p ${ZBX_USERPARAMETERDIR} && \ chown --quiet -R zabbix:root ${ZABBIX_CONF_DIR}/zabbix_agent2_item_keys.conf \ ${ZABBIX_CONF_DIR}/zabbix_agentd.d/ \ ${ZABBIX_CONF_DIR}/zabbix_agent2.d/ \ diff --git a/Dockerfiles/agent2/ubuntu/docker-entrypoint.sh b/Dockerfiles/agent2/ubuntu/docker-entrypoint.sh index 858335b9b..c27bb2f3c 100755 --- a/Dockerfiles/agent2/ubuntu/docker-entrypoint.sh +++ b/Dockerfiles/agent2/ubuntu/docker-entrypoint.sh @@ -175,12 +175,14 @@ prepare_zbx_agent_config() { if [ "${ZBX_ENABLEPERSISTENTBUFFER,,}" == "true" ]; then export ZBX_ENABLEPERSISTENTBUFFER=1 + else + unset ZBX_ENABLEPERSISTENTBUFFER fi if [ "${ZBX_ENABLESTATUSPORT,,}" == "true" ]; then export ZBX_STATUSPORT=${ZBX_STATUSPORT="31999"} else - unset ZBX_PERSISTENTBUFFERFILE + unset ZBX_STATUSPORT fi update_config_multiple_var "${ZABBIX_CONF_DIR}/zabbix_agentd_item_keys.conf" "DenyKey" "${ZBX_DENYKEY}" diff --git a/Dockerfiles/agent2/windows/Dockerfile b/Dockerfiles/agent2/windows/Dockerfile index 17f0cdf55..a59755c03 100644 --- a/Dockerfiles/agent2/windows/Dockerfile +++ b/Dockerfiles/agent2/windows/Dockerfile @@ -14,6 +14,12 @@ ARG MAJOR_VERSION ARG ZBX_VERSION ARG ZBX_SOURCES=https://git.zabbix.com/scm/zbx/zabbix.git +ENV ZABBIX_USER_HOME_DIR="C:\zabbix" ` + ZABBIX_CONF_DIR="C:\zabbix\conf" + +ENV ZBX_PERSISTENTBUFFERFILE="$ZABBIX_USER_HOME_DIR\buffer\agent2.db" ` + ZBX_USERPARAMETERDIR="${ZABBIX_USER_HOME_DIR}\user_scripts" + LABEL org.opencontainers.image.title="Zabbix agent 2" ` org.opencontainers.image.authors="Alexey Pustovalov " ` org.opencontainers.image.vendor="Zabbix SIA" ` @@ -36,24 +42,27 @@ USER ContainerAdministrator RUN $env:PATH = [string]::Format('{0}\zabbix\sbin;{0}\zabbix\bin;', $env:SystemDrive) + $env:PATH; ` [Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine); ` ` - $env:ZBX_HOME = [string]::Format('{0}\zabbix', $env:SystemDrive); ` - [Environment]::SetEnvironmentVariable('ZBX_HOME', $env:ZBX_HOME, [EnvironmentVariableTarget]::Machine); ` + [Environment]::SetEnvironmentVariable('ZABBIX_USER_HOME_DIR', $env:ZABBIX_USER_HOME_DIR, [EnvironmentVariableTarget]::Machine); ` ` Write-Host ('Verifying Zabbix agent 2 {0} ...' -f $env:ZBX_VERSION); ` zabbix_agent2.exe -V; RUN Set-Location -Path $env:SystemDrive\.; ` ` - New-Item -Force -ItemType directory -Path $env:ZBX_HOME\conf\zabbix_agentd.d | Out-Null; ` - New-Item -Force -ItemType directory -Path $env:ZBX_HOME\enc | Out-Null; ` - New-Item -Force -ItemType directory -Path $env:ZBX_HOME\buffer | Out-Null; ` + New-Item -Force -ItemType directory -Path $env:ZABBIX_CONF_DIR | Out-Null; ` + New-Item -Force -ItemType directory -Path $env:ZABBIX_CONF_DIR\zabbix_agentd.d | Out-Null; ` + New-Item -Force -ItemType directory -Path $env:ZABBIX_CONF_DIR\zabbix_agent2.d | Out-Null; \ + New-Item -Force -ItemType directory -Path $env:ZABBIX_USER_HOME_DIR\enc | Out-Null; ` + New-Item -Force -ItemType directory -Path $env:ZABBIX_USER_HOME_DIR\enc_internal | Out-Null; ` + New-Item -Force -ItemType directory -Path $env:ZABBIX_USER_HOME_DIR\buffer | Out-Null; ` + New-Item -Force -ItemType directory -Path $env:ZBX_USERPARAMETERDIR | Out-Null; ` ` net accounts /MaxPWAge:unlimited; ` net user /add zabbix /expire:never /passwordreq:no; ` - $acl = Get-Acl -Path $env:ZBX_HOME; ` + $acl = Get-Acl -Path $env:ZABBIX_USER_HOME_DIR; ` $ace = New-Object Security.AccessControl.FileSystemAccessRule ('zabbix', 'Modify', 'ContainerInherit, ObjectInherit', 'InheritOnly', 'Allow'); ` $acl.AddAccessRule($ace); ` - Set-Acl -AclObject $acl -Path $env:ZBX_HOME; + Set-Acl -AclObject $acl -Path $env:ZABBIX_USER_HOME_DIR; USER zabbix diff --git a/Dockerfiles/agent2/windows/docker-entrypoint.ps1 b/Dockerfiles/agent2/windows/docker-entrypoint.ps1 index 91a0fe4b9..bd6a0dcb6 100644 --- a/Dockerfiles/agent2/windows/docker-entrypoint.ps1 +++ b/Dockerfiles/agent2/windows/docker-entrypoint.ps1 @@ -4,22 +4,18 @@ if ($env:DEBUG_MODE -eq "true") { Set-PSDebug -trace 1 } -# Default Zabbix installation name # Default Zabbix server host -if ([string]::IsNullOrWhitespace($env:ZBX_SERVER_HOST)) { +if ($env:ZBX_SERVER_HOST -eq $null) { $env:ZBX_SERVER_HOST="zabbix-server" } # Default Zabbix server port number -if ([string]::IsNullOrWhitespace($env:ZBX_SERVER_PORT)) { +if ($env:ZBX_SERVER_PORT -eq $null) { $env:ZBX_SERVER_PORT="10051" } - # Default directories -# User 'zabbix' home directory -$ZabbixUserHomeDir="C:\zabbix" -# Configuration files directory -$ZabbixConfigDir="C:\zabbix\conf" +# Internal directory for TLS related files, used when TLS*File specified as plain text values +$ZabbixInternalEncDir="$env:ZABBIX_USER_HOME_DIR/enc_internal" function Update-Config-Var { Param ( @@ -97,7 +93,7 @@ function Update-Config-Var { Write-Host "added" } else { - Add-Content -Path $ConfigPath -Value "$VarName=$VarValue" + Add-Content -Path $ConfigPath -Value "$VarName=$VarValue" Write-Host "added at the end" } } @@ -119,75 +115,92 @@ function Update-Config-Multiple-Var { } } +function File-Process-From-Env { + Param ( + [Parameter(Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string] $VarName, + [Parameter(Mandatory=$false, Position=1)] + [string]$FileName = $null, + [Parameter(Mandatory=$false, Position=2)] + [string]$VarValue = $null + ) + + if (![string]::IsNullOrEmpty($VarValue)) { + $VarValue | Set-Content "$ZabbixInternalEncDir\VarName" + $FileName="$ZabbixInternalEncDir\VarName" + } + + if (![string]::IsNullOrEmpty($FileName)) { + Set-Item env:$VarName -Value $FileName + } + + $VarName=$VarName -replace 'FILE$' + Set-Item env:$VarName -Value $null +} + function Prepare-Zbx-Agent-Config { - Write-Host "** Preparing Zabbix agent 2 configuration file" + $ZbxAgentConfig="$env:ZABBIX_CONF_DIR\zabbix_agent2.conf" - $ZbxAgentConfig="$ZabbixConfigDir\zabbix_agent2.conf" - - if ([string]::IsNullOrWhitespace($env:ZBX_PASSIVESERVERS)) { + if ($env:ZBX_PASSIVESERVERS -eq $null) { $env:ZBX_PASSIVESERVERS="" } - else { - $env:ZBX_PASSIVESERVERS=",$env:ZBX_PASSIVESERVERS" - } - - $env:ZBX_PASSIVESERVERS=$env:ZBX_SERVER_HOST + $env:ZBX_PASSIVESERVERS - - if ([string]::IsNullOrWhitespace($env:ZBX_ACTIVESERVERS)) { + if ($env:ZBX_ACTIVESERVERS -eq $null) { $env:ZBX_ACTIVESERVERS="" } - else { - $env:ZBX_ACTIVESERVERS=",$env:ZBX_ACTIVESERVERS" + + if (![string]::IsNullOrEmpty($env:ZBX_SERVER_HOST) -And ![string]::IsNullOrEmpty($env:ZBX_PASSIVESERVERS)) { + $env:ZBX_PASSIVESERVERS="$env:ZBX_SERVER_HOST,$env:ZBX_PASSIVESERVERS" + } + elseif (![string]::IsNullOrEmpty($env:ZBX_SERVER_HOST)) { + $env:ZBX_PASSIVESERVERS=$env:ZBX_SERVER_HOST } - $env:ZBX_ACTIVESERVERS=$env:ZBX_SERVER_HOST + ":" + $env:ZBX_SERVER_PORT + $env:ZBX_ACTIVESERVERS - - Update-Config-Var $ZbxAgentConfig "LogType" "console" - Update-Config-Var $ZbxAgentConfig "LogFile" - Update-Config-Var $ZbxAgentConfig "LogFileSize" - Update-Config-Var $ZbxAgentConfig "DebugLevel" "$env:ZBX_DEBUGLEVEL" - Update-Config-Var $ZbxAgentConfig "SourceIP" + if (![string]::IsNullOrEmpty($env:ZBX_SERVER_HOST)) { + if (![string]::IsNullOrEmpty($env:ZBX_SERVER_PORT) -And $env:ZBX_SERVER_PORT -ne "10051") { + $env:ZBX_SERVER_HOST="$env:ZBX_SERVER_HOST:$env:ZBX_SERVER_PORT" + } + if (![string]::IsNullOrEmpty($env:ZBX_ACTIVESERVERS)) { + $env:ZBX_ACTIVESERVERS="$env:ZBX_SERVER_HOST,$env:ZBX_ACTIVESERVERS" + } + else { + $env:ZBX_ACTIVESERVERS=$env:ZBX_SERVER_HOST + } + } if ([string]::IsNullOrWhitespace($env:ZBX_PASSIVE_ALLOW)) { $env:ZBX_PASSIVE_ALLOW="true" } if ($env:ZBX_PASSIVE_ALLOW -eq "true") { - Write-Host "** Using '$env:ZBX_PASSIVESERVERS' servers for passive checks" - Update-Config-Var $ZbxAgentConfig "Server" "$env:ZBX_PASSIVESERVERS" + Write-Host "** Using '$env:ZBX_PASSIVESERVERS' servers for passive checks" } else { - Update-Config-Var $ZbxAgentConfig "Server" + Set-Item env:ZBX_PASSIVESERVERS -Value $null } - Update-Config-Var $ZbxAgentConfig "ListenPort" "$env:ZBX_LISTENPORT" - Update-Config-Var $ZbxAgentConfig "ListenIP" "$env:ZBX_LISTENIP" - if ([string]::IsNullOrWhitespace($env:ZBX_ACTIVE_ALLOW)) { $env:ZBX_ACTIVE_ALLOW="true" } - if ($env:ZBX_PASSIVE_ALLOW -eq "true") { + if ($env:ZBX_ACTIVE_ALLOW -eq "true") { Write-Host "** Using '$env:ZBX_ACTIVESERVERS' servers for active checks" - Update-Config-Var $ZbxAgentConfig "ServerActive" "$env:ZBX_ACTIVESERVERS" } else { - Update-Config-Var $ZbxAgentConfig "ServerActive" + Set-Item env:ZBX_ACTIVESERVERS -Value $null } - Update-Config-Var $ZbxAgentConfig "HeartbeatFrequency" "$env:ZBX_HEARTBEAT_FREQUENCY" - Update-Config-Var $ZbxAgentConfig "ForceActiveChecksOnStart" "$env:ZBX_FORCEACTIVECHECKSONSTART" + Set-Item env:ZBX_SERVER_HOST -Value $null + Set-Item env:ZBX_SERVER_PORT -Value $null if ([string]::IsNullOrWhitespace($env:ZBX_ENABLEPERSISTENTBUFFER)) { $env:ZBX_ENABLEPERSISTENTBUFFER="true" } if ($env:ZBX_ENABLEPERSISTENTBUFFER -eq "true") { - Update-Config-Var $ZbxAgentConfig "EnablePersistentBuffer" "1" - Update-Config-Var $ZbxAgentConfig "PersistentBufferFile" "$ZabbixUserHomeDir\buffer\agent2.db" - Update-Config-Var $ZbxAgentConfig "PersistentBufferPeriod" "$env:ZBX_PERSISTENTBUFFERPERIOD" + $env:ZBX_ENABLEPERSISTENTBUFFER="1" } else { - Update-Config-Var $ZbxAgentConfig "EnablePersistentBuffer" "0" + Set-Item env:ZBX_ENABLEPERSISTENTBUFFER -Value $null } if ([string]::IsNullOrWhitespace($env:ZBX_ENABLESTATUSPORT)) { @@ -195,65 +208,43 @@ function Prepare-Zbx-Agent-Config { } if ($env:ZBX_ENABLESTATUSPORT -eq "true") { - Update-Config-Var $ZbxAgentConfig "StatusPort" "31999" + $env:ZBX_STATUSPORT="31999" } - Update-Config-Var $ZbxAgentConfig "Hostname" "$env:ZBX_HOSTNAME" - Update-Config-Var $ZbxAgentConfig "HostnameItem" "$env:ZBX_HOSTNAMEITEM" - Update-Config-Var $ZbxAgentConfig "HostMetadata" "$env:ZBX_METADATA" - Update-Config-Var $ZbxAgentConfig "HostMetadataItem" "$env:ZBX_METADATAITEM" - Update-Config-Var $ZbxAgentConfig "HostInterface" "$env:ZBX_HOSTINTERFACE" - Update-Config-Var $ZbxAgentConfig "HostInterfaceItem" "$env:ZBX_HOSTINTERFACEITEM" - Update-Config-Var $ZbxAgentConfig "RefreshActiveChecks" "$env:ZBX_REFRESHACTIVECHECKS" - Update-Config-Var $ZbxAgentConfig "BufferSend" "$env:ZBX_BUFFERSEND" - Update-Config-Var $ZbxAgentConfig "BufferSize" "$env:ZBX_BUFFERSIZE" - # Please use include to enable Alias feature -# update_config_multiple_var $ZBX_AGENT_CONFIG "Alias" $env:ZBX_ALIAS - # Please use include to enable Perfcounter feature -# update_config_multiple_var $ZBX_AGENT_CONFIG "PerfCounter" $env:ZBX_PERFCOUNTER - Update-Config-Var $ZbxAgentConfig "Timeout" "$env:ZBX_TIMEOUT" - Update-Config-Var $ZbxAgentConfig "Include" ".\zabbix_agent2.d\plugins.d\*.conf" - Update-Config-Var $ZbxAgentConfig "Include" ".\zabbix_agentd.d\*.conf" $true - Update-Config-Var $ZbxAgentConfig "UnsafeUserParameters" "$env:ZBX_UNSAFEUSERPARAMETERS" - Update-Config-Var $ZbxAgentConfig "UserParameterDir" "$ZabbixUserHomeDir\user_scripts\" - Update-Config-Var $ZbxAgentConfig "TLSConnect" "$env:ZBX_TLSCONNECT" - Update-Config-Var $ZbxAgentConfig "TLSAccept" "$env:ZBX_TLSACCEPT" - Update-Config-Var $ZbxAgentConfig "TLSCAFile" "$env:ZBX_TLSCAFILE" - Update-Config-Var $ZbxAgentConfig "TLSCRLFile" "$env:ZBX_TLSCRLFILE" - Update-Config-Var $ZbxAgentConfig "TLSServerCertIssuer" "$env:ZBX_TLSSERVERCERTISSUER" - Update-Config-Var $ZbxAgentConfig "TLSServerCertSubject" "$env:ZBX_TLSSERVERCERTSUBJECT" - Update-Config-Var $ZbxAgentConfig "TLSCertFile" "$env:ZBX_TLSCERTFILE" - Update-Config-Var $ZbxAgentConfig "TLSCipherAll" "$env:ZBX_TLSCIPHERALL" - Update-Config-Var $ZbxAgentConfig "TLSCipherAll13" "$env:ZBX_TLSCIPHERALL13" - Update-Config-Var $ZbxAgentConfig "TLSCipherCert" "$env:ZBX_TLSCIPHERCERT" - Update-Config-Var $ZbxAgentConfig "TLSCipherCert13" "$env:ZBX_TLSCIPHERCERT13" - Update-Config-Var $ZbxAgentConfig "TLSCipherPSK" "$env:ZBX_TLSCIPHERPSK" - Update-Config-Var $ZbxAgentConfig "TLSCipherPSK13" "$env:ZBX_TLSCIPHERPSK13" - Update-Config-Var $ZbxAgentConfig "TLSKeyFile" "$env:ZBX_TLSKEYFILE" - Update-Config-Var $ZbxAgentConfig "TLSPSKIdentity" "$env:ZBX_TLSPSKIDENTITY" - Update-Config-Var $ZbxAgentConfig "TLSPSKFile" "$env:ZBX_TLSPSKFILE" - - Update-Config-Multiple-Var $ZbxAgentConfig "DenyKey" "$env:ZBX_DENYKEY" - Update-Config-Multiple-Var $ZbxAgentConfig "AllowKey" "$env:ZBX_ALLOWKEY" + Update-Config-Multiple-Var "$env:ZABBIX_CONF_DIR\zabbix_agentd_item_keys.conf" "DenyKey" "$env:ZBX_DENYKEY" + Update-Config-Multiple-Var "$env:ZABBIX_CONF_DIR\zabbix_agentd_item_keys.conf" "AllowKey" "$env:ZBX_ALLOWKEY" + File-Process-From-Env "ZBX_TLSCAFILE" "$env:ZBX_TLSCAFILE" "$env:ZBX_TLSCA" + File-Process-From-Env "ZBX_TLSCRLFILE" "$env:ZBX_TLSCRLFILE" "$env:ZBX_TLSCRL" + File-Process-From-Env "ZBX_TLSCERTFILE" "$env:ZBX_TLSCERTFILE" "$env:ZBX_TLSCERT" + File-Process-From-Env "ZBX_TLSKEYFILE" "$env:ZBX_TLSKEYFILE" "$env:ZBX_TLSKEY" + File-Process-From-Env "ZBX_TLSPSKFILE" "$env:ZBX_TLSPSKFILE" "$env:ZBX_TLSPSK" } function Prepare-Zbx-Agent-Plugins-Config { Write-Host "** Preparing Zabbix agent 2 (plugins) configuration files" - Update-Config-Var "$ZabbixConfigDir\zabbix_agent2.d\plugins.d\mongodb.conf" "Plugins.MongoDB.System.Path" "$ZabbixUserHomeDir\zabbix-agent2-plugin\mongodb.exe" - Update-Config-Var "$ZabbixConfigDir\zabbix_agent2.d\plugins.d\postgresql.conf" "Plugins.PostgreSQL.System.Path" "$ZabbixUserHomeDir\zabbix-agent2-plugin\postgresql.exe" - Update-Config-Var "$ZabbixConfigDir\zabbix_agent2.d\plugins.d\mssql.conf" "Plugins.MSSQL.System.Path" "$ZabbixUserHomeDir\zabbix-agent2-plugin\mssql.exe" - Update-Config-Var "$ZabbixConfigDir\zabbix_agent2.d\plugins.d\ember.conf" "Plugins.EmberPlus.System.Path" "$ZabbixUserHomeDir\zabbix-agent2-plugin\ember-plus.exe" + Update-Config-Var "$env:ZABBIX_CONF_DIR\zabbix_agent2.d\plugins.d\mongodb.conf" "Plugins.MongoDB.System.Path" "$ZabbixUserHomeDir\zabbix-agent2-plugin\mongodb.exe" + Update-Config-Var "$env:ZABBIX_CONF_DIR\zabbix_agent2.d\plugins.d\postgresql.conf" "Plugins.PostgreSQL.System.Path" "$ZabbixUserHomeDir\zabbix-agent2-plugin\postgresql.exe" + Update-Config-Var "$env:ZABBIX_CONF_DIR\zabbix_agent2.d\plugins.d\mssql.conf" "Plugins.MSSQL.System.Path" "$ZabbixUserHomeDir\zabbix-agent2-plugin\mssql.exe" + Update-Config-Var "$env:ZABBIX_CONF_DIR\zabbix_agent2.d\plugins.d\ember.conf" "Plugins.EmberPlus.System.Path" "$ZabbixUserHomeDir\zabbix-agent2-plugin\ember-plus.exe" if (Get-Command nvidia-smi.exe -errorAction SilentlyContinue) { - Update-Config-Var "$ZabbixConfigDir\zabbix_agent2.d\plugins.d\nvidia.conf" "Plugins.NVIDIA.System.Path" "$ZabbixUserHomeDir\zabbix-agent2-plugin\nvidia-gpu.exe" + Update-Config-Var "$env:ZABBIX_CONF_DIR\zabbix_agent2.d\plugins.d\nvidia.conf" "Plugins.NVIDIA.System.Path" "$ZabbixUserHomeDir\zabbix-agent2-plugin\nvidia-gpu.exe" + } +} + +function ClearZbxEnv() { + if ([string]::IsNullOrWhitespace($env:ZBX_CLEAR_ENV)) { + return } } function PrepareAgent { Write-Host "** Preparing Zabbix agent 2" + Prepare-Zbx-Agent-Config Prepare-Zbx-Agent-Plugins-Config + ClearZbxEnv } $commandArgs=$args diff --git a/Dockerfiles/build-mysql/windows/Dockerfile.agent2 b/Dockerfiles/build-mysql/windows/Dockerfile.agent2 index ca5214b23..a50302f3e 100644 --- a/Dockerfiles/build-mysql/windows/Dockerfile.agent2 +++ b/Dockerfiles/build-mysql/windows/Dockerfile.agent2 @@ -76,7 +76,7 @@ RUN Set-Location -Path $env:SystemDrive\.; ` Copy-Item -Path $env:ZBX_SOURCES_DIR\bin\win64\zabbix_agent2.exe $env:ZBX_OUTPUT_DIR\sbin; ` Copy-Item -Path $env:ZBX_SOURCES_DIR\src\go\conf\zabbix_agent2.win.conf $env:ZBX_OUTPUT_DIR\conf\zabbix_agent2.conf_template; ` Copy-Item -Recurse -Path $env:ZBX_SOURCES_DIR\src\go\conf\zabbix_agent2.d $env:ZBX_OUTPUT_DIR\conf\zabbix_agent2.d; ` - Copy-Item -Recurse -Path $env:SystemDrive\config_templates\agent2 $env:ZBX_OUTPUT_DIR\conf; ` + Copy-Item -Recurse -Path $env:SystemDrive\config_templates\agent2\* $env:ZBX_OUTPUT_DIR\conf; ` mingw32-make -s clean; ` ` Write-Host ('Building Zabbix MongoDB plugin {0} version ...' -f $env:MONGODB_PLUGIN_VERSION); `