Commit 7b5fd587 authored by qiuqunfeng's avatar qiuqunfeng
Browse files

Refine WAF attack log query time filtering logic

- Adjust time range filtering to use strictly positive time values
- Rename Elasticsearch query result variable for improved readability
- Maintain existing logging and error handling for WAF attack log retrieval
parent 7a6e4556
......@@ -792,8 +792,8 @@ func (s *wafService) ListAttackLogs(ctx context.Context, req *AttackLogFilter) (
boolQuery.Filter(elastic.NewBoolQuery().MustNot(elastic.NewTermQuery("action", "pass")))
}
hasStart := req.StartTime >= 0
hasEnd := req.EndTime >= 0
hasStart := req.StartTime > 0
hasEnd := req.EndTime > 0
if hasStart || hasEnd {
rangeQuery := elastic.NewRangeQuery("attack_time")
if hasStart {
......@@ -816,7 +816,7 @@ func (s *wafService) ListAttackLogs(ctx context.Context, req *AttackLogFilter) (
}
log.Info().Interface("limit", req.Limit).Msg("limit")
res, err := ss.Query(boolQuery).Size(req.Limit).
result, err := ss.Query(boolQuery).Size(req.Limit).
SortBy(elastic.NewFieldSort("attack_time").Order(false),
elastic.NewFieldSort("id.digit").Order(false)).
Do(ctx)
......@@ -825,11 +825,11 @@ func (s *wafService) ListAttackLogs(ctx context.Context, req *AttackLogFilter) (
return nil, "", fmt.Errorf("failed to search waf detections: %v", err)
}
list := make([]model.WafDetection, len(res.Hits.Hits))
endIdx := len(res.Hits.Hits) - 1
list := make([]model.WafDetection, len(result.Hits.Hits))
endIdx := len(result.Hits.Hits) - 1
pageToken := ""
log.Info().Interface("res", res).Msg("list attack logs res")
for i, hit := range res.Hits.Hits {
log.Info().Interface("res", result).Msg("list attack logs res")
for i, hit := range result.Hits.Hits {
log.Info().Interface("hit source", hit.Source).Msg("hit")
wafDetection := model.WafDetection{}
if err = json.Unmarshal(hit.Source, &wafDetection); err != nil {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment