Skip to content

Commit 73e69a4

Browse files
committed
19505 FIX Windows agent command compatibility
The commands to download and register the Windows agent in the agent registration slide-out were not compatible with both CMD and Powershell. Avoid compatibility problems with older versions of Powershell that don't support `&&` by splitting the Windows download and installation command into two: one for download and a second one for installation. Additionally, avoid compatibility problems with Powershell by not splitting the registration command into multiple lines using `^`. CMK-32105 Change-Id: Iefcaa56f154f9293d59a834f849aac3686765d8d
1 parent ec78725 commit 73e69a4

File tree

6 files changed

+57
-11
lines changed

6 files changed

+57
-11
lines changed

.werks/19505.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[//]: # (werk v3)
2+
# Fix Windows agent command compatibility issues
3+
4+
key | value
5+
---------- | ---
6+
date | 2026-03-20T12:14:08.081364+00:00
7+
version | 2.5.0b2
8+
class | fix
9+
edition | community
10+
component | wato
11+
level | 1
12+
compatible | yes
13+
14+
The commands to download and register the Windows agent in the agent
15+
registration slide-out were not compatible with both CMD and Powershell.
16+
17+
Avoid compatibility problems with older versions of Powershell that
18+
don't support `&&` by splitting the Windows download and installation
19+
command into two: one for download and a second one for installation.
20+
21+
Additionally, avoid compatibility problems with Powershell by not
22+
splitting the registration command into multiple lines using `^`.

cmk/gui/utils/agent_commands.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@
2929
from cmk.shared_typing.setup import AgentRegistrationCmds as SetupAgentRegistrationCmds
3030
from cmk.shared_typing.setup import AgentSlideout as SetupAgentSlideout
3131

32-
WINDOWS_AGENT_INSTALL_CMD = (
32+
WINDOWS_AGENT_DOWNLOAD_CMD = (
3333
"curl.exe -o check-mk-agent_{version}.msi"
3434
' "{{{{SERVER}}}}/{{{{SITE}}}}/check_mk/api/internal/domain-types/agent/actions/download_by_token/invoke"'
3535
' --header "Accept: application/octet-stream"'
3636
' --header "Authorization: CMK-TOKEN 0:[AGENT_DOWNLOAD_OTT]"'
3737
' --data-urlencode "os_type=windows_msi"'
38-
" && msiexec /i check-mk-agent_{version}.msi"
3938
)
4039

40+
WINDOWS_AGENT_INSTALL_CMD = "msiexec /i check-mk-agent_{version}.msi"
41+
4142
LINUX_DEBIAN_AGENT_INSTALL_CMD = """curl -o check-mk-agent_{version}-1_all.deb -fJG \\
4243
'{{{{SERVER}}}}/{{{{SITE}}}}/check_mk/api/internal/domain-types/agent/actions/download_by_token/invoke' \\
4344
--header 'Accept: application/octet-stream' \\
@@ -58,17 +59,20 @@ def build_agent_install_cmds(
5859
hostname: HostName,
5960
) -> AgentInstallCmds:
6061
return AgentInstallCmds(
62+
windows_download=WINDOWS_AGENT_DOWNLOAD_CMD.format(version=version),
6163
windows=WINDOWS_AGENT_INSTALL_CMD.format(version=version),
6264
linux_deb=LINUX_DEBIAN_AGENT_INSTALL_CMD.format(version=version),
6365
linux_rpm=LINUX_RPM_AGENT_INSTALL_CMD.format(version=version),
6466
)
6567

6668

67-
WINDOWS_AGENT_REGISTRATION_CMD = """\"C:\\Program Files (x86)\\checkmk\\service\\cmk-agent-ctl.exe\" register ^
68-
--hostname {{HOSTNAME}} ^
69-
--server {{SERVER}} ^
70-
--site {{SITE}} ^
71-
--user agent_registration"""
69+
WINDOWS_AGENT_REGISTRATION_CMD = (
70+
'"C:\\Program Files (x86)\\checkmk\\service\\cmk-agent-ctl.exe" register'
71+
" --hostname {{HOSTNAME}}"
72+
" --server {{SERVER}}"
73+
" --site {{SITE}}"
74+
" --user agent_registration"
75+
)
7276

7377
LINUX_REGISTRATION_CMD = """sudo cmk-agent-ctl register \\
7478
--hostname {{HOSTNAME}} \\

packages/cmk-frontend-vue/src/mode-host/agent-connection-test/components/AgentSlideOut.vue

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,31 @@ function getInitStep() {
203203
<GenerateToken
204204
v-model="ott"
205205
token-generation-endpoint-uri="domain-types/agent_download_token/collections/all"
206-
:description="_t('This requires the generation of a download token.')"
206+
:description="
207+
_t(
208+
'To securely fetch the latest agent package via the command line, you must first generate a temporary authentication token. ' +
209+
'This token is valid for 7 days and is used solely for the download process'
210+
)
211+
"
207212
:expires-in-seconds="604800"
208213
:token-generation-body="{}"
209214
/>
210215
</div>
211216
<template v-if="ott !== null">
217+
<template v-if="tab.installDownloadCmd">
218+
<CmkCode
219+
:title="_t('Download agent')"
220+
:code_txt="installCmdWithToken(tab.installDownloadCmd)"
221+
class="code"
222+
/>
223+
<CmkCode
224+
:title="_t('Install agent')"
225+
:code_txt="tab.installCmd || ''"
226+
class="code"
227+
/>
228+
</template>
212229
<CmkCode
213-
v-if="tab.installMsg && tab.installCmd"
230+
v-else-if="tab.installMsg && tab.installCmd"
214231
:code_txt="installCmdWithToken(tab.installCmd)"
215232
class="code"
216233
/>

packages/cmk-frontend-vue/src/mode-host/agent-connection-test/components/AgentSlideOutContent.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ const tabs = computed<AgentSlideOutTabs[]>(() => [
8585
id: 'windows',
8686
title: _t('Windows'),
8787
installMsg: _t(
88-
'Run this command on your Windows host to download and install the Checkmk agent. Please make sure to run this command with sufficient permissions (e.g. "Run as Administrator")'
88+
'Run these commands on your Windows host to download and install the Checkmk agent. Please make sure to run these commands with sufficient permissions (e.g. "Run as Administrator")'
8989
),
90+
installDownloadCmd: replaceMacros(props.agentInstallCmds.windows_download, false),
9091
installCmd: replaceMacros(props.agentInstallCmds.windows, false),
9192
registrationMsg: _t(
9293
'After you have downloaded the agent, run this command on your Windows host to register the Checkmk agent controller. Please make sure to run this command with sufficient permissions (e.g. "Run as Administrator").'

packages/cmk-frontend-vue/src/mode-host/agent-connection-test/lib/type_def.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface AgentSlideOutTabs {
1818
title: string
1919
installMsg?: TranslatedString
2020
installCmd?: string | undefined
21+
installDownloadCmd?: string
2122
installDebCmd?: string
2223
installRpmCmd?: string
2324
installTgzCmd?: string | undefined

packages/cmk-shared-typing/source/agent_slideout.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626
"agent_install_cmds": {
2727
"type": "object",
2828
"properties": {
29+
"windows_download": { "type": "string" },
2930
"windows": { "type": "string" },
3031
"linux_deb": { "type": "string" },
3132
"linux_rpm": { "type": "string" },
3233
"linux_tgz": { "type": "string" },
3334
"solaris": { "type": "string" },
3435
"aix": { "type": "string" }
3536
},
36-
"required": ["windows", "linux_deb", "linux_rpm"]
37+
"required": ["windows_download", "windows", "linux_deb", "linux_rpm"]
3738
},
3839
"agent_registration_cmds": {
3940
"type": "object",

0 commit comments

Comments
 (0)