- Notifications
You must be signed in to change notification settings - Fork 511
box_events: add limit parameter and pagination #15257
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
box_events: add limit parameter and pagination #15257
Conversation
| Pinging @elastic/security-service-integrations (Team:Security-Service Integrations) |
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.
Part of the reason we missed this problem was that the test case had a low interval so it looked like pagination worked based on assert.hit_count. Now that pagination is working, let's make sure that the test is also covering:
- Expand the test to verify that it makes no more requests when the returned
entriescount is less than thelimit. - Expand the test to verify that the second periodic interval executes with the previously persisted cursor stream position.
Here's a rough sketch of what I was thinking: 45b02c3
packages/box_events/data_stream/events/agent/stream/httpjson.yml.hbs Outdated Show resolved Hide resolved
efd6 left a comment
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.
This needs some field definitions:
test case failed: one or more errors found in document: [0] field "related.location.coordinates" is undefined, could be a multifield [1] field "related.location.type" is undefined, could be a multifield [2] field "threat.enrichments.indicator.geo.location.coordinates" is undefined, could be a multifield [3] field "threat.enrichments.indicator.geo.location.type" is undefined, could be a multifield packages/box_events/changelog.yml Outdated
| - description: Add limit parameter and pagination support. | ||
| type: enhancement | ||
| link: https://github.com/elastic/integrations/pull/15257 |
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.
I think this is also a bug fix against the absence of pagination.
🚀 Benchmarks reportTo see the full report comment with |
efd6 left a comment
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.
LGTM though nit and query. Also please wait for @andrewkroh
| type: group | ||
| fields: | ||
| - name: lat | ||
| description: Latitude coordinate | ||
| type: float | ||
| - name: lon | ||
| description: Longitude coordinate | ||
| type: float |
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 this because of geo's field reuse rules?
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.
Not sure what do you mean with the reuse rules. These fields are manually populated in the pipeline and mapping for them was missing, as they are not ECS.
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.
The reuse rules are at the bottom of this page and they do not list geo as reusable under related.
| | related.location.lat | Latitude coordinate | float | | ||
| | related.location.lon | Longitude coordinate | float | |
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.
This is not an ECS field, but it's been here almost since the package was originally published (0.3.0). It's unlikely to cause a conflict, but we may want to consider what we are going to do about it (not for now).
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.
These are all the non-ECS fields being added into ECS managed namespaces. There are three classes in my opinion.
Fields produced by beat processors that are always enabled (must keep).
- cloud.image.id
- host.containerized
- host.os.build
- host.os.codename
Never produced by beat processors or cel/httpjson inputs (can be removed).
- host.cpu.pct
- host.network.in.bytes
- host.network.in.packets
- host.network.out.bytes
- host.network.out.packets
New fields "created" in the box integration (should plan to remove).
- related.location.lat
- related.location.lon
- related.description
- related.indicator_typ
fydler analysis
ecsnamespace
Detect fields being added to namespaces controlled by ECS.
-
packages/box_events/data_stream/events/fields/agent.yml:4 cloud.image.id is defined in an ECS managed namespace, custom fields must use the dataset's namespace
-
packages/box_events/data_stream/events/fields/agent.yml:10 host.containerized is defined in an ECS managed namespace, custom fields must use the dataset's namespace
-
packages/box_events/data_stream/events/fields/agent.yml:15 host.os.build is defined in an ECS managed namespace, custom fields must use the dataset's namespace
-
packages/box_events/data_stream/events/fields/agent.yml:21 host.os.codename is defined in an ECS managed namespace, custom fields must use the dataset's namespace
-
packages/box_events/data_stream/events/fields/agent.yml:27 host.cpu.pct is defined in an ECS managed namespace, custom fields must use the dataset's namespace
-
packages/box_events/data_stream/events/fields/agent.yml:32 host.network.in.bytes is defined in an ECS managed namespace, custom fields must use the dataset's namespace
-
packages/box_events/data_stream/events/fields/agent.yml:37 host.network.in.packets is defined in an ECS managed namespace, custom fields must use the dataset's namespace
-
packages/box_events/data_stream/events/fields/agent.yml:42 host.network.out.bytes is defined in an ECS managed namespace, custom fields must use the dataset's namespace
-
packages/box_events/data_stream/events/fields/agent.yml:47 host.network.out.packets is defined in an ECS managed namespace, custom fields must use the dataset's namespace
-
packages/box_events/data_stream/events/fields/fields.yml:461 related.location.lat is defined in an ECS managed namespace, custom fields must use the dataset's namespace
-
packages/box_events/data_stream/events/fields/fields.yml:464 related.location.lon is defined in an ECS managed namespace, custom fields must use the dataset's namespace
-
packages/box_events/data_stream/events/fields/fields.yml:467 related.description is defined in an ECS managed namespace, custom fields must use the dataset's namespace
-
packages/box_events/data_stream/events/fields/fields.yml:470 related.indicator_type is defined in an ECS managed namespace, custom fields must use the dataset's namespace
Generated by fydler v0.0.0-20250910175042-5a5ea22c4415 5a5ea22c44150397a503f84105948a6fc294214d
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.
Agree
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.
@chemamartinez Can you please create an issue to follow-up on this problem.
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.
| "entries": [], | ||
| "next_stream_position": 4 | ||
| } | ||
| `}} |
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.
Final new line.
💚 Build Succeeded
History
|
|
| @chemamartinez Can you please post the request trace JSON logs from the system test to the PR description for review. |
| @andrewkroh couldn't find the request trace logs but I added the debug logs from the test that I think it can be enough to review its behaviour. |
| The request trace logs are in the |
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.
The request trace logs indicate that it's doing what I would expect. The one unvalidated assumption is that the API response when there is no more data is like
{ "chunk_size": 0, "entries": [], "next_stream_position": <big int> }
I looked there but forgot to defer the cleanup, I thought they are kept after the test finishes. Thanks! |
| Package box_events - 2.15.0 containing this change is available at https://epr.elastic.co/package/box_events/2.15.0/ |




Proposed commit message
Following changes added:
limitconfiguration for API queries, defaults to 500 as it is the maximum allowed value for the API.API reference: https://developer.box.com/reference/get-events/
Checklist
changelog.ymlfile.System test output
As interval is 10s, we can see the first two API calls are made during the first interval, and it wait another 10s to make the third one as the limit is higher than the count of returned events.
Request trace logs:
{"log.level":"debug","@timestamp":"2025-09-10T18:12:36.122Z","message":"HTTP request","transaction.id":"0PSN6GQTVPHHG-1","url.original":"http://svc-box-http:8080/oauth2/token","url.scheme":"http","url.path":"/oauth2/token","url.domain":"svc-box-http","url.port":"8080","url.query":"","http.request.method":"POST","http.request.header":{"Authorization":["Basic OGprNTEydzM5c2hvM3k5MjgybjBqNXZkeGw0eDZwbzg6OENONEoxVUx5NnB5UjZYQTZVOHBBWW0xQ0JVTk9OYzc="],"Content-Type":["application/x-www-form-urlencoded"]},"user_agent.original":"","http.request.body.content":"box_subject_id=19630872360&box_subject_type=user&grant_type=client_credentials","http.request.body.truncated":false,"http.request.body.bytes":78,"http.request.mime_type":"application/x-www-form-urlencoded","ecs.version":"1.6.0"} {"log.level":"debug","@timestamp":"2025-09-10T18:12:36.123Z","message":"HTTP response","transaction.id":"0PSN6GQTVPHHG-1","http.response.status_code":404,"http.response.body.content":"","http.response.body.truncated":false,"http.response.body.bytes":0,"http.response.mime_type":"","http.response.header":{"Content-Length":["0"],"Date":["Wed, 10 Sep 2025 18:12:36 GMT"]},"ecs.version":"1.6.0"} {"log.level":"debug","@timestamp":"2025-09-10T18:12:36.123Z","message":"HTTP request","transaction.id":"0PSN6GQTVPHHG-2","url.original":"http://svc-box-http:8080/oauth2/token","url.scheme":"http","url.path":"/oauth2/token","url.domain":"svc-box-http","url.port":"8080","url.query":"","http.request.method":"POST","http.request.header":{"Content-Type":["application/x-www-form-urlencoded"]},"user_agent.original":"","http.request.body.content":"box_subject_id=19630872360&box_subject_type=user&client_id=8jk512w39sho3y9282n0j5vdxl4x6po8&client_secret=8CN4J1ULy6pyR6XA6U8pAYm1CBUNONc7&grant_type=client_credentials","http.request.body.truncated":false,"http.request.body.bytes":168,"http.request.mime_type":"application/x-www-form-urlencoded","ecs.version":"1.6.0"} {"log.level":"debug","@timestamp":"2025-09-10T18:12:36.124Z","message":"HTTP response","transaction.id":"0PSN6GQTVPHHG-2","http.response.status_code":200,"http.response.body.content":"{\"access_token\":\"c3FIOG9vSGV4VHo4QzAyg5T1JvNnJoZ3ExaVNyQWw6WjRsanRKZG5lQk9qUE1BVQ\",\"expires_in\":3600,\"token_type\":\"bearer\",\"refresh_token\":\"c3FIOG9vSGV4VHo4QzAyg5T1JvNnJoZ3ExaVNyQWw6WjRsanRKZG5lQk9qUE1BVQ\",\"issued_token_type\":\"urn:ietf:params:oauth:token-type:access_token\"}","http.response.body.truncated":false,"http.response.body.bytes":274,"http.response.mime_type":"application/json","http.response.header":{"Content-Length":["274"],"Content-Type":["application/json"],"Date":["Wed, 10 Sep 2025 18:12:36 GMT"]},"ecs.version":"1.6.0"} {"log.level":"debug","@timestamp":"2025-09-10T18:12:36.124Z","message":"HTTP request","transaction.id":"0PSN6GQTVPHHG-3","url.original":"http://svc-box-http:8080/2.0/events?limit=2&stream_position=0&stream_type=all","url.scheme":"http","url.path":"/2.0/events","url.domain":"svc-box-http","url.port":"8080","url.query":"limit=2&stream_position=0&stream_type=all","http.request.method":"GET","http.request.header":{"Accept":["application/json"],"Authorization":["Bearer c3FIOG9vSGV4VHo4QzAyg5T1JvNnJoZ3ExaVNyQWw6WjRsanRKZG5lQk9qUE1BVQ"],"User-Agent":["Elastic-Filebeat/9.1.3 (linux; arm64; d9d2860c7593868e25d1b2da7da43793fe12c99e; 2025-08-23 00:02:13 +0000 UTC)"]},"user_agent.original":"Elastic-Filebeat/9.1.3 (linux; arm64; d9d2860c7593868e25d1b2da7da43793fe12c99e; 2025-08-23 00:02:13 +0000 UTC)","http.request.body.content":"","http.request.body.truncated":false,"http.request.body.bytes":0,"http.request.mime_type":"","ecs.version":"1.6.0"} {"log.level":"debug","@timestamp":"2025-09-10T18:12:36.125Z","message":"HTTP response","transaction.id":"0PSN6GQTVPHHG-3","http.response.status_code":200,"http.response.body.content":"{\"chunk_size\":2,\"entries\":[{\"source\":null,\"created_by\":{\"type\":\"user\",\"id\":\"2\",\"name\":\"Unknown User\",\"login\":\"\"},\"action_by\":null,\"created_at\":\"2019-12-20T11:38:56-08:00\",\"event_id\":\"97f1b31f-f143-4777-81f8-000000000001\",\"event_type\":\"SHIELD_ALERT\",\"ip_address\":\"10.1.2.3\",\"type\":\"event\",\"session_id\":null,\"additional_details\":{\"shield_alert\":{\"rule_category\":\"Anomalous Download\",\"rule_id\":123,\"rule_name\":\"Anomalous Download Rule\",\"risk_score\":77,\"alert_summary\":{\"description\":\"Significant increase in download content week over week, 9200% (25.04 MB) more than last week 12 additional files downloaded week over week)\",\"download_delta_size\":\"25 Mb\",\"download_delta_percent\":9200,\"historical_period\":{\"date_range\":{\"start_date\":\"2019-12-01T01:01:00-08:00\",\"end_date\":\"2019-12-08T01:01:00-08:00\"},\"download_size\":\"0 Mb\",\"downloaded_files_count\":1},\"anomaly_period\":{\"date_range\":{\"start_date\":\"2019-12-08T01:01:00-08:00\",\"end_date\":\"2019-12-15T01:01:00-08:00\"},\"download_size\":\"25 Mb\",\"downloaded_files_count\":13},\"download_ips\":[{\"ip\":\"1.128.0.0\"},{\"ip\":\"175.16.199.0\"}]},\"alert_id\":444,\"priority\":\"medium\",\"user\":{\"id\":567,\"name\":\"Some user\",\"email\":\"some@user.com\"},\"link\":\"https://cloud.app.box.com/master/shield/alerts/444\",\"created_at\":\"2019-12-20T11:38:16-08:00\"}}},{\"created_at\":\"2022-06-27T05:09:40-07:00\",\"created_by\":{\"id\":\"19530772260\",\"login\":\"info@elastic.co\",\"name\":\"Elastic Integrations\",\"type\":\"user\"},\"event_id\":\"97f1b31f-f143-4777-81f8-000000000002\",\"event_type\":\"ITEM_CREATE\",\"recorded_at\":\"2022-06-27T05:09:41-07:00\",\"session_id\":\"rzraadh3n273zc5f\",\"source\":{\"content_created_at\":\"2022-06-27T05:09:40-07:00\",\"content_modified_at\":\"2022-06-27T05:09:40-07:00\",\"created_at\":\"2022-06-27T05:09:40-07:00\",\"created_by\":{\"id\":\"19530772260\",\"login\":\"info@elastic.co\",\"name\":\"Elastic Integrations\",\"type\":\"user\"},\"description\":\"\",\"etag\":\"0\",\"folder_upload_email\":null,\"id\":\"166233012413\",\"item_status\":\"active\",\"modified_at\":\"2022-06-27T05:09:40-07:00\",\"modified_by\":{\"id\":\"19530772260\",\"login\":\"info@elastic.co\",\"name\":\"Elastic Integrations\",\"type\":\"user\"},\"name\":\"Platform App Diagnostics run on 2022-06-27 05-09-38 PDT\",\"owned_by\":{\"id\":\"19530772260\",\"login\":\"info@elastic.co\",\"name\":\"Elastic Integrations\",\"type\":\"user\"},\"parent\":{\"etag\":\"0\",\"id\":\"166232910591\",\"name\":\"Box Reports\",\"sequence_id\":\"0\",\"type\":\"folder\"},\"path_collection\":{\"entries\":[{\"etag\":null,\"id\":\"0\",\"name\":\"All Files\",\"sequence_id\":null,\"type\":\"folder\"},{\"etag\":\"0\",\"id\":\"166232910591\",\"name\":\"Box Reports\",\"sequence_id\":\"0\",\"type\":\"folder\"}],\"total_count\":2},\"purged_at\":null,\"sequence_id\":\"0\",\"shared_link\":null,\"size\":0,\"synced\":false,\"trashed_at\":null,\"type\":\"folder\"},\"type\":\"event\"}],\"next_stream_position\":1152922976252290800}","http.response.body.truncated":false,"http.response.body.bytes":2721,"http.response.mime_type":"application/json; charset=utf-8","http.response.header":{"Content-Type":["application/json; charset=utf-8"],"Date":["Wed, 10 Sep 2025 18:12:36 GMT"]},"ecs.version":"1.6.0"} {"log.level":"debug","@timestamp":"2025-09-10T18:12:38.115Z","message":"HTTP request","transaction.id":"0PSN6GQTVPHHG-4","url.original":"http://svc-box-http:8080/2.0/events?limit=2&stream_position=1152922976252290816&stream_type=all","url.scheme":"http","url.path":"/2.0/events","url.domain":"svc-box-http","url.port":"8080","url.query":"limit=2&stream_position=1152922976252290816&stream_type=all","http.request.method":"GET","http.request.header":{"Accept":["application/json"],"Authorization":["Bearer c3FIOG9vSGV4VHo4QzAyg5T1JvNnJoZ3ExaVNyQWw6WjRsanRKZG5lQk9qUE1BVQ"],"User-Agent":["Elastic-Filebeat/9.1.3 (linux; arm64; d9d2860c7593868e25d1b2da7da43793fe12c99e; 2025-08-23 00:02:13 +0000 UTC)"]},"user_agent.original":"Elastic-Filebeat/9.1.3 (linux; arm64; d9d2860c7593868e25d1b2da7da43793fe12c99e; 2025-08-23 00:02:13 +0000 UTC)","http.request.body.content":"","http.request.body.truncated":false,"http.request.body.bytes":0,"http.request.mime_type":"","ecs.version":"1.6.0"} {"log.level":"debug","@timestamp":"2025-09-10T18:12:38.122Z","message":"HTTP response","transaction.id":"0PSN6GQTVPHHG-4","http.response.status_code":200,"http.response.body.content":"{\"chunk_size\":1,\"entries\":[{\"source\":null,\"created_by\":{\"type\":\"user\",\"id\":\"2\",\"name\":\"Unknown User\",\"login\":\"\"},\"action_by\":null,\"created_at\":\"2019-12-20T11:38:56-08:00\",\"event_id\":\"97f1b31f-f143-4777-81f8-000000000003\",\"event_type\":\"SHIELD_ALERT\",\"ip_address\":\"10.1.2.3\",\"type\":\"event\",\"session_id\":null,\"additional_details\":{\"shield_alert\":{\"rule_category\":\"Anomalous Download\",\"rule_id\":123,\"rule_name\":\"Anomalous Download Rule\",\"risk_score\":77,\"alert_summary\":{\"description\":\"Significant increase in download content week over week, 9200% (25.04 MB) more than last week 12 additional files downloaded week over week)\",\"download_delta_size\":\"25 Mb\",\"download_delta_percent\":9200,\"historical_period\":{\"date_range\":{\"start_date\":\"2019-12-01T01:01:00-08:00\",\"end_date\":\"2019-12-08T01:01:00-08:00\"},\"download_size\":\"0 Mb\",\"downloaded_files_count\":1},\"anomaly_period\":{\"date_range\":{\"start_date\":\"2019-12-08T01:01:00-08:00\",\"end_date\":\"2019-12-15T01:01:00-08:00\"},\"download_size\":\"25 Mb\",\"downloaded_files_count\":13},\"download_ips\":[{\"ip\":\"1.128.0.0\"},{\"ip\":\"175.16.199.0\"}]},\"alert_id\":444,\"priority\":\"medium\",\"user\":{\"id\":567,\"name\":\"Some user\",\"email\":\"some@user.com\"},\"link\":\"https://cloud.app.box.com/master/shield/alerts/444\",\"created_at\":\"2019-12-20T11:38:16-08:00\"}}}],\"next_stream_position\":3}","http.response.body.truncated":false,"http.response.body.bytes":1301,"http.response.mime_type":"application/json; charset=utf-8","http.response.header":{"Content-Length":["1301"],"Content-Type":["application/json; charset=utf-8"],"Date":["Wed, 10 Sep 2025 18:12:38 GMT"]},"ecs.version":"1.6.0"} {"log.level":"debug","@timestamp":"2025-09-10T18:12:48.126Z","message":"HTTP request","transaction.id":"0PSN6GQTVPHHG-5","url.original":"http://svc-box-http:8080/2.0/events?limit=2&stream_position=3&stream_type=all","url.scheme":"http","url.path":"/2.0/events","url.domain":"svc-box-http","url.port":"8080","url.query":"limit=2&stream_position=3&stream_type=all","http.request.method":"GET","http.request.header":{"Accept":["application/json"],"Authorization":["Bearer c3FIOG9vSGV4VHo4QzAyg5T1JvNnJoZ3ExaVNyQWw6WjRsanRKZG5lQk9qUE1BVQ"],"User-Agent":["Elastic-Filebeat/9.1.3 (linux; arm64; d9d2860c7593868e25d1b2da7da43793fe12c99e; 2025-08-23 00:02:13 +0000 UTC)"]},"user_agent.original":"Elastic-Filebeat/9.1.3 (linux; arm64; d9d2860c7593868e25d1b2da7da43793fe12c99e; 2025-08-23 00:02:13 +0000 UTC)","http.request.body.content":"","http.request.body.truncated":false,"http.request.body.bytes":0,"http.request.mime_type":"","ecs.version":"1.6.0"} {"log.level":"debug","@timestamp":"2025-09-10T18:12:48.127Z","message":"HTTP response","transaction.id":"0PSN6GQTVPHHG-5","http.response.status_code":200,"http.response.body.content":"{\"chunk_size\":0,\"entries\":[{\"source\":null,\"created_by\":{\"type\":\"user\",\"id\":\"4\",\"name\":\"Unknown User\",\"login\":\"\"},\"action_by\":null,\"created_at\":\"2019-12-20T11:38:56-08:00\",\"event_id\":\"97f1b31f-f143-4777-81f8-000000000004\",\"event_type\":\"SHIELD_ALERT\",\"ip_address\":\"10.1.2.3\",\"type\":\"event\",\"session_id\":null,\"additional_details\":{\"shield_alert\":{\"rule_category\":\"Anomalous Download\",\"rule_id\":123,\"rule_name\":\"Anomalous Download Rule\",\"risk_score\":77,\"alert_summary\":{\"description\":\"Significant increase in download content week over week, 9200% (25.04 MB) more than last week 12 additional files downloaded week over week)\",\"download_delta_size\":\"25 Mb\",\"download_delta_percent\":9200,\"historical_period\":{\"date_range\":{\"start_date\":\"2019-12-01T01:01:00-08:00\",\"end_date\":\"2019-12-08T01:01:00-08:00\"},\"download_size\":\"0 Mb\",\"downloaded_files_count\":1},\"anomaly_period\":{\"date_range\":{\"start_date\":\"2019-12-08T01:01:00-08:00\",\"end_date\":\"2019-12-15T01:01:00-08:00\"},\"download_size\":\"25 Mb\",\"downloaded_files_count\":13},\"download_ips\":[{\"ip\":\"1.128.0.0\"},{\"ip\":\"175.16.199.0\"}]},\"alert_id\":444,\"priority\":\"medium\",\"user\":{\"id\":567,\"name\":\"Some user\",\"email\":\"some@user.com\"},\"link\":\"https://cloud.app.box.com/master/shield/alerts/444\",\"created_at\":\"2025-12-20T11:38:16-08:00\"}}}],\"next_stream_position\":4}","http.response.body.truncated":false,"http.response.body.bytes":1301,"http.response.mime_type":"application/json; charset=utf-8","http.response.header":{"Content-Length":["1301"],"Content-Type":["application/json; charset=utf-8"],"Date":["Wed, 10 Sep 2025 18:12:48 GMT"]},"ecs.version":"1.6.0"}