I am using the inputs.http plugin of Telegraf in order to import data from an API to influxdb. The API requires a time filter in the body of a POST request and responds with data between that time filter. I want to periodically call this API and retrieve data for the past 10 or so seconds. So I need to include the current timestamp in the body of the POST request. Can I pass the current server timestamp to telegraf.conf in the form of an environment variable or a command line argument? What I have attempted so far is using an environment variable in the telegraf.conf file as shown below. It did not work.
[[inputs.http]]
#URL
urls = ["url"]
#http method
method = "POST"
## Optional HTTP headers
headers = {"cache-control" = "no-cache","content-type" = "application/json"}
## HTTP entity-body to send with POST/PUT requests.
#body = "{\"measurement\":\"measurement_name\", \"time_filter\":[1593068400, 1593068800]}"
body = "{\"measurement\":\"measurement_name\", \"time_filter\":[1593562547, ${date +%s}]}"
#Data from HTTP in JSON format
data_format = "json"
I then run the command below
$telegraf -config telegraf.conf
and receive a 400 error. If I replace the body line (includes variable) with the line above it (no variable) everything works fine.