Skip to content

Commit a82cf2a

Browse files
committed
adapded the vulnerability indexer changes in version 4.11
1 parent 280d862 commit a82cf2a

File tree

4 files changed

+150
-50
lines changed

4 files changed

+150
-50
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ require (
5656
github.com/goccy/go-json v0.10.5 // indirect
5757
github.com/gofrs/flock v0.12.1 // indirect
5858
github.com/golang/snappy v1.0.0 // indirect
59-
github.com/gomarkdown/markdown v0.0.0-20250207164621-7a1f277a159e // indirect
59+
github.com/gomarkdown/markdown v0.0.0-20250311123330-531bef5e742b // indirect
6060
github.com/google/uuid v1.6.0 // indirect
6161
github.com/gorilla/css v1.0.1 // indirect
6262
github.com/iris-contrib/schema v0.0.6 // indirect

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ github.com/bytedance/sonic v1.13.1/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1
3838
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
3939
github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY=
4040
github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
41+
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
4142
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
4243
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
4344
github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4=
@@ -84,12 +85,15 @@ github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PU
8485
github.com/gofrs/flock v0.7.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
8586
github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E=
8687
github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0=
88+
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
8789
github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo=
8890
github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
8991
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
9092
github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
9193
github.com/gomarkdown/markdown v0.0.0-20250207164621-7a1f277a159e h1:ESHlT0RVZphh4JGBz49I5R6nTdC8Qyc08vU25GQHzzQ=
9294
github.com/gomarkdown/markdown v0.0.0-20250207164621-7a1f277a159e/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
95+
github.com/gomarkdown/markdown v0.0.0-20250311123330-531bef5e742b h1:EY/KpStFl60qA17CptGXhwfZ+k1sFNJIUNR8DdbcuUk=
96+
github.com/gomarkdown/markdown v0.0.0-20250311123330-531bef5e742b/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
9397
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
9498
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
9599
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
@@ -177,6 +181,7 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m
177181
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
178182
github.com/opensearch-project/opensearch-go v1.1.0 h1:eG5sh3843bbU1itPRjA9QXbxcg8LaZ+DjEzQH9aLN3M=
179183
github.com/opensearch-project/opensearch-go v1.1.0/go.mod h1:+6/XHCuTH+fwsMJikZEWsucZ4eZMma3zNSeLrTtVGbo=
184+
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
180185
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
181186
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
182187
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=

indexer/indexer.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (i *Indexer) GetAgentVulnerabilities(agentId string, ctx context.Context) (
5151
i.client.Search.WithFrom(0),
5252
i.client.Search.WithSize(2500),
5353
i.client.Search.WithRequestCache(true),
54-
i.client.Search.WithSort("vulnerability.cve:asc"),
54+
i.client.Search.WithSort("vulnerability.id:asc"),
5555
)
5656
if err != nil {
5757
return nil, err
@@ -76,5 +76,4 @@ func (i *Indexer) GetAgentVulnerabilities(agentId string, ctx context.Context) (
7676
vulns = append(vulns, hit.Vulnerability)
7777
}
7878
return vulns, nil
79-
8079
}

indexer/vulneranility.go

Lines changed: 143 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
11
package indexer
22

3+
import (
4+
"time"
5+
)
6+
7+
// Helper functions for non-string primitives
8+
func BoolPtr(b bool) *bool { return &b }
9+
func Int64Ptr(i int64) *int64 { return &i }
10+
func Float64Ptr(f float64) *float64 { return &f }
11+
func TimePtr(t time.Time) *time.Time { return &t }
12+
313
type Build struct {
4-
Original string `json:"original"`
14+
Original string `json:"original,omitempty"`
515
}
616

7-
type Agent struct {
8-
Build Build `json:"build,omitempty"`
9-
EphemeralID string `json:"ephemeral_id,omitempty"`
10-
ID string `json:"id"`
11-
Name string `json:"name"`
12-
Type string `json:"type"`
13-
Version string `json:"version"`
17+
type AgentHostBoot struct {
18+
ID string `json:"id,omitempty"`
19+
}
20+
21+
type AgentHostCPU struct {
22+
Usage *float64 `json:"usage,omitempty"`
23+
}
24+
25+
type DiskIO struct {
26+
Bytes *int64 `json:"bytes,omitempty"`
27+
}
28+
29+
type AgentHostDisk struct {
30+
Read *DiskIO `json:"read,omitempty"`
31+
Write *DiskIO `json:"write,omitempty"`
1432
}
1533

1634
type OS struct {
@@ -27,66 +45,144 @@ type Host struct {
2745
OS OS `json:"os"`
2846
}
2947

48+
type Geo struct {
49+
CityName string `json:"city_name,omitempty"`
50+
ContinentCode string `json:"continent_code,omitempty"`
51+
ContinentName string `json:"continent_name,omitempty"`
52+
CountryIsoCode string `json:"country_iso_code,omitempty"`
53+
CountryName string `json:"country_name,omitempty"`
54+
Location string `json:"location,omitempty"` // geo_point
55+
Name string `json:"name,omitempty"`
56+
PostalCode string `json:"postal_code,omitempty"`
57+
RegionIsoCode string `json:"region_iso_code,omitempty"`
58+
RegionName string `json:"region_name,omitempty"`
59+
Timezone string `json:"timezone,omitempty"`
60+
}
61+
62+
type NetworkTraffic struct {
63+
Bytes *int64 `json:"bytes,omitempty"`
64+
Packets *int64 `json:"packets,omitempty"`
65+
}
66+
67+
type AgentHostNetwork struct {
68+
Egress *NetworkTraffic `json:"egress,omitempty"`
69+
Ingress *NetworkTraffic `json:"ingress,omitempty"`
70+
}
71+
72+
type HostOS struct {
73+
Family string `json:"family,omitempty"`
74+
Full string `json:"full,omitempty"`
75+
Kernel string `json:"kernel,omitempty"`
76+
Name string `json:"name,omitempty"`
77+
Platform string `json:"platform,omitempty"`
78+
Type string `json:"type,omitempty"`
79+
Version string `json:"version,omitempty"`
80+
}
81+
82+
type RiskScores struct {
83+
CalculatedLevel string `json:"calculated_level,omitempty"`
84+
CalculatedScore *float64 `json:"calculated_score,omitempty"`
85+
CalculatedScoreNorm *float64 `json:"calculated_score_norm,omitempty"`
86+
StaticLevel string `json:"static_level,omitempty"`
87+
StaticScore *float64 `json:"static_score,omitempty"`
88+
StaticScoreNorm *float64 `json:"static_score_norm,omitempty"`
89+
}
90+
91+
type AgentHost struct {
92+
Architecture string `json:"architecture,omitempty"`
93+
Boot *AgentHostBoot `json:"boot,omitempty"`
94+
CPU *AgentHostCPU `json:"cpu,omitempty"`
95+
Disk *AgentHostDisk `json:"disk,omitempty"`
96+
Domain string `json:"domain,omitempty"`
97+
Geo *Geo `json:"geo,omitempty"`
98+
Hostname string `json:"hostname,omitempty"`
99+
ID string `json:"id,omitempty"`
100+
IP string `json:"ip,omitempty"`
101+
MAC string `json:"mac,omitempty"`
102+
Name string `json:"name,omitempty"`
103+
Network *AgentHostNetwork `json:"network,omitempty"`
104+
OS *HostOS `json:"os,omitempty"`
105+
PidNSIno string `json:"pid_ns_ino,omitempty"`
106+
Risk *RiskScores `json:"risk,omitempty"`
107+
Type string `json:"type,omitempty"`
108+
Uptime *int64 `json:"uptime,omitempty"`
109+
}
110+
111+
type Agent struct {
112+
Build *Build `json:"build,omitempty"`
113+
EphemeralID string `json:"ephemeral_id,omitempty"`
114+
Groups []string `json:"groups,omitempty"`
115+
Host *AgentHost `json:"host,omitempty"`
116+
ID string `json:"id,omitempty"`
117+
Name string `json:"name,omitempty"`
118+
Type string `json:"type,omitempty"`
119+
Version string `json:"version,omitempty"`
120+
}
121+
30122
type Package struct {
31-
Architecture string `json:"architecture"`
32-
BuildVersion string `json:"build_version,omitempty"`
33-
Checksum string `json:"checksum,omitempty"`
34-
Description string `json:"description"`
35-
InstallScope string `json:"install_scope,omitempty"`
36-
Installed string `json:"installed,omitempty"` // assuming installed date is a string in ISO format
37-
License string `json:"license,omitempty"`
38-
Name string `json:"name"`
39-
Path string `json:"path,omitempty"`
40-
Reference string `json:"reference,omitempty"`
41-
Size int64 `json:"size"`
42-
Type string `json:"type"`
43-
Version string `json:"version"`
123+
Architecture string `json:"architecture,omitempty"`
124+
BuildVersion string `json:"build_version,omitempty"`
125+
Checksum string `json:"checksum,omitempty"`
126+
Description string `json:"description,omitempty"`
127+
InstallScope string `json:"install_scope,omitempty"`
128+
Installed *time.Time `json:"installed,omitempty"`
129+
License string `json:"license,omitempty"`
130+
Name string `json:"name,omitempty"`
131+
Path string `json:"path,omitempty"`
132+
Reference string `json:"reference,omitempty"`
133+
Size *int64 `json:"size,omitempty"`
134+
Type string `json:"type,omitempty"`
135+
Version string `json:"version,omitempty"`
44136
}
45137

46138
type Scanner struct {
47-
Vendor string `json:"vendor"`
139+
Condition string `json:"condition,omitempty"`
140+
Reference string `json:"reference,omitempty"`
141+
Source string `json:"source,omitempty"`
142+
Vendor string `json:"vendor,omitempty"`
48143
}
49144

50145
type Score struct {
51-
Base float64 `json:"base"`
52-
Environmental float64 `json:"environmental,omitempty"`
53-
Temporal float64 `json:"temporal,omitempty"`
54-
Version string `json:"version"`
146+
Base *float64 `json:"base,omitempty"`
147+
Environmental *float64 `json:"environmental,omitempty"`
148+
Temporal *float64 `json:"temporal,omitempty"`
149+
Version string `json:"version,omitempty"`
55150
}
56151

57152
type Vulnerability struct {
58-
Category string `json:"category"`
59-
Classification string `json:"classification"`
60-
Description string `json:"description"`
61-
DetectedAt string `json:"detected_at"` // assuming dates are in string format
62-
Enumeration string `json:"enumeration"`
63-
ID string `json:"id"`
64-
PublishedAt string `json:"published_at"` // assuming dates are in string format
65-
Reference string `json:"reference"`
66-
ReportID string `json:"report_id,omitempty"`
67-
Scanner Scanner `json:"scanner"`
68-
Score Score `json:"score"`
69-
Severity string `json:"severity"`
153+
Category string `json:"category,omitempty"`
154+
Classification string `json:"classification,omitempty"`
155+
Description string `json:"description,omitempty"`
156+
DetectedAt *time.Time `json:"detected_at,omitempty"`
157+
Enumeration string `json:"enumeration,omitempty"`
158+
ID string `json:"id,omitempty"`
159+
PublishedAt *time.Time `json:"published_at,omitempty"`
160+
Reference string `json:"reference,omitempty"`
161+
ReportID string `json:"report_id,omitempty"`
162+
Scanner *Scanner `json:"scanner,omitempty"`
163+
Score *Score `json:"score,omitempty"`
164+
Severity string `json:"severity,omitempty"`
165+
UnderEvaluation *bool `json:"under_evaluation,omitempty"`
70166
}
71167

72168
type Cluster struct {
73-
Name string `json:"name"`
169+
Name string `json:"name,omitempty"`
74170
Node string `json:"node,omitempty"`
75171
}
76172

77173
type Schema struct {
78-
Version string `json:"version"`
174+
Version string `json:"version,omitempty"`
79175
}
80176

81177
type Wazuh struct {
82-
Cluster Cluster `json:"cluster"`
83-
Schema Schema `json:"schema"`
178+
Cluster *Cluster `json:"cluster,omitempty"`
179+
Schema *Schema `json:"schema,omitempty"`
84180
}
85181

86182
type AgentVulnerability struct {
87-
Agent Agent `json:"agent"`
88-
Host Host `json:"host"`
89-
Package Package `json:"package"`
90-
Vulnerability Vulnerability `json:"vulnerability"`
91-
Wazuh Wazuh `json:"wazuh"`
183+
Agent *Agent `json:"agent,omitempty"`
184+
Host *Host `json:"host,omitempty"`
185+
Package *Package `json:"package,omitempty"`
186+
Vulnerability *Vulnerability `json:"vulnerability,omitempty"`
187+
Wazuh *Wazuh `json:"wazuh,omitempty"`
92188
}

0 commit comments

Comments
 (0)