Get unix timestamp and pass as parameter - Telegraf inputs.http

Hi All,
I am trying to collect data from a rest api end point that requires a startTime and endTime to be passed in the URL. Is it possible to set the current unix timestamp and current unix timestamp -30 to variables and then pass these variables in the URL to my startTime and endTime?

Telegraf 1.15.3 running on Windows. Inputs config below

###############################################################################
#                                  INPUTS                                     #
###############################################################################
# Read formatted metrics from one or more HTTP endpoints
[[inputs.http]]
  
  ## Overwrite measurement name from default `http` to `NetScout`
  name_override = "netscout"
  
  ## One or more URLs from which to read formatted metrics
  urls = [
    "https://MY_ENDPOINT_IP/api/aed/v2/traffic/?startTime=1602180530&endTime=1602180600"
  ]
  
  ## HTTP method
  method = "GET"

  ## Optional HTTP headers
  headers = {"X-Arbux-APIToken" = "MY_TOKEN_DATE"}

  ## HTTP Content-Encoding for write request body, can be set to "gzip" to
  ## compress body or "identity" to apply no encoding.
  content_encoding = "identity"

  ## Use TLS but skip chain & host verification
  insecure_skip_verify = true

  ## Amount of time allowed to complete the HTTP request
  timeout = "5s"


  ## Data format to consume.
  ## Each data format has its own unique set of configuration options, read
  ## more about them here:
  ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
  data_format = "json"
  
  ## Only grab these fields
  fieldpass = ["total_bps_dropped","total_bps_passed","total_bytes_dropped","total_bytes_passed","total_pkts_dropped","total_pkts_passed","total_pps_dropped","total_pps_passed"]

Hello @RobD,
Hmm I don’t think this is possible, but Im not sure. I’m asking the telegraf team. You can use environment variables in your config. Configuring Telegraf | Telegraf 1.15 Documentation
Maybe you use can compose the url with a dynamic date first and use that?

There’s no way to configure telegraf by itself to do what you’re asking. You could set up environment variables outside of telegraf but they wouldn’t update on the collection interval so the same url would be used every interval.

The execd input might be an option for you. It works by calling a script or program you write to retrieve the data, then it hooks into telegraf to process the data and send it to your outputs. Telegraf signals your script when it’s time to collect, then it would build the url with the times you want and also make the http transaction. Then it would pass the data back to telegraf in one of the supported formats.

See the examples here:

and the data formats here:

I like the idea of using the execd input, but I’m not sure how I’m supposed to use it to set my URL for my other http input.

I have the following powershell script that produces the full URL:

[string]$UnixNow = [int][double]::Parse((Get-Date -UFormat %s))
[string]$UnixPrev = [int][double]::Parse((Get-Date -UFormat %s)) - 30

Write-Host = "https://MY_IP/api/aed/v2/traffic/?startTime=${UnixPrev}&endTime=${UnixNow}"

I don’t want to collect this as a metric I just want to use the output of the script for another input. Is this possible?