0

I am trying to ingest the data from one measurement (vulnerability) to another measurement (test1) using influxDB python client. Since i want to ingest only server, ID, route from vulnerability measurement into test1 measurement, i choose three columns. Any help would be appreciated on how to ingest the data from one measurement to another.

code:

from influxdb import InfluxDBClient
from datetime import datetime
client = InfluxDBClient('hostname', 8089, 'user', 'pwd', 'database')
results = client.query("SELECT server, ID, route from vulnerability") 
for row in results:
    influxJson = [
                    {
                        "measurement":"test1",  
                        "time" : datetime.utcnow().isoformat() + "Z",
                        "tags": {
                            'ResiliencyTier':'targetResiliencyTier',
                            'lob' : 'technologyDivision'
                        },
                        "fields": {
                            columns[0][0] : str(row[1][0]),
                            columns[1][0] : str(row[1][1]),
                            columns[2][0] : str(row[1][2])

                        }
                    }
                ]
client.write_points(influxJson) 

Sample Data of vulnerability measurement:

{'time': '2022-02-10T17:51:52.638000Z', 'server': '123123123', 'id': '351335', 'route': '37875'}, {'time': '2022-02-10T17:51:52.638000Z', 'server': '234', 'qid': '351343', 'route': '0037875'}

ERROR:

  File "Vul_SUmmary_UTEP_data_PROD.py", line 29, in startprocess
    columns[0][0] : str(row[1][0]),
NameError: name 'columns' is not defined

Thanks

peter
  • 17
  • 5

1 Answers1

0

Regarding the error (I know it's a little late), it clearly states that 'columns' is not defined. That's because it never is. 'row' is defined because it's the variable of your for-loop. If you want to fill another table with the data from row, you need to define it beforehand. You could also just write:

'server' : str(row[1][0]),
'ID' : str(row[1][1]),
'route' : str(row[1][2])

After all, you're just trying to create another dictionary for fields.

I hope you figured that out yourself in the last 5 months. I just stumbled across your question regarding another problem.