diff --git a/scripts/install.ps1 b/scripts/install.ps1 index 79b6d00..97a6ac9 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -10,7 +10,8 @@ param ( [bool]$EnableHost = $true, [bool]$EnableDocker = $false, [bool]$Insecure = $false, - [bool]$Uninstall = $false + [bool]$Uninstall = $false, + [string]$AgentId = "" ) $ErrorActionPreference = "Stop" @@ -292,6 +293,7 @@ $ServiceArgs = @( if ($EnableHost) { $ServiceArgs += "--enable-host" } if ($EnableDocker) { $ServiceArgs += "--enable-docker" } if ($Insecure) { $ServiceArgs += "--insecure" } +if (-not [string]::IsNullOrWhiteSpace($AgentId)) { $ServiceArgs += @("--agent-id", "`"$AgentId`"") } $BinPath = "`"$DestPath`" $($ServiceArgs -join ' ')" diff --git a/scripts/install.sh b/scripts/install.sh index f02f1cc..9fbe5df 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -10,6 +10,7 @@ # --enable-host Enable host metrics (default: true) # --enable-docker Enable docker metrics (default: false) # --interval Reporting interval (default: 30s) +# --agent-id Custom agent identifier (default: auto-generated) # --uninstall Remove the agent set -euo pipefail @@ -48,6 +49,7 @@ ENABLE_HOST="true" ENABLE_DOCKER="false" UNINSTALL="false" INSECURE="false" +AGENT_ID="" # --- Helper Functions --- log_info() { printf "[INFO] %s\n" "$1"; } @@ -70,6 +72,7 @@ build_exec_args() { if [[ "$ENABLE_HOST" == "true" ]]; then EXEC_ARGS="$EXEC_ARGS --enable-host"; fi if [[ "$ENABLE_DOCKER" == "true" ]]; then EXEC_ARGS="$EXEC_ARGS --enable-docker"; fi if [[ "$INSECURE" == "true" ]]; then EXEC_ARGS="$EXEC_ARGS --insecure"; fi + if [[ -n "$AGENT_ID" ]]; then EXEC_ARGS="$EXEC_ARGS --agent-id ${AGENT_ID}"; fi } # Build exec args as array for direct execution (proper quoting) @@ -79,6 +82,7 @@ build_exec_args_array() { if [[ "$ENABLE_HOST" == "true" ]]; then EXEC_ARGS_ARRAY+=(--enable-host); fi if [[ "$ENABLE_DOCKER" == "true" ]]; then EXEC_ARGS_ARRAY+=(--enable-docker); fi if [[ "$INSECURE" == "true" ]]; then EXEC_ARGS_ARRAY+=(--insecure); fi + if [[ -n "$AGENT_ID" ]]; then EXEC_ARGS_ARRAY+=(--agent-id "$AGENT_ID"); fi } # --- Parse Arguments --- @@ -93,6 +97,7 @@ while [[ $# -gt 0 ]]; do --disable-docker) ENABLE_DOCKER="false"; shift ;; --insecure) INSECURE="true"; shift ;; --uninstall) UNINSTALL="true"; shift ;; + --agent-id) AGENT_ID="$2"; shift 2 ;; *) fail "Unknown argument: $1" ;; esac done @@ -305,6 +310,11 @@ if [[ "$OS" == "darwin" ]]; then PLIST_ARGS="${PLIST_ARGS} --insecure" fi + if [[ -n "$AGENT_ID" ]]; then + PLIST_ARGS="${PLIST_ARGS} + --agent-id + ${AGENT_ID}" + fi cat > "$PLIST" <