From 811ca706893f4f5e7d959de6f3f385dcc38706eb Mon Sep 17 00:00:00 2001 From: Alexey Pustovalov Date: Mon, 30 Dec 2024 16:29:20 +0000 Subject: [PATCH] Fixed Windows containers building --- Dockerfiles/agent/windows/Dockerfile | 6 +- .../agent/windows/docker-entrypoint.ps1 | 102 ++++++++++-------- .../build-mysql/windows/Dockerfile.agent | 2 +- 3 files changed, 61 insertions(+), 49 deletions(-) diff --git a/Dockerfiles/agent/windows/Dockerfile b/Dockerfiles/agent/windows/Dockerfile index 11e154f4e..bc896e45a 100644 --- a/Dockerfiles/agent/windows/Dockerfile +++ b/Dockerfiles/agent/windows/Dockerfile @@ -14,11 +14,10 @@ ARG MAJOR_VERSION ARG ZBX_VERSION ARG ZBX_SOURCES=https://git.zabbix.com/scm/zbx/zabbix.git -ENV ZABBIX_USER_HOME_DIR="C:\zabbix" \ +ENV ZABBIX_USER_HOME_DIR="C:\zabbix" ` ZABBIX_CONF_DIR="C:\zabbix\conf" -ENV ZBX_LOADMODULEPATH="${ZABBIX_USER_HOME_DIR}/modules" \ - ZBX_USERPARAMETERDIR=${ZABBIX_USER_HOME_DIR}/user_scripts +ENV ZBX_USERPARAMETERDIR="${ZABBIX_USER_HOME_DIR}\user_scripts" LABEL org.opencontainers.image.title="Zabbix agent" ` org.opencontainers.image.authors="Alexey Pustovalov " ` @@ -53,7 +52,6 @@ RUN Set-Location -Path $env:SystemDrive\.; ` New-Item -Force -ItemType directory -Path $env:ZABBIX_CONF_DIR\zabbix_agentd.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\buffer | Out-Null; ` - New-Item -Force -ItemType directory -Path $env:ZBX_LOADMODULEPATH | Out-Null; ` New-Item -Force -ItemType directory -Path $env:ZBX_USERPARAMETERDIR | Out-Null; ` ` net accounts /MaxPWAge:unlimited; ` diff --git a/Dockerfiles/agent/windows/docker-entrypoint.ps1 b/Dockerfiles/agent/windows/docker-entrypoint.ps1 index b7b9e0d1b..b56c397ed 100644 --- a/Dockerfiles/agent/windows/docker-entrypoint.ps1 +++ b/Dockerfiles/agent/windows/docker-entrypoint.ps1 @@ -6,11 +6,11 @@ if ($env:DEBUG_MODE -eq "true") { # 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" } @@ -117,35 +117,58 @@ 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$' + Write-Host "** $VarName" + Set-Item env:$VarName -Value $null +} + function Prepare-Zbx-Agent-Config { - Write-Host "** Preparing Zabbix agent configuration file" - $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 ([string]::IsNullOrWhitespace($env:ZBX_PASSIVESERVERS)) { - $env:ZBX_PASSIVESERVERS="" + if (![string]::IsNullOrEmpty($env:ZBX_SERVER_HOST) -And ![string]::IsNullOrEmpty($env:ZBX_PASSIVESERVERS)) { + $env:ZBX_PASSIVESERVERS="$env:ZBX_SERVER_HOST,$env:ZBX_PASSIVESERVERS" } - else { - $env:ZBX_PASSIVESERVERS=",$env:ZBX_PASSIVESERVERS" + elseif (![string]::IsNullOrEmpty($env:ZBX_SERVER_HOST)) { + $env:ZBX_PASSIVESERVERS=$env:ZBX_SERVER_HOST } - $env:ZBX_PASSIVESERVERS=$env:ZBX_SERVER_HOST + $env:ZBX_PASSIVESERVERS - - if ([string]::IsNullOrWhitespace($env:ZBX_ACTIVESERVERS)) { - $env:ZBX_ACTIVESERVERS="" - } - else { - $env:ZBX_ACTIVESERVERS=",$env:ZBX_ACTIVESERVERS" - } - - $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" - Update-Config-Var $ZbxAgentConfig "LogRemoteCommands" "$env:ZBX_LOGREMOTECOMMANDS" + 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" @@ -153,10 +176,9 @@ function Prepare-Zbx-Agent-Config { 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" } else { - Update-Config-Var $ZbxAgentConfig "Server" + Set-Item env:ZBX_PASSIVESERVERS -Value $null } if ([string]::IsNullOrWhitespace($env:ZBX_ACTIVE_ALLOW)) { @@ -165,29 +187,21 @@ function Prepare-Zbx-Agent-Config { 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 } - # 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-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-Var $ZbxAgentConfig "TLSCAFile" "$env:ZBX_TLSCAFILE" - Update-Config-Var $ZbxAgentConfig "TLSCRLFile" "$env:ZBX_TLSCRLFILE" - Update-Config-Var $ZbxAgentConfig "TLSCertFile" "$env:ZBX_TLSCERTFILE" - 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 "TLSPSKFile" "$env:ZBX_TLSPSKFILE" +# Update-Config-Multiple-Var "$env:ZABBIX_CONF_DIR\zabbix_agentd_modules.conf" "LoadModule" "$env:LOADMODULE" - Update-Config-Multiple-Var $ZbxAgentConfig "DenyKey" "$env:ZBX_DENYKEY" - Update-Config-Multiple-Var $ZbxAgentConfig "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 ClearZbxEnv() { diff --git a/Dockerfiles/build-mysql/windows/Dockerfile.agent b/Dockerfiles/build-mysql/windows/Dockerfile.agent index cb6d61113..104a26315 100644 --- a/Dockerfiles/build-mysql/windows/Dockerfile.agent +++ b/Dockerfiles/build-mysql/windows/Dockerfile.agent @@ -73,5 +73,5 @@ RUN Set-Location -Path $env:SystemDrive\.; ` Copy-Item -Path $env:ZBX_SOURCES_DIR\bin\win64\zabbix_get.exe $env:ZBX_OUTPUT_DIR\bin; ` Copy-Item -Path $env:ZBX_SOURCES_DIR\bin\win64\zabbix_sender.exe $env:ZBX_OUTPUT_DIR\bin; ` Copy-Item -Path $env:ZBX_SOURCES_DIR\conf\zabbix_agentd.win.conf $env:ZBX_OUTPUT_DIR\conf\zabbix_agentd.conf_template; ` - Copy-Item -Recurse -Path $env:SystemDrive\config_templates\agent $env:ZBX_OUTPUT_DIR\conf\; ` + Copy-Item -Recurse -Path $env:SystemDrive\config_templates\agent\* $env:ZBX_OUTPUT_DIR\conf\; ` Write-Host 'Zabbix binaries are compiled...';