Skip to content

Commit f6b8c98

Browse files
author
piexlmax
committed
add agent version
1 parent 78cc0df commit f6b8c98

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

model/request/engine.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type AgentRegisterReq struct {
2424
ServerPath string `json:"serverPath"`
2525
ServerEnv string `json:"serverEnv"`
2626
Pid string `json:"pid"`
27+
ProjectVersion string `json:"projectVersion"`
2728
}
2829

2930
type HookRuleReq struct {
@@ -68,6 +69,7 @@ type Pant struct {
6869

6970
type Component struct {
7071
PackagePath string `json:"packagePath"`
72+
PackageVersion string `json:"packageVersion"`
7173
PackageSignature string `json:"packageSignature"`
7274
PackageName string `json:"packageName"`
7375
PackageAlgorithm string `json:"packageAlgorithm"`

service/auxiliary.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func GenAQLForGolang(packageName, version string) string {
2020
}
2121

2222
// 获取包
23-
func GetMod() []request.Component {
23+
func GetMod() ([]request.Component, string) {
2424
//fmt.Println(getCurrentPath())
2525
path, _ := os.Executable()
2626
return scanFile(path, true)
@@ -35,7 +35,7 @@ func isExe(file string, info fs.FileInfo) bool {
3535
}
3636

3737
// 从二进制文件读取包信息
38-
func scanFile(file string, mustPrint bool) (packages []request.Component) {
38+
func scanFile(file string, mustPrint bool) (packages []request.Component, agentVersion string) {
3939
bi, err := buildinfo.ReadFile(file)
4040
if err != nil {
4141
if mustPrint {
@@ -45,7 +45,7 @@ func scanFile(file string, mustPrint bool) (packages []request.Component) {
4545
fmt.Fprintf(os.Stderr, "%s: %v\n", file, err)
4646
}
4747
}
48-
return packages
48+
return packages, agentVersion
4949
}
5050
fmt.Printf("%s: %s\n", file, bi.GoVersion)
5151
bi.GoVersion = "" // suppress printing go version again
@@ -57,16 +57,21 @@ func scanFile(file string, mustPrint bool) (packages []request.Component) {
5757
if licl[0] == "dep" {
5858
fmt.Printf("依赖:%s\t版本:%s\n", licl[1], licl[2])
5959
aql := GenAQLForGolang(licl[1], licl[2])
60+
if licl[1] == "github.com/HXSecurity/DongTai-agent-go" {
61+
fmt.Println("当前探针版本为:" + licl[2])
62+
agentVersion = licl[2]
63+
}
6064
packages = append(packages, request.Component{
6165
PackageName: aql,
6266
PackageAlgorithm: "SHA-1",
6367
PackagePath: file,
68+
PackageVersion: licl[2],
6469
PackageSignature: utils.SHA1(aql),
6570
},
6671
)
6772
}
6873
}
69-
return
74+
return packages, agentVersion
7075
}
7176

7277
// 获取服务信息

service/engine.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func AgentRegister() (err error) {
7878
OS := runtime.GOOS
7979
hostname, _ := os.Hostname()
8080
version := "1.0.0"
81+
packages, agentVersion := GetMod()
8182
if global.Config.DongtaiGoProjectVersion != "" {
8283
version = global.Config.DongtaiGoProjectVersion
8384
}
@@ -132,7 +133,8 @@ func AgentRegister() (err error) {
132133
AutoCreateProject: global.Config.DongtaiGoProjectCreate,
133134
Name: name,
134135
Language: "GO",
135-
Version: version,
136+
Version: agentVersion,
137+
ProjectVersion: version,
136138
ProjectName: projectName,
137139
Hostname: hostname,
138140
Network: ips,
@@ -201,13 +203,12 @@ func AgentRegister() (err error) {
201203
}
202204
req.ServerAddr = ip.String()
203205
agentId, err := api.AgentRegister(req)
204-
205206
if err != nil {
206207
fmt.Println(err)
207208
break
208209
}
209210
global.AgentId = agentId
210-
UploadSca()
211+
UploadSca(packages)
211212
go func() {
212213
for {
213214
time.Sleep(10 * time.Second)
@@ -257,8 +258,7 @@ func PingPang() {
257258
req.Detail.AgentId = global.AgentId
258259
api.ReportUpload(req)
259260
}
260-
func UploadSca() {
261-
packages := GetMod()
261+
func UploadSca(packages []request.Component) {
262262
var req request.UploadReq
263263
req.Type = 18
264264
req.Detail.AgentId = global.AgentId

0 commit comments

Comments
 (0)