Skip to content

Commit c577fbb

Browse files
[abnormal_security] Update pagination termination condition (#10860)
Update the pagination termination condition for the threat data stream so that pagination stops whenever nextPageNumber is not found in the response body. This should apply to both the /v1/threats and /v1/threats/:id endpoints.
1 parent db5288a commit c577fbb

File tree

7 files changed

+33
-86
lines changed

7 files changed

+33
-86
lines changed

packages/abnormal_security/_dev/deploy/docker/files/config.yml

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -323,23 +323,7 @@ rules:
323323
Content-Type:
324324
- 'application/json'
325325
body: |-
326-
{"threats":[{"threatId":"284712ab-6d8b-47b3-89d3-a314efef79e2"}],"pageNumber":2,"nextPageNumber":3}
327-
- path: /v1/threats
328-
methods: ['GET']
329-
query_params:
330-
filter: "{filter:.*}"
331-
pageNumber: 3
332-
pageSize: 1
333-
request_headers:
334-
Authorization:
335-
- "Bearer xxxx"
336-
responses:
337-
- status_code: 200
338-
headers:
339-
Content-Type:
340-
- 'application/json'
341-
body: |-
342-
{"threats":[],"pageNumber":3,"nextPageNumber":4}
326+
{"threats":[{"threatId":"284712ab-6d8b-47b3-89d3-a314efef79e2"}]}
343327
- path: /v1/threats/184712ab-6d8b-47b3-89d3-a314efef79e2
344328
methods: ['GET']
345329
query_params:
@@ -402,26 +386,9 @@ rules:
402386
"https://www.example.com/"
403387
]
404388
}
405-
],
406-
"pageNumber": 1,
407-
"nextPageNumber": 2
389+
]
408390
}
409391
`}}
410-
- path: /v1/threats/184712ab-6d8b-47b3-89d3-a314efef79e2
411-
methods: ['GET']
412-
query_params:
413-
pageNumber: 2
414-
pageSize: 1
415-
request_headers:
416-
Authorization:
417-
- "Bearer xxxx"
418-
responses:
419-
- status_code: 200
420-
headers:
421-
Content-Type:
422-
- 'application/json'
423-
body: |-
424-
{"threatId":"184712ab-6d8b-47b3-89d3-a314efef79e2","messages":[],"pageNumber":2,"nextPageNumber":3}
425392
- path: /v1/threats/284712ab-6d8b-47b3-89d3-a314efef79e2
426393
methods: ['GET']
427394
query_params:
@@ -483,23 +450,6 @@ rules:
483450
"https://www.example.com/"
484451
]
485452
}
486-
],
487-
"pageNumber": 1,
488-
"nextPageNumber": 2
453+
]
489454
}
490455
`}}
491-
- path: /v1/threats/284712ab-6d8b-47b3-89d3-a314efef79e2
492-
methods: ['GET']
493-
query_params:
494-
pageNumber: 2
495-
pageSize: 1
496-
request_headers:
497-
Authorization:
498-
- "Bearer xxxx"
499-
responses:
500-
- status_code: 200
501-
headers:
502-
Content-Type:
503-
- 'application/json'
504-
body: |-
505-
{"threatId":"284712ab-6d8b-47b3-89d3-a314efef79e2","messages":[],"pageNumber":2,"nextPageNumber":3}

packages/abnormal_security/changelog.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# newer versions go on top
2+
- version: "0.1.1"
3+
changes:
4+
- description: Update pagination termination condition in threat data stream.
5+
type: enhancement
6+
link: https://github.com/elastic/integrations/pull/10860
27
- version: "0.1.0"
38
changes:
49
- description: Initial release.

