Skip to content

Commit 80d4209

Browse files
authored
[Filebeat][okta] Fix okta pagination (#21797)
* Fix okta pagination * Use cursor storage
1 parent 325ee32 commit 80d4209

6 files changed

Lines changed: 16 additions & 6 deletions

File tree

x-pack/filebeat/input/httpjson/date_cursor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ func newDateCursorFromConfig(config config, log *logp.Logger) *dateCursor {
4141
c.urlField = config.DateCursor.URLField
4242
c.initialInterval = config.DateCursor.InitialInterval
4343
c.dateFormat = config.DateCursor.getDateFormat()
44-
c.valueTpl = config.DateCursor.ValueTemplate.Template
44+
if config.DateCursor.ValueTemplate != nil {
45+
c.valueTpl = config.DateCursor.ValueTemplate.Template
46+
}
4547

4648
return c
4749
}

x-pack/filebeat/input/httpjson/pagination.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (p *pagination) nextRequestInfo(ri *requestInfo, response response, lastObj
7272

7373
// getNextLinkFromHeader retrieves the next URL for pagination from the HTTP Header of the response
7474
func getNextLinkFromHeader(header http.Header, fieldName string, re *regexp.Regexp) (string, error) {
75-
links, ok := header[fieldName]
75+
links, ok := header[http.CanonicalHeaderKey(fieldName)]
7676
if !ok {
7777
return "", fmt.Errorf("field %s does not exist in the HTTP Header", fieldName)
7878
}

x-pack/filebeat/input/httpjson/pagination_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
func TestGetNextLinkFromHeader(t *testing.T) {
1616
header := make(http.Header)
17-
header.Add("Link", "<https://dev-168980.okta.com/api/v1/logs>; rel=\"self\"")
17+
header.Add("link", "<https://dev-168980.okta.com/api/v1/logs>; rel=\"self\"")
1818
header.Add("Link", "<https://dev-168980.okta.com/api/v1/logs?after=1581658181086_1>; rel=\"next\"")
1919
re, _ := regexp.Compile("<([^>]+)>; *rel=\"next\"(?:,|$)")
2020
url, err := getNextLinkFromHeader(header, "Link", re)

x-pack/filebeat/input/httpjson/requester.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func (r *requester) processHTTPRequest(ctx context.Context, publisher cursor.Pub
113113
return err
114114
}
115115

116+
response.header = resp.Header
116117
responseData, err := ioutil.ReadAll(resp.Body)
117118
if err != nil {
118119
return fmt.Errorf("failed to read http response: %w", err)
@@ -165,10 +166,10 @@ func (r *requester) processHTTPRequest(ctx context.Context, publisher cursor.Pub
165166
if err != nil {
166167
return err
167168
}
168-
}
169169

170-
if lastObj != nil && r.dateCursor.enabled {
171-
r.updateCursorState(ri.url, r.dateCursor.getNextValue(common.MapStr(lastObj)))
170+
if lastObj != nil && r.dateCursor.enabled {
171+
r.updateCursorState(ri.url, r.dateCursor.getNextValue(common.MapStr(lastObj)))
172+
}
172173
}
173174

174175
return nil

x-pack/filebeat/module/okta/system/config/input.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ ssl: {{ .ssl | tojson }}
4444
url: {{ .url }}
4545
{{ end }}
4646

47+
date_cursor.field: published
48+
date_cursor.url_field: since
49+
date_cursor.initial_interval: {{ .initial_interval }}
50+
4751
{{ else if eq .input "file" }}
4852

4953
type: log

x-pack/filebeat/module/okta/system/manifest.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var:
88
default: "SSWS"
99
- name: http_client_timeout
1010
- name: http_method
11+
default: GET
1112
- name: http_headers
1213
- name: http_request_body
1314
- name: interval
@@ -31,6 +32,8 @@ var:
3132
- name: tags
3233
default: [forwarded]
3334
- name: url
35+
- name: initial_interval
36+
default: 24h
3437

3538
input: config/input.yml
3639
ingest_pipeline: ingest/pipeline.yml

0 commit comments

Comments
 (0)