Skip to content

Commit db3793a

Browse files
committed
imperva_cloud_waf: handle case where cursor state cannot be found in log file index
The previous code assumes that it is possible to determine the remainder of work to be done by splitting on the last log file that was collected. This fails when the last log file collected is not in the log files that the index returns for whatever reason. In that case, use the complete index to start again on the basis that the cursor log file state has gone stale relative to the index returned by the API.
1 parent 7bcf6b5 commit db3793a

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

packages/imperva_cloud_waf/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: "1.12.2"
3+
changes:
4+
- description: Fix handling of API requests when the cursor state cannot be found in the log file index returned by Imperva.
5+
type: bugfix
6+
link: https://github.com/elastic/integrations/pull/14298
27
- version: "1.12.1"
38
changes:
49
- description: Fix ingest pipeline to handle whitespace in request URL.

packages/imperva_cloud_waf/data_stream/event/agent/stream/cel.yml.hbs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,20 @@ program: |
3131
"Authorization": ["Basic "+string(base64(state.user+":"+state.password))],
3232
}
3333
}).do_request().as(resp, resp.StatusCode == 200 ?
34-
bytes(resp.Body).as(body, {
34+
resp.Body.as(body, {
3535
"worklist": (
36-
has(state.cursor) && has(state.cursor.log_file) && state.cursor.log_file != null
37-
?
38-
string(body).split(state.cursor.log_file)[1].split("\n").filter(x,x!="").map(x,{"filename":x})
36+
has(state.?cursor.log_file) && state.cursor.log_file != null ?
37+
string(body).split(state.cursor.log_file)[?1].optMap(f,
38+
f.split("\n").map(x, x != "",
39+
{"filename":x}
40+
)
41+
).orValue(string(body).split("\n").map(x,
42+
{"filename":x}
43+
))
3944
:
40-
string(body).split("\n").map(x,{"filename":x})
45+
string(body).split("\n").map(x,
46+
{"filename":x}
47+
)
4148
),
4249
"next": 0,
4350
})
@@ -71,7 +78,7 @@ program: |
7178
"Authorization": ["Basic "+string(base64(state.user + ":" + state.password))],
7279
}
7380
}).do_request().as(resp, resp.StatusCode == 200 ?
74-
bytes(resp.Body).as(body, {
81+
resp.Body.as(body, {
7582
"events": try(string(body), "error").as(body, type(body) == type("") ?
7683
dyn((body+"|==|").split("|==|")[1].split("\n").filter(x,x!="").map(x,{"message":x}))
7784
:
@@ -90,8 +97,7 @@ program: |
9097
),
9198
"cursor": {
9299
"log_file": (
93-
has(state.cursor) && has(state.cursor.log_file) && state.cursor.log_file != null
94-
?
100+
has(state.?cursor.log_file) && state.cursor.log_file != null ?
95101
(
96102
(v.worklist[v.next].filename).split(".")[0] != (state.cursor.log_file).split(".")[0] ?
97103
v.worklist[v.next].filename

packages/imperva_cloud_waf/manifest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
format_version: 3.0.3
22
name: imperva_cloud_waf
33
title: Imperva Cloud WAF
4-
version: "1.12.1"
4+
version: "1.12.2"
55
description: Collect logs from Imperva Cloud WAF with Elastic Agent.
66
type: integration
77
categories:

0 commit comments

Comments
 (0)