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] Add support for accessing response variable of previous request in chain call #32955

Closed
vinit-chauhan opened this issue Sep 1, 2022 · 6 comments
Assignees

Comments

@vinit-chauhan
Copy link
Contributor

Describe the enhancement:

Request 1: To get uuid
	Url :  /get/uuid
Response:
 {
“user_uuid” : “123-abc”
}

Request 2: To get asset list 
	Url :  /get/assets/{user_uuid}/list
Response:
 {
  “asset_list” : [
       asset_1, 
       asset_2,
       asset_3,
       asset_4
       ]
 }
Request 3: To asset detail
	Url :  /get/assets/{user_uuid}/detail/{asset_id}
Response:
 {
    "id": "95c2725c-72",
    "name": “user-windows”,
}

Here from request 1 we can get the value of user_uuid which will be used for making a second call to find the list of assets. So here we can make the second call with the use of replace in chain call.
For request 3, we need to give user_uuid and asset_id in url params. We can get the asset_id from the response of request 2 using replace. But we are not able to use user_uuid in the request 3.

For fetching the value of user_uuid from the url params of the second request we have tried to use .last_response in both the request i.e request 2 and request 3 but we are getting .last_response as
{"body":null,"header":null,"page":0,"url":"xxxxx"}

So we are not able to make the request 3 because we don’t have user_uuid.

Describe a specific use case for the enhancement or feature:
https://developer.tenable.com/reference/exports-assets-download-chunk

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Sep 1, 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 Sep 1, 2022
@ShourieG
Copy link
Contributor

ShourieG commented Sep 1, 2022

@vinit-elastic This is definitely possible currently , using a similar config as follows :

  • type: httpjson
    enabled: true
    id: sample-httpjson-id
    request.url: /get/uuid
    chain:
    • step:
      request.url: /get/assets/$.exportId/list
      request.method: GET
      replace: $.exportId
    • step:
      request.url: /get/assets/user_uuid/detail/$.asset_list[:].id
      request.method: GET
      replace: $.asset_list[:].id

We do not require the last response do achieve this

@vinit-chauhan
Copy link
Contributor Author

vinit-chauhan commented Sep 2, 2022

@ShourieG As you have mentioned is working perfectly.
However, It does not seem to match our use case. We need the value of user_uuid in URL params in Request 3 which we fetch from the response of Request 1. Basically, we would want to replace {user_uuid} with 123-abc, which we get from the initial request, in both steps, and {asset_id} with all the asset IDs in their respective chained call.

@ShourieG
Copy link
Contributor

ShourieG commented Sep 2, 2022

@vinit-elastic ok got it, but here the response that you want would want is the 1st response and not the last_response , since in step 3 last_response would mean the last_response of the chain. So maybe we could introduce something like first_response , that holds the response from the root request for access ?

@vinit-chauhan
Copy link
Contributor Author

@ShourieG - for first_response if you are suggesting implementing something like last_response, I'm not sure how we would use it to add previous values in the new request URLs. We could have used the value templates sprintf but is it possible to manipulate the string using it and then add the asset_id again?

@ShourieG ShourieG self-assigned this Sep 5, 2022
@andrewkroh
Copy link
Member

andrewkroh commented Sep 6, 2022

Relates / Blocks: elastic/integrations#2338

@epixa epixa changed the title [Filebeat][HTTP JSON][Enhancement] Add support for accessing response variable of previous request in chain call [Filebeat][httpjson] Add support for accessing response variable of previous request in chain call Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants