[ Agent ] [ Status ] - accomplish agent info part

This commit is contained in:
zeaslity
2024-01-18 15:56:07 +08:00
parent d1671bbe77
commit 86b6484194
6 changed files with 391 additions and 24 deletions

View File

@@ -23,7 +23,9 @@ type AgentOsOperator struct {
CanAccessInternet bool `json:"can_access_internet",comment:"是否可以访问公网"`
IsOsTypeUbuntu bool `json:"is_os_type_ubuntu",comment:"主机操作系统是否为ubuntu系列"`
IsOsTypeUbuntu bool `json:"is_os_type_ubuntu",comment:"主机操作系统是否为debian系列"`
IsOsTypeCentOS bool `json:"is_os_type_centos",comment:"主机操作系统是否为centos系列"`
IsAgentInnerWall bool `json:"is_agent_inner_wall",comment:"主机是否身处国内"`

View File

@@ -1,13 +1,13 @@
package executor
import (
"agent-go/status"
"strconv"
"strings"
)
func BuildAgentOsOperator(osInfo string, ossOfflinePrefix string) *AgentOsOperator {
// todo build from env
AgentOsOperatorCache = &AgentOsOperator{
InstallCommandPrefix: []string{
"apt-get", "install", "--allow-downgrades", "-y",
@@ -23,7 +23,7 @@ func BuildAgentOsOperator(osInfo string, ossOfflinePrefix string) *AgentOsOperat
}
// os type
detectByOsType(AgentOsOperatorCache, osInfo)
detectByAgentStatusInfo(AgentOsOperatorCache)
// internet
detectByInternet(AgentOsOperatorCache)
@@ -31,6 +31,74 @@ func BuildAgentOsOperator(osInfo string, ossOfflinePrefix string) *AgentOsOperat
return AgentOsOperatorCache
}
func detectByAgentStatusInfo(os *AgentOsOperator) {
agentMetric := status.ReportAgentMetric()
if strings.Contains(agentMetric.HostInfo.PlatformFamily, "centos") {
// centos
os.IsOsTypeUbuntu = false
os.IsOsTypeCentOS = true
os.InstallCommandPrefix = []string{
"yum", "install", "-y",
}
os.RemoveCommandPrefix = []string{
"yum", "remove",
}
} else if strings.Contains(agentMetric.HostInfo.PlatformFamily, "debian") {
// ubuntu
os.IsOsTypeUbuntu = true
os.RemoveCommandPrefix = []string{"apt", "remove", "-y"}
os.InstallCommandPrefix = []string{
"apt-get", "install", "--allow-downgrades", "-y",
}
// os release code
os.AgentOSReleaseCode = judgeUbuntuReleaseFromOsVersion(agentMetric.HostInfo.PlatformVersion)
}
// agent cpu arch
os.AgentArch = judgeAgentCpuArchByKernelArch(agentMetric.HostInfo.KernelArch)
}
func judgeUbuntuReleaseFromOsVersion(osVersion string) string {
switch osVersion {
case "16.04":
return "xenial"
case "18.04":
return "bionic"
case "20.04":
return "focal"
case "22.04":
return "jammy"
default:
return "ubuntu-unknown"
}
}
func judgeAgentCpuArchByKernelArch(kernelArch string) string {
switch kernelArch {
case "x86_64":
return "amd64"
case "aarch64":
return "arm64"
case "armv8":
return "arm64"
case "armv6":
return "arm6"
case "armv7":
return "arm7"
case "i32":
return "386"
case "i86":
return "386"
default:
return "cpu-unknown"
}
}
func detectByOsType(os *AgentOsOperator, osInfo string) {
ubuntuOsReleaseCode := [][]string{