14.12.2021, 13:07
(This post was last modified: 14.12.2021, 13:13 by thomasoppida.)
[attachment=2455 Wrote:admin pid='24163' dateline='1639476013']Modified send_metric function for the previous example. Replace IP/BUCKET/ORG/TOKEN placeholders with your parameters.
Code:function send_metric(table, name, addr, value)
if name == nil or name == '' then
return
end
name = string.gsub(name, ' ', '\\ ')
local url = 'http://IP:8086/api/v2/write?bucket=BUCKET&org=ORG'
local body
if type(value) == 'boolean' then
body = string.format('%s,name=%s,addr=%s state=%s', table, name, addr, value)
else
-- most likely number
body = string.format('%s,name=%s,addr=%s value=%s', table, name, addr, value)
end
local res, code = http.request({
url = url,
method = 'POST',
body = body,
headers = {
Authorization = 'Token TOKEN'
}
})
if code ~= 204 then
log('error sending to influx', res, code, body)
end
end
Thank you for responding Admin. I tried to put in your code in Postman just to verify that access is ok.
I can see to get response in postman I have to set Authorization to Oauth 2.0 and I get the header prefix Bearer.
Do I replace Token with Bearer instead in the script? I didn't get this to work either... Suggestions?