InfluxDB JSON 数据摄取到测量中

发布于 2025-01-10 02:12:48 字数 1480 浏览 5 评论 0原文

我正在尝试使用 influxDB python 客户端将数据从一个测量(漏洞)提取到另一个测量(test1)。由于我只想提取服务器、ID、从漏洞测量到 test1 测量的路由,因此我选择三列。任何关于如何将数据从一个测量摄取到另一个测量的帮助将不胜感激。

代码:

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) 

漏洞测量示例数据:

{'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'}

错误:

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

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

<逆流佳人身旁 2025-01-17 02:12:48

关于错误(我知道有点晚了),它明确指出 'columns' 未定义。那是因为它从来都不是。 'row' 被定义是因为它是 for 循环的变量。如果你想用行中的数据填充另一个表,你需要事先定义它。您也可以只写:

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

毕竟,您只是想为 fields 创建另一个字典。

我希望你在过去 5 个月里自己已经弄清楚了这一点。我刚刚偶然发现你关于另一个问题的问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文