Skip to content

Commit 4b700ed

Browse files
authored
Merge pull request #71 from hazcod/feat/warnings
fix(falcon): fetch device details in chunks of 100
2 parents a739f52 + 0f22334 commit 4b700ed

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

pkg/falcon/extractor.go

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,50 @@ func GetMessages(config *config.Config, ctx context.Context) (results map[string
175175
return nil, nil, nil, errors.Wrap(err, "could not query all hosts")
176176
}
177177

178-
hostDetail, err := client.Hosts.GetDeviceDetails(&hosts.GetDeviceDetailsParams{
179-
Ids: hostResult.Payload.Resources,
180-
Context: ctx,
181-
HTTPClient: nil,
182-
})
183-
if err != nil || !hostDetail.IsSuccess() {
184-
return nil, nil, nil, errors.Wrap(err, "could not query all host details")
178+
allHostDetails := make([]*models.DomainDeviceSwagger, 0)
179+
180+
step := 100
181+
sliceStart := 0
182+
sliceEnd := sliceStart + step
183+
184+
for {
185+
186+
if sliceEnd == len(hostResult.Payload.Resources)-1 {
187+
break
188+
}
189+
190+
if sliceEnd >= len(hostResult.Payload.Resources) {
191+
sliceEnd = len(hostResult.Payload.Resources) - 1
192+
}
193+
194+
if sliceEnd == sliceStart {
195+
break
196+
}
197+
198+
logrus.WithField("slice_start", sliceStart).WithField("slice_end", sliceEnd).
199+
Debug("fetching host device details")
200+
201+
slicePart := hostResult.Payload.Resources[sliceStart:sliceEnd]
202+
203+
hostDetail, err := client.Hosts.GetDeviceDetails(&hosts.GetDeviceDetailsParams{
204+
Ids: slicePart,
205+
Context: ctx,
206+
HTTPClient: nil,
207+
})
208+
if err != nil || !hostDetail.IsSuccess() {
209+
return nil, nil, nil, errors.Wrap(err, "could not query all host details")
210+
}
211+
212+
allHostDetails = append(allHostDetails, hostDetail.Payload.Resources...)
213+
214+
sliceStart = sliceEnd
215+
sliceEnd = sliceStart + step
185216
}
186217

187218
securityErrorsMap := make(map[string]struct{})
188219
now := time.Now()
189220

190-
for _, detail := range hostDetail.Payload.Resources {
221+
for _, detail := range allHostDetails {
191222

192223
email, err := findEmailTag(detail.Tags, config.Email.Domains)
193224
if err != nil || email == "" {

0 commit comments

Comments
 (0)