[ Project ] 适配前端部分代码

This commit is contained in:
zeaslity
2023-08-02 14:30:01 +08:00
parent 98467f9590
commit 8e2eacfa47
22 changed files with 596 additions and 142 deletions

View File

@@ -189,7 +189,7 @@ func parseAgentServerInfo(agentServerInfoConf string) *register.AgentServerInfo
}
log.Info(fmt.Sprintf("agent server info is %v", string(jsonFormat)))
// build a operator cache
// build operator cache
BuildAgentOsOperator(agentServerInfo)
return agentServerInfo
@@ -197,21 +197,13 @@ func parseAgentServerInfo(agentServerInfoConf string) *register.AgentServerInfo
func BuildAgentOsOperator(agentServerInfo *register.AgentServerInfo) {
executor.AgentOsOperatorCache = &executor.AgentOsOperator{
InstallCommandPrefix: []string{
"apt-get", "install", "-y",
},
RemoveCommandPrefix: []string{"apt", "remove", "-y"},
CanAccessInternet: true,
IsOsTypeUbuntu: true,
IsAgentInnerWall: true,
AgentArch: "amd64",
AgentOSReleaseCode: "focal",
AgentServerInfo: agentServerInfo,
}
// call the init exec function
agentOsOperator := executor.BuildAgentOsOperator(agentServerInfo.OSInfo)
// assign the agentServerInfo
agentOsOperator.AgentServerInfo = agentServerInfo
// debug
marshal, _ := json.Marshal(executor.AgentOsOperatorCache)
log.DebugF("cached agent operator is %s", marshal)
marshal, _ := json.Marshal(agentOsOperator)
log.DebugF("[Agent INIT] cached agent operator is %s", marshal)
}

View File

@@ -69,13 +69,17 @@ func PipeLineCommandExecutor(pipeLineCommand [][]string) ([]string, error) {
var output []byte
var err error
for i, command := range pipeLineCommand {
cmd := exec.Command(command[0], command[1:]...)
cmd.Stdin = bytes.NewReader(output)
output, err = cmd.Output()
if err != nil {
return strings.Split(string(output), "\n"), err
}
if i == len(pipeLineCommand)-1 {
return strings.Split(string(output), "\n"), nil
}

View File

@@ -0,0 +1,80 @@
package executor
import "strings"
func BuildAgentOsOperator(osInfo string) *AgentOsOperator {
AgentOsOperatorCache = &AgentOsOperator{
InstallCommandPrefix: []string{
"apt-get", "install", "-y",
},
RemoveCommandPrefix: []string{"apt", "remove", "-y"},
CanAccessInternet: true,
IsOsTypeUbuntu: true,
IsAgentInnerWall: true,
AgentArch: "amd64",
AgentOSReleaseCode: "focal",
AgentServerInfo: nil,
}
// os type
detectByOsType(AgentOsOperatorCache, osInfo)
// internet
detectByInternet(AgentOsOperatorCache)
return AgentOsOperatorCache
}
func detectByOsType(os *AgentOsOperator, osInfo string) {
ubuntuSsRealseCode := [][]string{
{
"cat",
"/etc/os-release",
},
{
"grep",
"CODE",
},
{
"head",
"-1",
},
{
"cut",
"-d",
"=",
"-f",
"2",
},
}
if strings.HasPrefix(osInfo, "Ce") {
// centos
os.IsOsTypeUbuntu = false
os.InstallCommandPrefix = []string{
"yum", "install", "-y",
}
os.RemoveCommandPrefix = []string{
"yum", "remove",
}
} else {
// ubuntu
os.IsOsTypeUbuntu = true
os.RemoveCommandPrefix = []string{"apt", "remove", "-y"}
os.InstallCommandPrefix = []string{
"apt-get", "install", "-y",
}
// os release code
osRealseResult, _ := PipeLineCommandExecutor(ubuntuSsRealseCode)
os.AgentOSReleaseCode = osRealseResult[0]
}
}
func detectByInternet(os *AgentOsOperator) {
}

View File

@@ -11,7 +11,6 @@ import (
type RabbitMQ interface {
RabbitSendWriter
RabbitConnectCloser
}
@@ -29,6 +28,7 @@ type RabbitConnectCloser interface {
type RabbitQueue struct {
RabbitConn *RabbitMQConn
RabbitProp *ConnectProperty
}

View File

@@ -3,14 +3,13 @@ package status
import (
"fmt"
"github.com/shirou/gopsutil/v3/disk"
"runtime"
"time"
)
type DiskStatus struct {
Total uint64
Used uint64
LogicalDisk []disk.PartitionStat
Total uint64
Used uint64
//LogicalDisk []disk.PartitionStat
}
func GetDiskStatus() *DiskStatus {
@@ -22,11 +21,12 @@ func GetDiskStatus() *DiskStatus {
ds.Total = du.Total
ds.Used = du.Used
// 2023年7月14日 去除此部分 没什么用
// Get logical disk info for Linux systems
if runtime.GOOS == "linux" {
ld, _ := disk.Partitions(true)
ds.LogicalDisk = ld
}
//if runtime.GOOS == "linux" {
// ld, _ := disk.Partitions(true)
// ds.LogicalDisk = ld
//}
return ds
}