Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/configs/nuage/scripts/dpi_simulator/dpi_sample_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#Reads from sample_data.json and injects the same data to a sample_index in localhost elasticsearch database. To use, paste the sample data in the file.

from elasticsearch import Elasticsearch
es = Elasticsearch('http://localhost:9200')
import json
import time

try:
data = json.load(open('sample_data_dpi.json','r'))
except:
print('Error reading sample_data.json. Exiting.')
exit(0)

try:
hits = data['hits']['hits']
except:
print('Hits not present in data. Check data. Exiting.')
exit(0)

print('Number of hits read = %d'%(len(hits)))
print("Indexing...")

timestamp = (time.time() - 10*60*60)*1000


import random

for hit in hits:
hit = hit["_source"]
hit["timestamp"] = int(timestamp)
timestamp += 30*1000

es.index(index='nuage_dpi_flowstats_test',doc_type='nuage_doc_type',body=hit)

print('Finished..')
Loading