Add agent-id support to host agent installers (Related to #721)

This commit is contained in:
rcourtman 2025-11-20 18:14:18 +00:00
parent 516097990a
commit 18b0323340
3 changed files with 43 additions and 1 deletions

View file

@ -201,6 +201,18 @@ Start-Service -Name PulseHostAgent
Run `pulse-host-agent --help` for the full list. Run `pulse-host-agent --help` for the full list.
## Avoiding ID collisions
Pulse keys hosts on the identifier supplied by the agent (machine-id by default). Cloned systems frequently share `/etc/machine-id`, which makes Pulse alternate a single row between multiple machines. Keep the ID unique by regenerating the machine-id on each clone or by providing an explicit `--agent-id`/`PULSE_AGENT_ID` when installing:
```bash
sudo rm /etc/machine-id /var/lib/dbus/machine-id
sudo systemd-machine-id-setup
sudo systemctl restart pulse-host-agent
```
Re-running the installer with `--agent-id <unique-name>` achieves the same result if regenerating the machine-id is undesirable.
## Viewing Hosts ## Viewing Hosts
- **Settings → Agents → Host agents** lists every reporting host and provides ready-made install commands. - **Settings → Agents → Host agents** lists every reporting host and provides ready-made install commands.

View file

@ -11,6 +11,7 @@ param(
[string]$PulseUrl = $env:PULSE_URL, [string]$PulseUrl = $env:PULSE_URL,
[string]$Token = $env:PULSE_TOKEN, [string]$Token = $env:PULSE_TOKEN,
[string]$Interval = $env:PULSE_INTERVAL, [string]$Interval = $env:PULSE_INTERVAL,
[string]$AgentId = $env:PULSE_AGENT_ID,
[string]$InstallPath = "C:\Program Files\Pulse", [string]$InstallPath = "C:\Program Files\Pulse",
[string]$Arch = $env:PULSE_ARCH, [string]$Arch = $env:PULSE_ARCH,
[switch]$NoService [switch]$NoService
@ -251,6 +252,7 @@ if (-not $Interval) {
PulseInfo "Configuration:" PulseInfo "Configuration:"
Write-Host " Pulse URL: $PulseUrl" Write-Host " Pulse URL: $PulseUrl"
Write-Host " Token: $(if ($Token) { '***' + $Token.Substring([Math]::Max(0, $Token.Length - 4)) } else { 'none' })" Write-Host " Token: $(if ($Token) { '***' + $Token.Substring([Math]::Max(0, $Token.Length - 4)) } else { 'none' })"
Write-Host " Agent ID: $(if ($AgentId) { $AgentId } else { 'machine-id (default)' })"
Write-Host " Interval: $Interval" Write-Host " Interval: $Interval"
Write-Host " Install Path: $InstallPath" Write-Host " Install Path: $InstallPath"
if ($Arch) { if ($Arch) {
@ -381,6 +383,9 @@ try {
if ($Token) { if ($Token) {
$agentArgs += @("--token", "`"$Token`"") $agentArgs += @("--token", "`"$Token`"")
} }
if ($AgentId) {
$agentArgs += @("--agent-id", "`"$AgentId`"")
}
$serviceBinaryPath = "`"$agentPath`" $($agentArgs -join ' ')" $serviceBinaryPath = "`"$agentPath`" $($agentArgs -join ' ')"
$manualCommand = "& `"$agentPath`" $($agentArgs -join ' ')" $manualCommand = "& `"$agentPath`" $($agentArgs -join ' ')"
} catch { } catch {
@ -397,6 +402,9 @@ $config = @{
if ($Token) { if ($Token) {
$config.token = $Token $config.token = $Token
} }
if ($AgentId) {
$config.agentId = $AgentId
}
$config | ConvertTo-Json | Set-Content $configPath $config | ConvertTo-Json | Set-Content $configPath
PulseSuccess "Created configuration at $configPath" PulseSuccess "Created configuration at $configPath"

View file

@ -71,6 +71,7 @@ KEYCHAIN_ENABLED=true
KEYCHAIN_OPT_OUT=false KEYCHAIN_OPT_OUT=false
KEYCHAIN_OPT_OUT_REASON="" KEYCHAIN_OPT_OUT_REASON=""
USE_KEYCHAIN=false USE_KEYCHAIN=false
AGENT_ID="${PULSE_AGENT_ID:-}"
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case "$1" in case "$1" in
@ -86,6 +87,10 @@ while [[ $# -gt 0 ]]; do
INTERVAL="$2" INTERVAL="$2"
shift 2 shift 2
;; ;;
--agent-id)
AGENT_ID="$2"
shift 2
;;
--platform) --platform)
PLATFORM="$2" PLATFORM="$2"
shift 2 shift 2
@ -162,9 +167,10 @@ fi
if [[ -z "$PULSE_URL" ]]; then if [[ -z "$PULSE_URL" ]]; then
log_error "Pulse URL is required" log_error "Pulse URL is required"
echo "Usage: $0 --url <pulse-url> --token <api-token> [--interval 30s] [--platform linux|darwin|windows] [--force] [--no-keychain]" echo "Usage: $0 --url <pulse-url> --token <api-token> [--interval 30s] [--agent-id <id>] [--platform linux|darwin|windows] [--force] [--no-keychain]"
echo "" echo ""
echo " --force Skip interactive prompts and accept secure defaults (including Keychain storage)." echo " --force Skip interactive prompts and accept secure defaults (including Keychain storage)."
echo " --agent-id Override the identifier used to deduplicate hosts (defaults to machine-id)."
echo " --no-keychain Disable Keychain storage and embed the token in the launch agent plist instead." echo " --no-keychain Disable Keychain storage and embed the token in the launch agent plist instead."
exit 1 exit 1
fi fi
@ -234,6 +240,11 @@ if [[ -n "$PULSE_TOKEN" ]]; then
else else
echo " Token: none" echo " Token: none"
fi fi
if [[ -n "$AGENT_ID" ]]; then
echo " Agent ID: $AGENT_ID"
else
echo " Agent ID: machine-id (default)"
fi
echo " Interval: $INTERVAL" echo " Interval: $INTERVAL"
echo " Platform: $PLATFORM/$ARCH" echo " Platform: $PLATFORM/$ARCH"
echo "" echo ""
@ -406,6 +417,9 @@ if [[ -n "$PULSE_TOKEN" ]]; then
AGENT_CMD="$AGENT_CMD --token $PULSE_TOKEN" AGENT_CMD="$AGENT_CMD --token $PULSE_TOKEN"
fi fi
AGENT_CMD="$AGENT_CMD --interval $INTERVAL" AGENT_CMD="$AGENT_CMD --interval $INTERVAL"
if [[ -n "$AGENT_ID" ]]; then
AGENT_CMD="$AGENT_CMD --agent-id $AGENT_ID"
fi
MANUAL_START_CMD="$AGENT_CMD" MANUAL_START_CMD="$AGENT_CMD"
MANUAL_START_WRAPPED="nohup $MANUAL_START_CMD >$LINUX_LOG_FILE 2>&1 &" MANUAL_START_WRAPPED="nohup $MANUAL_START_CMD >$LINUX_LOG_FILE 2>&1 &"
@ -529,6 +543,12 @@ elif [[ "$PLATFORM" == "darwin" ]] && command -v launchctl &> /dev/null; then
USE_KEYCHAIN=false USE_KEYCHAIN=false
fi fi
LAUNCHD_AGENT_ID_ARGS=""
if [[ -n "$AGENT_ID" ]]; then
LAUNCHD_AGENT_ID_ARGS=" <string>--agent-id</string>
<string>$AGENT_ID</string>"
fi
# Create wrapper script if using Keychain # Create wrapper script if using Keychain
if [[ "$USE_KEYCHAIN" == true ]]; then if [[ "$USE_KEYCHAIN" == true ]]; then
WRAPPER_SCRIPT="/usr/local/bin/pulse-host-agent-wrapper.sh" WRAPPER_SCRIPT="/usr/local/bin/pulse-host-agent-wrapper.sh"
@ -588,6 +608,7 @@ WRAPPER_EOF
<string>$PULSE_URL</string> <string>$PULSE_URL</string>
<string>--interval</string> <string>--interval</string>
<string>$INTERVAL</string> <string>$INTERVAL</string>
$LAUNCHD_AGENT_ID_ARGS
</array> </array>
<key>RunAtLoad</key> <key>RunAtLoad</key>
<true/> <true/>
@ -619,6 +640,7 @@ EOF
<string>$PULSE_TOKEN</string> <string>$PULSE_TOKEN</string>
<string>--interval</string> <string>--interval</string>
<string>$INTERVAL</string> <string>$INTERVAL</string>
$LAUNCHD_AGENT_ID_ARGS
</array> </array>
<key>RunAtLoad</key> <key>RunAtLoad</key>
<true/> <true/>