packages/abnormal_security/data_stream/threat/agent/stream/cel.yml.hbs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ program: |
5050
}
5151
}).do_request().as(resp, resp.StatusCode == 200 ?
5252
bytes(resp.Body).decode_json().as(body, {
53-
"worklist": body.threats.map(e, e.threatId),
53+
"worklist": body,
5454
"next": 0,
5555
})
5656
:
@@ -73,9 +73,9 @@ program: |
7373
))
7474
).as(state, state.with(
7575
!has(state.worklist) ? state : // Exit early due to GET failure.
76-
state.next < size(state.worklist) ?
76+
has(state.worklist.threats) && size(state.worklist.threats) > 0 ?
7777
request("GET",
78-
state.url.trim_right("/") + "/v1/threats/" + string(state.worklist[state.next]) + "?" + {
78+
state.url.trim_right("/") + "/v1/threats/" + string(state.worklist.threats[state.next].threatId) + "?" + {
7979
"pageSize": [string(state.page_size)],
8080
"pageNumber": [string(state.child_next_page)]
8181
}.format_query()
@@ -85,30 +85,25 @@ program: |
8585
}
8686
}).do_request().as(resp, resp.StatusCode == 200 ?
8787
bytes(resp.Body).decode_json().as(body,{
88-
"events": (
89-
size(body.messages) > 0 ?
90-
body.messages.map(e,{
91-
"message": e.encode_json(),
92-
})
93-
:
94-
[{"message":"retry"}]
95-
),
88+
"events": body.messages.map(e,{
89+
"message": e.encode_json(),
90+
}),
9691
"cursor": {
9792
"last_timestamp": state.end_time
9893
},
99-
"worklist": int(state.next) + 1 < size(state.worklist) || size(body.messages) > 0 ? state.worklist : [],
100-
"child_next_page": size(body.messages) > 0 ? int(state.child_next_page) + 1 : 1,
94+
"worklist": int(state.next) + 1 < size(state.worklist.threats) || has(body.nextPageNumber) ? state.worklist : {},
95+
"child_next_page": has(body.nextPageNumber) ? body.nextPageNumber : 1,
10196
"next": (
102-
size(body.messages) > 0 ?
97+
has(body.nextPageNumber) ?
10398
state.next
10499
:
105-
int(state.next) + 1 < size(state.worklist) ?
100+
int(state.next) + 1 < size(state.worklist.threats) ?
106101
int(state.next) + 1
107102
:
108103
0
109104
),
110-
"next_page": int(state.next) + 1 < size(state.worklist) || size(body.messages) > 0 ? state.next_page : int(state.next_page) + 1,
111-
"want_more": true,
105+
"next_page": int(state.next) + 1 < size(state.worklist.threats) || has(body.nextPageNumber) ? state.next_page : has(state.worklist.nextPageNumber) ? state.worklist.nextPageNumber : 1,
106+
"want_more": int(state.next) + 1 < size(state.worklist.threats) || has(body.nextPageNumber) || has(state.worklist.nextPageNumber),
112107
})
113108
:
114109
{

packages/abnormal_security/data_stream/threat/elasticsearch/ingest_pipeline/default.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ processors:
99
tag: data_collection_error
1010
if: ctx.error?.message != null && ctx.message == null && ctx.event?.original == null
1111
message: error message set and no data to process.
12-
- drop:
13-
if: ctx.message == 'retry'
14-
tag: drop_retry_events
1512
- rename:
1613
field: message
1714
tag: rename_message_to_event_original

packages/abnormal_security/data_stream/threat/sample_event.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,22 @@
4545
}
4646
},
4747
"agent": {
48-
"ephemeral_id": "3cfaa9dc-bca8-4e29-a807-77b68709b731",
49-
"id": "7aaba523-565c-4597-bc42-59135436336b",
50-
"name": "docker-fleet-agent",
48+
"ephemeral_id": "b66f399f-ba1c-4fe5-af82-9ca7a0204545",
49+
"id": "e2eadaf0-613d-41d9-913c-96125e06487a",
50+
"name": "elastic-agent-55334",
5151
"type": "filebeat",
5252
"version": "8.13.0"
5353
},
5454
"data_stream": {
5555
"dataset": "abnormal_security.threat",
56-
"namespace": "37330",
56+
"namespace": "45319",
5757
"type": "logs"
5858
},
5959
"ecs": {
6060
"version": "8.11.0"
6161
},
6262
"elastic_agent": {
63-
"id": "7aaba523-565c-4597-bc42-59135436336b",
63+
"id": "e2eadaf0-613d-41d9-913c-96125e06487a",
6464
"snapshot": false,
6565
"version": "8.13.0"
6666
},
@@ -88,7 +88,7 @@
8888
],
8989
"dataset": "abnormal_security.threat",
9090
"id": "2260288475997441000",
91-
"ingested": "2024-08-08T06:53:48Z",
91+
"ingested": "2024-08-23T05:40:07Z",
9292
"kind": "enrichment",
9393
"original": "{\"abxMessageId\":2260288475997441000,\"abxPortalUrl\":\"https://portal.abnormalsecurity.com/home/threat-center/remediation-history/3456765434567654\",\"attachmentCount\":0,\"attachmentNames\":[],\"attackStrategy\":\"Unknown Sender\",\"attackType\":\"Spam\",\"attackVector\":\"Link\",\"attackedParty\":\"Employee (Other)\",\"autoRemediated\":true,\"ccEmails\":[],\"fromAddress\":\"john@example.com\",\"fromName\":\"john\",\"impersonatedParty\":\"None / Others\",\"internetMessageId\":\"\\u003cAZz8NUMEST-qmuz77_koic@example\\u003e\",\"isRead\":false,\"postRemediated\":false,\"receivedTime\":\"2024-07-17T23:25:38Z\",\"recipientAddress\":\"bob@example.com\",\"remediationStatus\":\"Auto-Remediated\",\"remediationTimestamp\":\"2024-07-17T23:25:45.73564Z\",\"replyToEmails\":[],\"returnPath\":\"bounce-bob_H181S7GUCF@example.com\",\"senderDomain\":\"example.com\",\"senderIpAddress\":\"81.2.69.142\",\"sentTime\":\"2024-07-17T23:25:29Z\",\"subject\":\"YoU.have.𝗪𝟬0𝗡𝗡 a K0baIt 215-piece_ToooI_Set_Noo0wW..#GBOB\",\"summaryInsights\":[\"Abnormal Email Body HTML\",\"Invisible characters found in Email\",\"Suspicious Link\",\"Unusual Sender\",\"Unusual Sender Domain\"],\"threatId\":\"bf255f2d-a2ad-3f50-5075-fdcc24308bbd\",\"toAddresses\":[\"bob@example.com\"],\"urlCount\":1,\"urls\":[\"https://www.example.com/\"]}",
9494
"reference": "https://portal.abnormalsecurity.com/home/threat-center/remediation-history/3456765434567654",

