HTTP JSON.md

使用htpjson输入从带有JSON payloads的HTTP API读取消息。

This input supports:

  • Auth
    • Basic
    • OAuth2
  • Retrieval at a configurable interval:以可配置的间隔检索
  • Pagination:分页
  • Retries:重试
  • Rate limiting:速率限制
  • Proxying:代理
  • Request transformations:请求转换
  • Response transformations:响应转换

示例配置:

filebeat.inputs:
# Fetch your public IP every minute.
- type: httpjson
  interval: 1m
  request.url: https://api.ipify.org/?format=json
  processors:
    - decode_json_fields:
        fields: ["message"]
        target: "json"
filebeat.inputs:
- type: httpjson
  request.url: http://localhost:9200/_search?scroll=5m
  request.method: POST
  response.split:
    target: body.hits.hits
  response.pagination:
    - set:
        target: url.value
        value: http://localhost:9200/_search/scroll
    - set:
        target: url.params.scroll_id
        value: '[[.last_response.body._scroll_id]]'
    - set:
        target: body.scroll
        value: 5m

此外,它还支持通过Basic auth、HTTP Headers或oauth2进行身份验证。

Example configurations with authentication:

filebeat.inputs:
- type: httpjson
  request.url: http://localhost
  request.transforms:
    - set:
        target: header.Authorization
        value: 'Basic aGVsbG86d29ybGQ='
filebeat.inputs:
- type: httpjson
  auth.oauth2:
    client.id: 12345678901234567890abcdef
    client.secret: abcdef12345678901234567890
    token_url: http://localhost/oauth2/token
  request.url: http://localhost
filebeat.inputs:
- type: httpjson
  auth.oauth2:
    client.id: 12345678901234567890abcdef
    client.secret: abcdef12345678901234567890
    token_url: http://localhost/oauth2/token
    user: user@domain.tld
    password: P@$$W0₹D
  request.url: http://localhost

输入状态

httpjson输入在请求之间保持运行时状态。可以通过一些配置选项和转换访问此状态。

状态有以下要素:

  • last_response.url.value:The full URL with params and fragments from the last request with a successful response.
  • last_response.url.params:A url.Values of the params from the URL in last_response.url.value. Can be queried with the Get function.
  • last_response.header:A map containing the headers from the last successful response.
  • last_response.body:A map containing the parsed JSON body from the last successful response. This is the response as it comes from the remote server.
  • last_response.page:A number indicating the page number of the last response. It starts with the value 0 at every interval.
  • first_event:A map representing the first event sent to the output (result from applying transforms to last_response.body).
  • last_event:A map representing the last event of the current request in the requests chain (result from applying transforms to last_response.body).
  • url:The last requested URL as a raw url.URL Go type.
  • header:A map containing the headers. References the next request headers when used in request.rate_limit.early_limit or response.pagination configuration sections, and to the last response headers when used in response.transforms, response.split, or request.rate_limit.limit configuration sections.
  • body:A map containing the body. References the next request body when used in request.rate_limit.early_limit or response.pagination configuration sections, and to the last response body when used in response.transforms or response.split configuration sections.
  • cursor:A map containing any data the user configured to be stored between restarts (See cursor).

除了cursor,所有提到的对象仅在运行时存储,它的值在重新启动之间保持不变。

。。。


HTTP JSON.md
http://blog.lujinkai.cn/运维/ELK/filebeats/配置/inputs/HTTP JSON/
作者
像方便面一样的男子
发布于
2023年12月5日
许可协议