[ Agent ] [ init ] - ifx init process to use status module

This commit is contained in:
zeaslity
2024-01-18 16:45:13 +08:00
parent 86b6484194
commit 2b3dd8a4d8
3 changed files with 1318 additions and 33 deletions

View File

@@ -227,14 +227,14 @@ func UniformAgentServerInfo(agentServerInfo *register.AgentServerInfo) {
func BuildAgentOsOperator(agentServerInfo *register.AgentServerInfo) {
// 2023年8月4日 passthrough some key information
// 2023年8月4日 pass through some key information
ossOfflinePrefix := g.G.AgentConfig.GetString("octopus.agent.executor.ossOfflinePrefix")
if !strings.HasSuffix(ossOfflinePrefix, "/") {
ossOfflinePrefix += "/"
}
// call the init exec function
agentOsOperator := executor.BuildAgentOsOperator(agentServerInfo.OSInfo, ossOfflinePrefix)
agentOsOperator := executor.BuildAgentOsOperator(ossOfflinePrefix)
// assign the agentServerInfo
agentOsOperator.AgentServerInfo = agentServerInfo

View File

@@ -6,7 +6,7 @@ import (
"strings"
)
func BuildAgentOsOperator(osInfo string, ossOfflinePrefix string) *AgentOsOperator {
func BuildAgentOsOperator(ossOfflinePrefix string) *AgentOsOperator {
AgentOsOperatorCache = &AgentOsOperator{
InstallCommandPrefix: []string{
@@ -15,6 +15,7 @@ func BuildAgentOsOperator(osInfo string, ossOfflinePrefix string) *AgentOsOperat
RemoveCommandPrefix: []string{"apt", "remove", "-y"},
CanAccessInternet: true,
IsOsTypeUbuntu: true,
IsOsTypeCentOS: false,
IsAgentInnerWall: false,
AgentArch: "amd64",
AgentOSReleaseCode: "focal",
@@ -32,7 +33,7 @@ func BuildAgentOsOperator(osInfo string, ossOfflinePrefix string) *AgentOsOperat
}
func detectByAgentStatusInfo(os *AgentOsOperator) {
agentMetric := status.ReportAgentMetric()
agentMetric := status.ReportAgentInfo()
if strings.Contains(agentMetric.HostInfo.PlatformFamily, "centos") {
// centos
@@ -48,6 +49,7 @@ func detectByAgentStatusInfo(os *AgentOsOperator) {
} else if strings.Contains(agentMetric.HostInfo.PlatformFamily, "debian") {
// ubuntu
os.IsOsTypeUbuntu = true
os.IsOsTypeCentOS = false
os.RemoveCommandPrefix = []string{"apt", "remove", "-y"}
os.InstallCommandPrefix = []string{
"apt-get", "install", "--allow-downgrades", "-y",
@@ -99,6 +101,35 @@ func judgeAgentCpuArchByKernelArch(kernelArch string) string {
}
}
func detectByInternet(os *AgentOsOperator) {
outsideTestUrl := "www.google.com"
innerTestUrl := "www.baidu.com"
testInternetCommand := []string{
"curl",
"-o",
"/dev/null",
"-m",
"5",
"-s",
}
if PureResultSingleExecute(append(testInternetCommand, outsideTestUrl)) {
os.CanAccessInternet = true
os.IsAgentInnerWall = false
} else if PureResultSingleExecute(append(testInternetCommand, innerTestUrl)) {
os.CanAccessInternet = true
os.IsAgentInnerWall = true
} else {
os.CanAccessInternet = false
os.IsAgentInnerWall = true
}
log.InfoF("[Agent Network Status] - Can Access Internet => %s Inner CN => %s", strconv.FormatBool(os.CanAccessInternet), strconv.FormatBool(os.IsAgentInnerWall))
}
func detectByOsType(os *AgentOsOperator, osInfo string) {
ubuntuOsReleaseCode := [][]string{
@@ -152,32 +183,3 @@ func detectByOsType(os *AgentOsOperator, osInfo string) {
}
}
func detectByInternet(os *AgentOsOperator) {
outsideTestUrl := "www.google.com"
innerTestUrl := "www.baidu.com"
testInternetCommand := []string{
"curl",
"-o",
"/dev/null",
"-m",
"5",
"-s",
}
if PureResultSingleExecute(append(testInternetCommand, outsideTestUrl)) {
os.CanAccessInternet = true
os.IsAgentInnerWall = false
} else if PureResultSingleExecute(append(testInternetCommand, innerTestUrl)) {
os.CanAccessInternet = true
os.IsAgentInnerWall = true
} else {
os.CanAccessInternet = false
os.IsAgentInnerWall = true
}
log.InfoF("[Agent Network Status] - Can Access Internet => %s Inner CN => %s", strconv.FormatBool(os.CanAccessInternet), strconv.FormatBool(os.IsAgentInnerWall))
}

File diff suppressed because it is too large Load Diff