Skip to content
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

Allow use of created_at for Scan timestamp display on UI #1980

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions deepfence_server/reporters/scan/scan_reporters.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func GetScanStatus(ctx context.Context, scanType utils.Neo4jScanType, scanIDs []
res, err := tx.Run(fmt.Sprintf(`
MATCH (m:%s) -[:SCANNED]-> (n)
WHERE m.node_id IN $scan_ids
RETURN m.node_id, m.status, m.status_message, n.node_id, n.node_name, labels(n) as node_type, m.updated_at`, scanType),
RETURN m.node_id, m.status, m.status_message, n.node_id, n.node_name, labels(n) as node_type, m.created_at, m.updated_at`, scanType),
map[string]interface{}{"scan_ids": scanIDs})
if err != nil {
return model.ScanStatusResp{}, err
Expand All @@ -94,7 +94,8 @@ func extractStatuses(recs []*db.Record) map[string]model.ScanInfo {
NodeID: rec.Values[3].(string),
NodeName: rec.Values[4].(string),
NodeType: Labels2NodeType(rec.Values[5].([]interface{})),
UpdatedAt: rec.Values[6].(int64),
CreatedAt: rec.Values[6].(int64),
UpdatedAt: rec.Values[7].(int64),
}
statuses[rec.Values[0].(string)] = info
}
Expand Down Expand Up @@ -125,7 +126,7 @@ func GetComplianceScanStatus(ctx context.Context, scanType utils.Neo4jScanType,
query := fmt.Sprintf(`
MATCH (m:%s) -[:SCANNED]-> (n:CloudNode)
WHERE m.node_id IN $scan_ids
RETURN m.node_id, m.benchmark_types, m.status, m.status_message, n.node_id, m.updated_at, n.node_name`, scanType)
RETURN m.node_id, m.benchmark_types, m.status, m.status_message, n.node_id, m.created_at, m.updated_at, n.node_name`, scanType)

res, err := tx.Run(query, map[string]interface{}{"scan_ids": scanIDs})
if err != nil {
Expand Down Expand Up @@ -156,8 +157,9 @@ func extractStatusesWithBenchmarks(recs []*db.Record) []model.ComplianceScanInfo
StatusMessage: rec.Values[3].(string),
NodeID: rec.Values[4].(string),
NodeType: controls.ResourceTypeToString(controls.CloudAccount),
UpdatedAt: rec.Values[5].(int64),
NodeName: rec.Values[6].(string),
CreatedAt: rec.Values[5].(int64),
UpdatedAt: rec.Values[6].(int64),
NodeName: rec.Values[7].(string),
},
BenchmarkTypes: benchmarkTypes,
}
Expand Down Expand Up @@ -512,13 +514,13 @@ func GetScansList(ctx context.Context, scanType utils.Neo4jScanType, nodeIDs []m
WHERE n.node_id IN $node_ids
AND (` + strings.Join(nodeTypesStr, " OR ") + `)
` + reporters.ParseFieldFilters2CypherWhereConditions("m", mo.Some(ff), false) + `
RETURN m.node_id, m.status, m.status_message, m.updated_at, n.node_id, n.node_name, labels(n) as node_type
RETURN m.node_id, m.status, m.status_message, m.created_at, m.updated_at, n.node_id, n.node_name, labels(n) as node_type
ORDER BY m.updated_at ` + fw.FetchWindow2CypherQuery()
} else {
query = `
MATCH (m:` + string(scanType) + `) -[:SCANNED]-> (n)
` + reporters.ParseFieldFilters2CypherWhereConditions("m", mo.Some(ff), true) + `
RETURN m.node_id, m.status, m.status_message, m.updated_at, n.node_id, n.node_name, labels(n) as node_type
RETURN m.node_id, m.status, m.status_message, m.created_at, m.updated_at, n.node_id, n.node_name, labels(n) as node_type
ORDER BY m.updated_at ` + fw.FetchWindow2CypherQuery()
}
scansInfo, err = processScansListQuery(query, nodeIDsStr, tx)
Expand Down Expand Up @@ -546,10 +548,11 @@ func processScansListQuery(query string, nodeIds []string, tx neo4j.Transaction)
ScanID: rec.Values[0].(string),
Status: rec.Values[1].(string),
StatusMessage: rec.Values[2].(string),
UpdatedAt: rec.Values[3].(int64),
NodeID: rec.Values[4].(string),
NodeName: rec.Values[5].(string),
NodeType: Labels2NodeType(rec.Values[6].([]interface{})),
CreatedAt: rec.Values[3].(int64),
UpdatedAt: rec.Values[4].(int64),
NodeID: rec.Values[5].(string),
NodeName: rec.Values[6].(string),
NodeType: Labels2NodeType(rec.Values[7].([]interface{})),
}
scansInfo = append(scansInfo, tmp)
}
Expand Down Expand Up @@ -577,7 +580,7 @@ func GetCloudCompliancePendingScansList(ctx context.Context, scanType utils.Neo4
res, err := tx.Run(`
MATCH (m:`+string(scanType)+`) -[:SCANNED]-> (n:CloudNode{node_id: $node_id})
WHERE m.status = $starting
RETURN m.node_id, m.benchmark_types, m.status, m.status_message, n.node_id, m.updated_at, n.node_name ORDER BY m.updated_at`,
RETURN m.node_id, m.benchmark_types, m.status, m.status_message, n.node_id, m.created_at, m.updated_at, n.node_name ORDER BY m.updated_at`,
map[string]interface{}{"node_id": nodeID, "starting": utils.ScanStatusStarting})
if err != nil {
return model.CloudComplianceScanListResp{}, err
Expand Down Expand Up @@ -1149,7 +1152,7 @@ func GetBulkScans(ctx context.Context, scanType utils.Neo4jScanType, scanID stri

neoRes, err := tx.Run(`
MATCH (m:Bulk`+string(scanType)+`{node_id:$scan_id}) -[:BATCH]-> (d:`+string(scanType)+`) -[:SCANNED]-> (n)
RETURN d.node_id as scan_id, d.status, d.status_message, n.node_id as node_id, n.node_name, labels(n) as node_type, d.updated_at`,
RETURN d.node_id as scan_id, d.status, d.status_message, n.node_id as node_id, n.node_name, labels(n) as node_type, d.created_at, d.updated_at`,
map[string]interface{}{"scan_id": scanID})
if err != nil {
return scanIDs, err
Expand Down Expand Up @@ -1212,7 +1215,7 @@ func GetComplianceBulkScans(ctx context.Context, scanType utils.Neo4jScanType, s

neoRes, err := tx.Run(`
MATCH (m:Bulk`+string(scanType)+`{node_id:$scan_id}) -[:BATCH]-> (d:`+string(scanType)+`) -[:SCANNED]-> (n:CloudNode)
RETURN d.node_id, d.benchmark_types, d.status, d.status_message, n.node_id, d.updated_at, n.node_name`,
RETURN d.node_id, d.benchmark_types, d.status, d.status_message, n.node_id, d.created_at, d.updated_at, n.node_name`,
map[string]interface{}{"scan_id": scanID})
if err != nil {
log.Error().Msgf("Compliance bulk scans status query failed: %+v", err)
Expand Down
13 changes: 7 additions & 6 deletions deepfence_server/reporters/search/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func constructIndirectMatchInit(

if doReturn {
if extendedField != "" {
query += "\n"+`MATCH (` + name + `) -[:IS]-> (e) ` +
query += "\n" + `MATCH (` + name + `) -[:IS]-> (e) ` +
reporters.ParseFieldFilters2CypherWhereConditions("e", mo.Some(extendedFilter.Filters), true) +
reporters.OrderFilter2CypherCondition("e", extendedFilter.Filters.OrderFilter, []string{name}) +
` RETURN ` + reporters.FieldFilterCypher(name, filter.InFieldFilter) + `, e` +
Expand Down Expand Up @@ -480,7 +480,7 @@ func searchGenericScanInfoReport(ctx context.Context, scanType utils.Neo4jScanTy
ORDER BY n.updated_at DESC` +
scanFilter.Window.FetchWindow2CypherQuery() +
`}` +
` RETURN n.node_id as scan_id, n.status as status, n.status_message as status_message, n.updated_at as updated_at, m.node_id as node_id, COALESCE(m.node_type, m.cloud_provider) as node_type, m.node_name as node_name` +
` RETURN n.node_id as scan_id, n.status as status, n.status_message as status_message, n.created_at as created_at, n.updated_at as updated_at, m.node_id as node_id, COALESCE(m.node_type, m.cloud_provider) as node_type, m.node_name as node_name` +
reporters.OrderFilter2CypherCondition("", scanFilter.Filters.OrderFilter, nil) +
fw.FetchWindow2CypherQuery()
log.Debug().Msgf("search query: %v", query)
Expand All @@ -507,10 +507,11 @@ func searchGenericScanInfoReport(ctx context.Context, scanType utils.Neo4jScanTy
ScanID: rec.Values[0].(string),
Status: rec.Values[1].(string),
StatusMessage: rec.Values[2].(string),
UpdatedAt: rec.Values[3].(int64),
NodeID: rec.Values[4].(string),
NodeType: rec.Values[5].(string),
NodeName: rec.Values[6].(string),
CreatedAt: rec.Values[3].(int64),
UpdatedAt: rec.Values[4].(int64),
NodeID: rec.Values[5].(string),
NodeType: rec.Values[6].(string),
NodeName: rec.Values[7].(string),
SeverityCounts: counts,
})
}
Expand Down
Loading