packages/abnormal_security/docs/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -498,22 +498,22 @@ An example event for `threat` looks as following:
498498
}
499499
},
500500
"agent": {
501-
"ephemeral_id": "3cfaa9dc-bca8-4e29-a807-77b68709b731",
502-
"id": "7aaba523-565c-4597-bc42-59135436336b",
503-
"name": "docker-fleet-agent",
501+
"ephemeral_id": "b66f399f-ba1c-4fe5-af82-9ca7a0204545",
502+
"id": "e2eadaf0-613d-41d9-913c-96125e06487a",
503+
"name": "elastic-agent-55334",
504504
"type": "filebeat",
505505
"version": "8.13.0"
506506
},
507507
"data_stream": {
508508
"dataset": "abnormal_security.threat",
509-
"namespace": "37330",
509+
"namespace": "45319",
510510
"type": "logs"
511511
},
512512
"ecs": {
513513
"version": "8.11.0"
514514
},
515515
"elastic_agent": {
516-
"id": "7aaba523-565c-4597-bc42-59135436336b",
516+
"id": "e2eadaf0-613d-41d9-913c-96125e06487a",
517517
"snapshot": false,
518518
"version": "8.13.0"
519519
},
@@ -541,7 +541,7 @@ An example event for `threat` looks as following:
541541
],
542542
"dataset": "abnormal_security.threat",
543543
"id": "2260288475997441000",
544-
"ingested": "2024-08-08T06:53:48Z",
544+
"ingested": "2024-08-23T05:40:07Z",
545545
"kind": "enrichment",
546546
"original": "{\"abxMessageId\":2260288475997441000,\"abxPortalUrl\":\"https://portal.abnormalsecurity.com/home/threat-center/remediation-history/3456765434567654\",\"attachmentCount\":0,\"attachmentNames\":[],\"attackStrategy\":\"Unknown Sender\",\"attackType\":\"Spam\",\"attackVector\":\"Link\",\"attackedParty\":\"Employee (Other)\",\"autoRemediated\":true,\"ccEmails\":[],\"fromAddress\":\"john@example.com\",\"fromName\":\"john\",\"impersonatedParty\":\"None / Others\",\"internetMessageId\":\"\\u003cAZz8NUMEST-qmuz77_koic@example\\u003e\",\"isRead\":false,\"postRemediated\":false,\"receivedTime\":\"2024-07-17T23:25:38Z\",\"recipientAddress\":\"bob@example.com\",\"remediationStatus\":\"Auto-Remediated\",\"remediationTimestamp\":\"2024-07-17T23:25:45.73564Z\",\"replyToEmails\":[],\"returnPath\":\"bounce-bob_H181S7GUCF@example.com\",\"senderDomain\":\"example.com\",\"senderIpAddress\":\"81.2.69.142\",\"sentTime\":\"2024-07-17T23:25:29Z\",\"subject\":\"YoU.have.𝗪𝟬0𝗡𝗡 a K0baIt 215-piece_ToooI_Set_Noo0wW..#GBOB\",\"summaryInsights\":[\"Abnormal Email Body HTML\",\"Invisible characters found in Email\",\"Suspicious Link\",\"Unusual Sender\",\"Unusual Sender Domain\"],\"threatId\":\"bf255f2d-a2ad-3f50-5075-fdcc24308bbd\",\"toAddresses\":[\"bob@example.com\"],\"urlCount\":1,\"urls\":[\"https://www.example.com/\"]}",
547547
"reference": "https://portal.abnormalsecurity.com/home/threat-center/remediation-history/3456765434567654",

packages/abnormal_security/manifest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
format_version: 3.2.1
22
name: abnormal_security
33
title: Abnormal Security
4-
version: 0.1.0
4+
version: 0.1.1
55
description: Collect logs from Abnormal Security with Elastic Agent.
66
type: integration
77
categories:

0 commit comments

Comments
 (0)