Skip to content

Commit ca62d96

Browse files
authored
ti_threatconnect: fix handling of missing cursor.last_timestamp (elastic#13235)
It is possible to get into a state where the program expects there to be a last_timestamp in the cursor but none exists due to previous data being present but empty. Fix this by falling back to the look-back time if the last_timestamp is missing. Also reorganise the code to make the logic less opaque.
1 parent 1595cc1 commit ca62d96

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

packages/ti_threatconnect/changelog.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# newer versions go on top
22
# WARNING: this version number needs to be kept up to date in the transform!
3+
- version: "1.9.3"
4+
changes:
5+
- description: Prevent agent failure when last time stamp is missing in cursor.
6+
type: bugfix
7+
link: https://github.com/elastic/integrations/pull/13235
38
- version: "1.9.2"
49
changes:
510
- description: Add a compatibility pipeline to the transform.

packages/ti_threatconnect/data_stream/indicator/agent/stream/cel.yml.hbs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ redact:
7171
# milliseconds and if it ended in 0, that 0 would be dropped and TC TQL then would error on the timestamp.
7272
program: |
7373
['lastModified GEQ "'+(
74-
!state.want_more ?
75-
state.?cursor.last_timestamp.orValue((now - duration(state.initial_interval)).format(time_layout.RFC3339))
76-
:
77-
state.?cursor.first_timestamp.orValue("")
74+
state.want_more ?
75+
state.?cursor.first_timestamp.orValue("")
76+
:
77+
state.?cursor.last_timestamp.orValue((now - duration(state.initial_interval)).format(time_layout.RFC3339))
7878
)+'"'+(
7979
state.?tql_filter.orValue("") != "" ?
8080
" AND "+state.tql_filter.trim(" ")
@@ -127,23 +127,24 @@ program: |
127127
state.url.trim_right("/")
128128
),
129129
"cursor": {
130+
"first_timestamp": (
131+
!(has(body.data) && has(state.?cursor.first_timestamp)) ?
132+
// We don't have any data or a first_timestamp. Limit to look-back.
133+
string(now - duration(state.initial_interval))
134+
: (has(body.next) && body.next != null && body.next != "") ?
135+
// want_more is true, so limit to first timestamp.
136+
state.cursor.first_timestamp
137+
:
138+
// We have data, but want_more is false, limit to last available
139+
// timestamp falling back to look-back.
140+
state.?cursor.last_timestamp.orValue(string(now - duration(state.initial_interval)))
141+
),
130142
?"last_timestamp": (
131143
has(body.data) && body.data.size() > 0 ?
132144
optional.of(body.data.map(e, timestamp(e.lastModified)).max() + duration("1s"))
133145
:
134146
state.?cursor.last_timestamp
135147
),
136-
"first_timestamp": (
137-
has(body.data) && state.?cursor.first_timestamp.orValue(null) != null ?
138-
(
139-
has(body.next) && body.next != null && body.next != "" ?
140-
state.cursor.first_timestamp
141-
:
142-
state.cursor.last_timestamp
143-
)
144-
:
145-
string(now - duration(state.initial_interval))
146-
),
147148
}
148149
})
149150
:

packages/ti_threatconnect/elasticsearch/transform/latest/transform.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ source:
99
# us that ability in order to prevent having duplicate IoC data and prevent query
1010
# time field type conflicts.
1111
dest:
12-
index: "logs-ti_threatconnect_latest.dest_indicator-5"
13-
pipeline: "1.9.2-tactics_compatibility"
12+
index: "logs-ti_threatconnect_latest.dest_indicator-6"
13+
pipeline: "1.9.3-tactics_compatibility"
1414
aliases:
1515
- alias: "logs-ti_threatconnect_latest.indicator"
1616
move_on_creation: true
@@ -33,4 +33,4 @@ _meta:
3333
managed: true
3434
# Bump this version to delete, reinstall, and restart the transform during package.
3535
# Version bump is needed if there is any code change in transform.
36-
fleet_transform_version: 0.5.0
36+
fleet_transform_version: 0.6.0

packages/ti_threatconnect/manifest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
format_version: 3.0.3
33
name: ti_threatconnect
44
title: ThreatConnect
5-
version: "1.9.2"
5+
version: "1.9.3"
66
description: Collects Indicators from ThreatConnect using the Elastic Agent and saves them as logs inside Elastic
77
type: integration
88
categories:

0 commit comments

Comments
 (0)