-
Notifications
You must be signed in to change notification settings - Fork 597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Posture counts #1653
Posture counts #1653
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package ingesters | |
|
||
import ( | ||
"encoding/json" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/deepfence/ThreatMapper/deepfence_utils/directory" | ||
|
@@ -79,12 +80,12 @@ func CommitFuncStatus[Status any](ts utils.Neo4jScanType) func(ns string, data [ | |
return err | ||
} | ||
|
||
if ts != utils.NEO4J_COMPLIANCE_SCAN { | ||
worker, err := directory.Worker(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
worker, err := directory.Worker(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if ts != utils.NEO4J_COMPLIANCE_SCAN { | ||
event := scans.UpdateScanEvent{ | ||
ScanType: ts, | ||
RecordMap: recordMap, | ||
|
@@ -97,7 +98,17 @@ func CommitFuncStatus[Status any](ts utils.Neo4jScanType) func(ns string, data [ | |
if ts == utils.NEO4J_CLOUD_COMPLIANCE_SCAN { | ||
task = utils.UpdateCloudResourceScanStatusTask | ||
} | ||
err = worker.Enqueue(task, b) | ||
if err := worker.Enqueue(task, b); err != nil { | ||
log.Error().Err(err).Msgf("failed to enqueue %s", task) | ||
} | ||
} | ||
|
||
if (ts == utils.NEO4J_COMPLIANCE_SCAN || ts == utils.NEO4J_CLOUD_COMPLIANCE_SCAN) && anyCompleted(others) { | ||
err := worker.Enqueue(utils.CachePostureProviders, | ||
[]byte(strconv.FormatInt(utils.GetTimestamp(), 10))) | ||
if err != nil { | ||
log.Error().Err(err).Msgf("failed to enqueue %s", utils.CachePostureProviders) | ||
} | ||
} | ||
|
||
return err | ||
|
@@ -156,3 +167,17 @@ func ToMap[T any](data T) map[string]interface{} { | |
_ = json.Unmarshal(out, &bb) | ||
return bb | ||
} | ||
|
||
func anyCompleted(data []map[string]interface{}) bool { | ||
|
||
complete := false | ||
|
||
for i := range data { | ||
if data[i]["scan_status"].(string) == utils.SCAN_STATUS_SUCCESS { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to check if string conversion gave no error? Otherwise, might run into runtime error There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we dont need to check here as this field is guaranteed to have string data |
||
complete = true | ||
break | ||
} | ||
} | ||
|
||
return complete | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the condition
n.agent_running=true
not required for linux posture count too?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hosts with agent_running=false are not allowed to scan so they will not appear here