Some help on inputs.http with cookies and for Nvidia DLS API calls

Hello

i need some help to collet data from Nvidia DLS API (it’s a NVidia license server onpremise) that got an API Swagger.

to access the data we must get an Beare token with an API token

the below command get the bearer token that we will reuse on the comamnds to get the usefull data

curl -X POST \
'https://<url-to-nvidia-dls>/auth/v1/api-key-token' \
--header 'Accept: */*' \
--header 'x-api-key: <api-token>'

and using the data received by the previous command we do the API calls needed

curl -X GET \
'https://<url-to-nvidia-dls>/admin/v1/org/<id/virtual-groups/43949/leases>' \
--header 'Accept: */*' \
--header 'Authorization: bearer <token recevied from the previous command>'

so with this command i try to adapt it to telegraf inputs.http

but i’m confused on how i can reuse the data from the cookie in the header of the real uri to get the data.

i may be wrong on the process, please do not hesitate to suggest any correction

[[inputs.http]]
  ## One or more URLs from which to read formatted metrics.
  urls = [ "https://<url-to-nvidia-dls>/admin/v1/org/<id/virtual-groups/43949/leases>" ]

  ## HTTP method
  method = "GET"

  ## Optional HTTP headers
  headers = {"Accept" = "*/*", "Authorization" = "bearer <==token recevied from the previous command==>"}

  ## Optional TLS Config
  insecure_skip_verify = true

  ## Optional Cookie authentication
  cookie_auth_url = "https://<url-to-nvidia-dls>/auth/v1/api-key-token"
  cookie_auth_method = "POST"
  cookie_auth_headers = { "Accept" = "*/*", "x-api-key" = "@{local_secrets:api-token}" }

  data_format = "json"

@tonic8 the correct solution would be to add a new plugin for the NVidia DLS server. You can add a feature request or, even better, provide a pull-request… :slight_smile:

ahhh that’s “cheating” :sweat_smile:

Technically i can use “inputs.exec” and execute a script.

i wanted a more “telegraf native”, but without thinking to go direct for a new plugin.

i will see for the feature request, unfortunately my dev level never go upper than scripting.

feature request plugin for Nvidia DLS (Delegated License Service) Appliance licenses usage · Issue #16119 · influxdata/telegraf · GitHub
:grinning:

Now we only need someone to implement it… :stuck_out_tongue_winking_eye:

yes. and i pay for :coffee: for it

while waiting for this very gentle person. i try ti work on a workarround :grinning:

tehcnically i could execute the request for the bearer token outside telegraf and save it in a file (through a cron the token have a lifetime, so i will need to update it regularly).

as in the inputs.http there is an option for bearer token :

  ## Optional Bearer token settings to use for the API calls.
  ## Use either the token itself or the token file if you need a token.
  # token = "eyJhbGc...Qssw5c"
  # token_file = "/path/to/file"

i did some tests:

  • using the token setting with the bearer token in the telegraf config it’s working
  • using the **token_file ** setting with the bearer token in a file it’s not working

i checked in case i mispelled the path (and telegraf telle me it can find the file.

so the location is good and inside the file there is only the same string than using “token” i got a status code 401

  • and i checked the token is not expired.

i don’t see any specific details on the file in the documentation (specific format or else), so i presume is a simple line file.

any suggestion?