From 2108d09f6afd8cc9801ed5acc767502aea0d689d Mon Sep 17 00:00:00 2001 From: yumusb <43062104+yumusb@users.noreply.github.com> Date: Thu, 15 Jan 2026 19:34:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=20name=20=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/handler/agent_install_handler.go | 25 ++++++- web/src/admin/pages/Agents/AgentInstall.tsx | 80 +++++++++++++-------- 2 files changed, 74 insertions(+), 31 deletions(-) diff --git a/internal/handler/agent_install_handler.go b/internal/handler/agent_install_handler.go index 10b570d..021e796 100644 --- a/internal/handler/agent_install_handler.go +++ b/internal/handler/agent_install_handler.go @@ -111,6 +111,25 @@ echo_warn() { echo -e "${YELLOW}[WARN]${NC} $1" } +# 解析参数 +AGENT_NAME_CUSTOM="" +while [[ $# -gt 0 ]]; do + case $1 in + --name) + AGENT_NAME_CUSTOM="$2" + shift # past argument + shift # past value + ;; + *) + shift # past argument + ;; + esac +done + +if [ -n "$AGENT_NAME_CUSTOM" ]; then + echo_info "使用自定义探针名称: $AGENT_NAME_CUSTOM" +fi + # 检测操作系统和架构 detect_platform() { OS=$(uname -s | awk '{print tolower($0)}') @@ -187,7 +206,11 @@ register_agent() { local token="` + token + `" echo_info "正在注册探针..." - /usr/local/bin/$AGENT_NAME register --endpoint "$endpoint" --token "$token" --yes + if [ -n "$AGENT_NAME_CUSTOM" ]; then + /usr/local/bin/$AGENT_NAME register --endpoint "$endpoint" --token "$token" --name "$AGENT_NAME_CUSTOM" --yes + else + /usr/local/bin/$AGENT_NAME register --endpoint "$endpoint" --token "$token" --yes + fi } # 主流程 diff --git a/web/src/admin/pages/Agents/AgentInstall.tsx b/web/src/admin/pages/Agents/AgentInstall.tsx index def105b..4e436af 100644 --- a/web/src/admin/pages/Agents/AgentInstall.tsx +++ b/web/src/admin/pages/Agents/AgentInstall.tsx @@ -1,5 +1,5 @@ import React, { type ReactElement, useCallback, useEffect, useMemo, useState } from 'react'; -import { Alert, App, Button, Card, Select, Space, Tabs, Typography } from 'antd'; +import { Alert, App, Button, Card, Select, Space, Tabs, Typography, Input } from 'antd'; import { CopyIcon } from 'lucide-react'; import { listApiKeys } from '@/api/apiKey.ts'; import { getServerUrl } from '@/api/agent.ts'; @@ -37,6 +37,7 @@ const AgentInstall = () => { const [selectedOS, setSelectedOS] = useState(DEFAULT_OS); const [apiKeys, setApiKeys] = useState([]); const [selectedApiKey, setSelectedApiKey] = useState(''); + const [customHostname, setCustomHostname] = useState(''); const [loading, setLoading] = useState(true); // 服务器地址相关状态 @@ -131,8 +132,12 @@ const AgentInstall = () => { if (!backendServerUrl || !selectedApiKey) { return ''; } - return `curl -fsSL ${backendServerUrl}/api/agent/install.sh?token=${selectedApiKey} | sudo bash`; - }, [backendServerUrl, selectedApiKey]); + let cmd = `curl -fsSL ${backendServerUrl}/api/agent/install.sh?token=${selectedApiKey} | sudo bash`; + if (customHostname) { + cmd = `curl -fsSL ${backendServerUrl}/api/agent/install.sh?token=${selectedApiKey} | sudo bash -s -- --name "${customHostname}"`; + } + return cmd; + }, [backendServerUrl, selectedApiKey, customHostname]); // API Key 选择器选项 const apiKeyOptions = useMemo( @@ -207,35 +212,50 @@ const AgentInstall = () => { ); }, [backendServerUrl, frontendUrl]); - // API Token 选择组件 const ApiChooser = useCallback(() => ( - + - {apiKeys.length === 0 ? ( - - 请先前往 API密钥管理 页面生成一个 API Token - - } - type="warning" - showIcon - className="mt-2" +
+
选择 API Token
+ {apiKeys.length === 0 ? ( + + 请先前往 API密钥管理 页面生成一个 API Token + + } + type="warning" + showIcon + className="mt-2" + /> + ) : ( + setCustomHostname(e.target.value)} + className="w-full" + allowClear /> - ) : ( -