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.
Related
I am trying to parse parts of the URL that I received from an API. I am trying to do this using Regex in Jmeter and save it into Variables.
I have a URL which looks like
I receive a URL as part of an API response and have extracted the URL into a variable named "UploadUrl". The value is similar to
https://Domain/path1/path2?queryParam1=Value1&queryParam2=Value2
I need to extract
Protocol as https
Host as Domain
Path as path1/path2
Parameters as queryParam1=Value1&queryParam2=Value2
so that I can pass them as inputs in the JMeter http Sampler.
enter image description here
but when I run the JMeter script the value is not getting extracted via the Regex.
What am I doing wrong?
You can put everything into "Path" field of the HTTP Request sampler
If you still want to extract protocol, host and so on it would be way easier to do using JSR223 PostProcessor and some Groovy code like:
URL url = new URL(vars.get('UploadUrl'))
def protocol = url.getProtocol()
def host = url.getHost()
def port = url.getPort()
if (port == -1) {
port = url.getDefaultPort()
}
def path = url.getPath()
def query = url.getQuery()
vars.put('protocol', protocol)
vars.put('host', host)
vars.put('port', port as String)
vars.put('path', path)
vars.put('query', query)
Demo:
You will be able to access the values like ${host}, ${port}, etc. where required.
Telegraf plugin:
HTTP Input Plugin
I'm trying to use telegraf to collect data from an vendor API.
test.conf file looks like this:
[[inputs.http]] urls = ["https://10.10.10.10"] method = "POST" body = '{"F_":"LOGIN","DATA":{"ID":"user","PWD":"password"}}'
When debugging i can see this is the error i get:
[inputs.http] Error in plugin: [url=https://10.10.10.10]: received status code 411 (Length Required), expected any value out of [200]
The API documentation for my vendor API states that the field "Content-Length" and "Host" are mandatory, but I can find now way to enable that in the plugin.
I have also tried using the http_response plugin, and I am able to get the JSON reply, but unfortuately i have not been able to find a good way to get the response_body_field JSON appended to the influxdb.
Does anybody know if either:
I can enable the two headers dynamicly(The POST lenght will vary)
or:
use the response_body_field from http_response and smoothly parse it to the influxdb?
I am trying to create a proof on concept using the TICK stack for monitoring. I have the helloworld stack running and showing CPU/Docker metrics.
I am trying to use the telegraf http input plugin to pull from an http endpoint:
From the docs i have simply configured the URL, GET and type (Set to json)
[[inputs.http]]
## One or more URLs from which to read formatted metrics
urls = [
"http://localhost:500/Queues"
]
method = "GET"
data_format = "json"
However nothing appears in Influx/Chronograf.
I can modify the endpoint to suit any changes there, but what am i doing wrong in telegraf config ?
I think I had the same struggle. For me the following conf worked:
[[inputs.http]]
name_override ="restservice_health"
urls = [
"https://localhost:5001/health"
]
method = "GET"
data_format = "value"
data_type = "string"
In this way, it appeared in Influxdb under the name "restservice_health" (allthough this option is not important for the example, so you could leave it out).
First, you would have to look at the result of the http://localhost:500/Queues request to make sure that it's a valid JSON object.
Then, depending on what is returned from that endpoint, you may have to configure the JSON parser, for example by setting json_query to a GJSON query to navigate the JSON response to the data you need.
I have a Grails controller that receives a DefaultMultipartHttpServletRequest like so:
def myController() {
DefaultMultipartHttpServletRequest proxyRequest = (DefaultMultipartHttpServletRequest) request
}
This controller acts as a proxy by taking pieces of this request and then resends the request to another destination.
For non-multipart requests, this worked fine, I did something like:
IProxyService service = (IProxyService) clientFactory.create()
Response response = service.doPOST(proxyRequest.getRequestBody())
Where proxyRequest.getRequestBody() contains a JSON block containing the request payload.
However, I do not know how to get this to work with multipart request payload, since the request body is no longer a simple block of JSON, but something like the following (taken from Chrome devtools):
How can I can pass this request payload through using my proxy service above, where doPost takes a String?
Have you tried
def parameterValue = request.getParameter("parameterName")
to get the parameter value?
If you see the method signatures for DefaultMultipartHttpServletRequest you will see there are methods for getting the files and other parameters separately because the request body is getting used to both upload the file and to pass in other parameters.
In my rails (3.2.13) app I send data to an external server using a form, then the external server process the data I sent and shows that the result is ok or not, I need to save that result or status to my rails app database, but I'm not sure about how to redirect to another page when the process in the external server is done.
I have a function to ask the server if the process of that data went ok using the reference or id that I sent in the first place using the form but as I said I don't know how to redirect after the process is finish...
please help me
You can use some core Ruby libraries to make a subsequent request on the same endpoint to determine the status code of your request. Try the following, cited in whole from Ruby Inside:
# Basic REST.
# Most REST APIs will set semantic values in response.body and response.code.
require "net/http"
http = Net::HTTP.new("api.restsite.com")
request = Net::HTTP::Post.new("/users")
request.set_form_data({"users[login]" => "quentin"})
response = http.request(request)
# Use nokogiri, hpricot, etc to parse response.body.
request = Net::HTTP::Get.new("/users/1")
response = http.request(request)
# As with POST, the data is in response.body.
request = Net::HTTP::Put.new("/users/1")
request.set_form_data({"users[login]" => "changed"})
response = http.request(request)
request = Net::HTTP::Delete.new("/users/1")
response = http.request(request)
Once you've instantiated a response object, you can operate on it in the following manner:
response.code #=> returns HTTP response code