Skip to content
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

Update filebeat httpjson input to support pagination via Header and Okta module #16354

Merged
merged 21 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion x-pack/filebeat/docs/inputs/input-httpjson.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,32 @@ Time duration between repeated data retrievals. Default: 0s, meaning no repeated
If the HTTP API returns data in a JSON array, then this option can be set to decode these records
from the array. Default: not used.

[float]
==== `no_http_body`

If set, do not use HTTP request body. Default: false.

[float]
==== `pagination.enabled`

This option specifies whether pagination is enabled. Default: false.
This option specifies whether pagination is enabled. Default: true.

[float]
==== `pagination.extra_body_content`

Any additional data that needs to be set in the HTTP pagination request can be specified in
this JSON blob. Default: not used.

[float]
==== `pagination.header.field_name`

The field name in the HTTP Header that is used for pagination control.

[float]
==== `pagination.header.regex_pattern`

The regular expression pattern to use for retrieving the pagination information from the HTTP Header field specified above.

[float]
==== `pagination.id_field`

Expand All @@ -120,6 +135,22 @@ Required when pagination is enabled.
This specifies the URL for sending pagination request. Required if the pagination URL is different
than the HTTP API URL.

[float]
==== `rate_limit.limit`

This specifies the field in the HTTP Header of the response that specifies the total limit.

[float]
==== `rate_limit.remaining`

This specifies the field in the HTTP Header of the response that specifies the remaining quota of the rate limit.

[float]
==== `rate_limit.reset`

This specifies the field in the HTTP Header of the response that specifies the epoch time
when the rate limit will be reset.

[float]
==== `ssl`

Expand Down
62 changes: 50 additions & 12 deletions x-pack/filebeat/input/httpjson/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package httpjson

import (
"regexp"
"strings"
"time"

Expand All @@ -16,35 +17,72 @@ import (

// Config contains information about httpjson configuration
type config struct {
alakahakai marked this conversation as resolved.
Show resolved Hide resolved
APIKey string `config:"api_key"`
HTTPClientTimeout time.Duration `config:"http_client_timeout"`
HTTPHeaders common.MapStr `config:"http_headers"`
HTTPMethod string `config:"http_method" validate:"required"`
HTTPRequestBody common.MapStr `config:"http_request_body"`
Interval time.Duration `config:"interval"`
JSONObjects string `config:"json_objects_array"`
Pagination *Pagination `config:"pagination"`
TLS *tlscommon.Config `config:"ssl"`
URL string `config:"url" validate:"required"`
APIKey string `config:"api_key"`
AuthenticationScheme string `config:"authentication_scheme"`
HTTPClientTimeout time.Duration `config:"http_client_timeout"`
HTTPHeaders common.MapStr `config:"http_headers"`
HTTPMethod string `config:"http_method" validate:"required"`
HTTPRequestBody common.MapStr `config:"http_request_body"`
Interval time.Duration `config:"interval"`
JSONObjects string `config:"json_objects_array"`
NoHTTPBody bool `config:"no_http_body"`
Pagination *Pagination `config:"pagination"`
RateLimit *RateLimit `config:"rate_limit"`
TLS *tlscommon.Config `config:"ssl"`
URL string `config:"url" validate:"required"`
}

// Pagination contains information about httpjson pagination settings
type Pagination struct {
IsEnabled bool `config:"enabled"`
Enabled *bool `config:"enabled"`
ExtraBodyContent common.MapStr `config:"extra_body_content"`
Header *Header `config:"header"`
IDField string `config:"id_field"`
RequestField string `config:"req_field"`
URL string `config:"url"`
}

// IsEnabled returns true if the `enable` field is set to true in the yaml.
func (p *Pagination) IsEnabled() bool {
return p != nil && (p.Enabled == nil || *p.Enabled)
}

// HTTP Header information for pagination
type Header struct {
FieldName string `config:"field_name" validate:"required"`
RegexPattern *regexp.Regexp `config:"regex_pattern" validate:"required"`
}

// HTTP Header Rate Limit information
type RateLimit struct {
Limit string `config:"limit"`
Reset string `config:"reset"`
Remaining string `config:"remaining"`
}

func (c *config) Validate() error {
switch strings.ToUpper(c.HTTPMethod) {
case "GET":
break
case "POST":
break
default:
return errors.Errorf("httpjson input: Invalid http_method, %s - ", c.HTTPMethod)
return errors.Errorf("httpjson input: Invalid http_method, %s", c.HTTPMethod)
}
if c.NoHTTPBody {
if len(c.HTTPRequestBody) > 0 {
return errors.Errorf("invalid configuration: both no_http_body and http_request_body cannot be set simultaneously")
}
if c.Pagination != nil && (len(c.Pagination.ExtraBodyContent) > 0 || c.Pagination.RequestField != "") {
return errors.Errorf("invalid configuration: both no_http_body and pagination.extra_body_content or pagination.req_field cannot be set simultaneously")
}
}
if c.Pagination != nil {
if c.Pagination.Header != nil {
if c.Pagination.RequestField != "" || c.Pagination.IDField != "" || len(c.Pagination.ExtraBodyContent) > 0 {
return errors.Errorf("invalid configuration: both pagination.header and pagination.req_field or pagination.id_field or pagination.extra_body_content cannot be set simultaneously")
}
}
}
return nil
}
Expand Down
Loading