Push json file to InfluxDB

I am trying to collect Bitbucket API data as a json file and push the data to InfluxDB. I am doing this via Jenkins scripted pipeline.
I am not sure how to convert my json data to points as the data will be dynamic. The script executes without any error but I am unable to see my data in InfluxDB
How can I specify which measurement to use.

Code is as below

import groovy.json.*
def result

influxSRV='x.x.x.x:8086'
influxDb='dbname'
measurement = 'ms'

node('master'){
    stage('collect'){
            sh "curl -XGET -u 'xx:yy' https://x.y.z > output.json"
             result = readJSON file: 'output.json'
	    sh "curl -iX POST \'http://${influxSRV}/write?db=${influxDb}&precision=ms\' --data-binary \'${measurement},${result}\'"
    }
}

Hello @arrthy,
Welcome! you have two options to get data from a JSON API to InfluxDB. The first is to change the data to line protocol manually so you can write it to the database. The second is to use Telegraf. I recommend checking out the Telegraf file plugin or the exec plugin. I recommend using Telegraf.
telegraf/README.md at release-1.14 · influxdata/telegraf · GitHub
telegraf/README.md at release-1.14 · influxdata/telegraf · GitHub

Here is an example you might find useful:

Please note that the example is for 1.x but would work the same for 2.x with a slight change to the Telegraf config. https://docs.influxdata.com/influxdb/v2.0/write-data/no-code/use-telegraf/manual-config/

Unfortunately, I cannot use telegraf. Is it possible to insert multiple values to a field using one post query.
I need only two fields from the JSON generated. I want the DB to look like:
commit user
xx yy
zz cc
aa bb

I tried below

         result = readJSON file: 'output.json'
		 "${result.values.id}".tokenize(',').each
         {
             id-> println "${id}"
             fieldCommit = "CommitID=${id}"
             fieldsList.add(fieldCommit)
         }
		     userId = "${result.values.author.slug}".tokenize(',').each
         {
             id-> println "${id}"
             fieldUser = "UserID=${id}"
             fieldsList.add(fieldUser)
         }
		String output = fieldsList.toString().replaceAll("(^\\[|\\]\$)", "");
		String fieldsRow = output.toString().replaceAll(" ", "");
         
		 sh "curl -iX POST \'http://${influxSRV}/write?db=${influxDb}&precision=ms\' --data-binary \'${measurement},${tagsRow} ${fieldsRow}\'"

But the POST operation fails with below error:

HTTP/1.1 400 Bad Request
Content-Type: application/json
Request-Id: 98bea35d-9e47-11ea-8009-080027379d84
X-Influxdb-Build: OSS
X-Influxdb-Error: unable to parse

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.