influxdata / influxdb-client-python

InfluxDB 2.0 python client
https://influxdb-client.readthedocs.io/en/stable/
MIT License
705 stars 186 forks source link

Write multiple points failed #233

Closed Wapiti08 closed 3 years ago

Wapiti08 commented 3 years ago

Steps to reproduce: List the minimal actions needed to reproduce the behavior.

  1. create the write_api
  2. get the list to write and make the appended points
  3. write to influxdb
                for ord, field_value in enumerate(non_rep_values):  
                    points.append(Point(meas).field(field_name,field_value))
                write_api.write(bucket=bucket, record=points)

    Expected behavior: I want to write all the elements in a list to the influxdb with write_api

Actual behavior: When I tried to write multiple points with a list, I got only the last item written to the influxdb.

Specifications:

bednar commented 3 years ago

Hi @Wapiti08,

thanks for using our client.

It looks like that your Points have same measurement name, tag set, and timestamp. If you submit Point with the same measurement, tag set, and timestamp, but with a different field set, the field set becomes the union of the old field set and the new field set, where any conflicts favor the new field set.

https://docs.influxdata.com/influxdb/v2.0/reference/syntax/line-protocol/#duplicate-points

Regards

Wapiti08 commented 3 years ago

Please tell me how I can write all the data in a list. I have no idea. Add timestamp? Do you have any examples?

bednar commented 3 years ago

Could you share how your data looks like and how your query looks like?

Wapiti08 commented 3 years ago

['https://en.wikipedia.org/wiki/Advanced_persistent_threat', 'https://blog.malwarebytes.com/101/2016/07/explained-advanced-persistent-threat-apt/', 'https://www.fireeye.com/current-threats/apt-groups.html', 'https://www.kaspersky.com/resource-center/definitions/advanced-persistent-threats', 'https://www.trendmicro.com/en_us/research/21/d/iron-tiger-apt-updates-toolkit-with-evolved-sysupdate-malware-va.html', 'https://thehackernews.com/2021/04/lazarus-apt-hackers-are-now-using-bmp.html', 'https://www.sciencedirect.com/science/article/pii/S0020025520308628', 'https://ieeexplore.ieee.org/document/7163279', 'https://github.com/cyber-research/APTMalware', 'https://threatpost.com/ta416-apt-plugx-malware-variant/161505/', 'https://www.computerweekly.com/news/252490098/MosaicRegressor-APT-campaign-using-rare-malware-variant', 'https://threatpost.com/chinese-apt-sepulcher-malware-phishing-attacks/158871/', 'https://www.zdnet.com/article/ancient-icefog-apt-malware-spotted-again-in-new-wave-of-attacks/', 'https://www.cybereason.com/blog/molerats-apt-new-malware-and-techniques-in-middle-east-espionage-campaign', 'https://www.cyberbit.com/blog/endpoint-security/dtrack-apt-malware-found-in-nuclear-power-plant/', 'https://blogs.blackberry.com/en/2019/10/mobile-malware-and-apt-espionage-prolific-pervasive-and-cross-platform', 'https://www.sans.org/blog/apt-memory-and-malware-challenge-solution', 'https://www.bleepingcomputer.com/news/security/new-bendybear-apt-malware-gets-linked-to-chinese-hacking-group/', 'https://www.csoonline.com/article/2615666/5-signs-youve-been-hit-with-an-apt.html', 'https://digitalguardian.com/blog/what-advanced-persistent-threat-apt-definition', 'https://www.imperva.com/learn/application-security/apt-advanced-persistent-threat/', 'https://resources.infosecinstitute.com/topic/malware-spotlight-what-is-apt/', 'https://www.proofpoint.com/us/blog/threat-insight/chinese-apt-ta413-resumes-targeting-tibet-following-covid-19-themed-economic', 'https://www.pandasecurity.com/en/mediacenter/news/apt-coronavirus-malware/', 'https://www.scmagazine.com/home/security-news/cybercrime/foreign-apt-groups-use-coronavirus-phishing-lures-to-drop-rat-malware/', 'https://link.springer.com/article/10.1007/s11416-015-0258-7', 'https://www.watchguard.com/help/docs/help-center/en-US/Content/en-US/WG-Cloud/Devices/reports/report_zero_day_malware_apt.html', 'https://www.welivesecurity.com/2020/09/30/aptc23-group-evolves-its-android-spyware/', 'https://www.anomali.com/blog/anomali-cyber-watch-apt-malware-vulnerabilities-and-more', 'https://www.securityweek.com/onionduke-apt-malware-distributed-malicious-tor-exit-node', 'https://www.ptsecurity.com/ww-en/analytics/calypso-apt-2019/', 'https://searchsecurity.techtarget.com/definition/advanced-persistent-threat-APT', 'https://www.cynet.com/network-attacks/advanced-persistent-threat-apt-attacks/', 'https://securelist.com/satellite-turla-apt-command-and-control-in-the-sky/72081/', 'https://www.darkreading.com/attacks-breaches/zebrocy-apt-group-expands-malware-arsenal-with-new-backdoor-family/d/d-id/1334863', 'https://www.infosecurity-magazine.com/news/chinese-apt-group-linked-to/', 'https://www.varonis.com/blog/apt-groups/', 'https://securityintelligence.com/cybercriminals-leverage-massively-distributed-malware-in-apt-style-attacks/', 'https://www.sentinelone.com/blog/here-we-go-crimeware-apt-journey-from-robbinhood-to-apt28/', 'https://duo.com/decipher/iron-tiger-apt-updates-toolkit-in-18-month-malware-attack']

It is just a list of urls. I want to write them as the field values only.

Wapiti08 commented 3 years ago

I did not use query. The list is generated by other scripts. I want to write those urls to influxdb

Wapiti08 commented 3 years ago

I realize I may need to add unique timestamp as the id.

bednar commented 3 years ago

You could add unique timestamp or tag into Point. Something like:

index = 0
for ord, field_value in enumerate(non_rep_values):  
       points.append(Point(meas).tag("index", index).field(field_name,field_value))
       index += 1
write_api.write(bucket=bucket, record=points)
Wapiti08 commented 3 years ago

Thanks a lot