Created
February 18, 2019 15:15
-
-
Save seanthegeek/c2083f29d9226a92012bf0b9f4babcd0 to your computer and use it in GitHub Desktop.
Revisions
-
seanthegeek created this gist
Feb 18, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ from elasticsearch_dsl import connections, Search, Q from parsedmarc.elastic import _AggregateReportDoc, _ForensicReportDoc from parsedmarc.utils import get_ip_address_country # Replace with your Elasticsearch URLs connections.create_connection(hosts=["127.0.0.1:9200"]) search = Search(index="dmarc_aggregate*") query = ~Q(dict(exists=dict(field="source_country"))) search.query = query count = search.count() search = search[0:count] results = search.execute() for result in results: doc = _AggregateReportDoc.get(id=result.meta.id, index=result.meta.index) source_ip_address = str(result.source_ip_address) source_country = get_ip_address_country(source_ip_address) if source_country: doc.source_country = source_country doc.save() search = Search(index="dmarc_forensic*") query = ~Q(dict(exists=dict(field="source_country"))) search.query = query count = search.count() search = search[0:count] results = search.execute() for result in results: doc = _ForensicReportDoc.get(id=result.meta.id, index=result.meta.index) source_ip_address = str(result.source_ip_address) source_country = get_ip_address_country(source_ip_address) if source_country: doc.source_country = source_country doc.save()