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

Return all results from an aggregated ES query #109

Merged
merged 1 commit into from
Aug 31, 2023
Merged
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
22 changes: 14 additions & 8 deletions services/client_monitoring/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"www.velocidex.com/golang/velociraptor/json"
)

const OPENSEARCH_MAX_BUCKETS = 10000

func (self *ClientMonitoringManager) ListAvailableEventResults(
ctx context.Context,
in *api_proto.ListAvailableEventResultsRequest) (
Expand Down Expand Up @@ -39,7 +41,8 @@ const (
"aggs": {
"genres": {
"terms": {
"field": "artifact"
"field": "artifact",
"size": %q
}
}
}
Expand All @@ -61,7 +64,8 @@ const (
"aggs": {
"genres": {
"terms": {
"field": "artifact"
"field": "artifact",
"size": %q
}
}
}
Expand All @@ -82,13 +86,13 @@ func listAvailableEventArtifacts(
// artifacts runner, it is still possible for server artifacts
// to be written by various services (e.g. Audit manager).
query = json.Format(getAvailableServerArtifactsQuery,
"server", "results")
"server", "results", OPENSEARCH_MAX_BUCKETS)

} else {
// Even if client events are not generated there are always
// some query logs sent so we can aggregate by unique log
// messages.
query = json.Format(getAvailableArtifactsQuery, in.ClientId, "logs")
query = json.Format(getAvailableArtifactsQuery, in.ClientId, "logs", OPENSEARCH_MAX_BUCKETS)
}

hits, err := cvelo_services.QueryElasticAggregations(ctx,
Expand Down Expand Up @@ -126,7 +130,8 @@ const getAvailableEventTimesQuery = `
"aggs": {
"genres": {
"terms": {
"field": "date"
"field": "date",
"size": %q
}
}
}
Expand All @@ -150,7 +155,8 @@ const getAvailableServerEventTimesQuery = `
"aggs": {
"genres": {
"terms": {
"field": "date"
"field": "date",
"size": %q
}
}
}
Expand All @@ -165,11 +171,11 @@ func listAvailableEventTimestamps(

var query string
if in.ClientId == "" || in.ClientId == "server" {
query = json.Format(getAvailableServerEventTimesQuery, in.Artifact)
query = json.Format(getAvailableServerEventTimesQuery, in.Artifact, OPENSEARCH_MAX_BUCKETS)

} else {
query = json.Format(getAvailableEventTimesQuery, in.ClientId,
"results", in.Artifact)
"results", in.Artifact, OPENSEARCH_MAX_BUCKETS)
}

hits, err := cvelo_services.QueryElasticAggregations(ctx,
Expand Down
Loading