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

[Filebeat] httpjson input dot notation in last response #30476

Closed
leehinman opened this issue Feb 18, 2022 · 4 comments
Closed

[Filebeat] httpjson input dot notation in last response #30476

leehinman opened this issue Feb 18, 2022 · 4 comments
Assignees
Labels

Comments

@leehinman
Copy link
Contributor

leehinman commented Feb 18, 2022

In 8.0.0 the keys for last_response have "url.params" instead of url
& params being structs with accessible fields.

Steps to Reproduce

API server

Small API server written in Flask.

#!/usr/bin/env python3

from flask import Flask, json

companies = {"id": 1, "name": "Company One"}

api = Flask(__name__)

@api.route('/companies', methods=['GET'])
def get_companies():
  return json.dumps(companies)

if __name__ == '__main__':
    api.run() 

httpjson config

- type: httpjson
  enabled: true
  interval: 5s
  request.method: "GET"
  request.url: http://localhost:5000/companies
  request.transforms:
    - set:
        target: url.params.start
        value: "[[.cursor.last_execution_datetime]]"
        default: '[[formatDate ((now).Add (parseDuration "-5s"))]]'
    - set:
        target: url.params.end
        value: '[[formatDate ((parseDate .cursor.last_execution_datetime).Add (parseDuration "5s"))]]'
        default: '[[formatDate now]]'
  cursor:
    last_execution_datetime:
       value: '[[.last_response]]'

Results

{
  "log.level": "debug",
  "@timestamp": "2022-02-18T10:57:57.058-0600",
  "log.logger": "input.httpjson-cursor",
  "log.origin": {
    "file.name": "httpjson/cursor.go",
    "file.line": 56
  },
  "message": "cursor.last_execution_datetime stored with {\"body\":{\"id\":1,\"name\":\"Company One\"},\"header\":{\"Content-Length\":[\"32\"],\"Content-Type\":[\"text/html; charset=utf-8\"],\"Date\":[\"Fri, 18 Feb 2022 16:57:57 GMT\"],\"Server\":[\"Werkzeug/2.0.3 Python/3.9.10\"]},\"page\":1,\"url.params\":{\"end\":[\"2022-02-18T16:57:57Z\"],\"start\":[\"2022-02-18T16:57:52Z\"]},\"url.value\":\"http://localhost:5000/companies?end=2022-02-18T16%3A57%3A57Z\\u0026start=2022-02-18T16%3A57%3A52Z\"}",
  "service.name": "filebeat",
  "id": "D60AF34257EE2D7B",
  "input_source": "http://localhost:5000/companies",
  "input_url": "http://localhost:5000/companies",
  "ecs.version": "1.6.0"
}

notice key names of "url.params" and "url.value"

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Feb 18, 2022
@leehinman leehinman changed the title [httpjson input] dot notation in last response [Filebeat] httpjson input dot notation in last response Feb 18, 2022
@elasticmachine
Copy link
Collaborator

Pinging @elastic/security-external-integrations (Team:Security-External Integrations)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Feb 18, 2022
@leehinman leehinman added the bug label Feb 18, 2022
@andrewkroh
Copy link
Member

I think this was fixed, but a backport for 8.0 was missed in #28695. Looks like this change fixed it, but I'm not 100% sure.

https://github.com/elastic/beats/pull/28695/files#diff-38319f0690a1641fe887515fd856de7714b72235b98094d9caee38d13dcd8bc8R180

@leehinman
Copy link
Contributor Author

Backport of #28695 should get us to the behavior in #30477 , I just wanted to document that 7.x and 8.x both had issues around the data stored in .last_response but in different way. Just so we didn't fix one but not the other.

@marc-gr
Copy link
Contributor

marc-gr commented Feb 28, 2022

Did the missing backport to 8.0. #30574

@marc-gr marc-gr closed this as completed Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants