summaryrefslogtreecommitdiffstats
path: root/utils/test/scripts/shared_utils.py
diff options
context:
space:
mode:
authorJuraj Linkes <jlinkes@cisco.com>2016-03-29 11:13:27 +0200
committerJuraj Linkes <jlinkes@cisco.com>2016-03-30 15:06:53 +0200
commit20c693591a98597d05a37485bb1d15d2df595af0 (patch)
tree2865ab6f2048246dcf8d6f3f52ded327326b8c3b /utils/test/scripts/shared_utils.py
parente25e39c1a1bdd57a8a28944f918b04cde5c397f1 (diff)
added ELK scripts for porting data from mongo to elasticsearch and managing kibana dashboards
Change-Id: I9edbc1535f6f9c4ca4dc8b4871a04c2ed6d1969e Signed-off-by: Juraj Linkes <jlinkes@cisco.com>
Diffstat (limited to 'utils/test/scripts/shared_utils.py')
-rw-r--r--utils/test/scripts/shared_utils.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/utils/test/scripts/shared_utils.py b/utils/test/scripts/shared_utils.py
new file mode 100644
index 000000000..899f844ec
--- /dev/null
+++ b/utils/test/scripts/shared_utils.py
@@ -0,0 +1,36 @@
+import urllib3
+import json
+http = urllib3.PoolManager()
+
+
+def delete_request(url, username, password, body=None):
+ headers = urllib3.util.make_headers(basic_auth=':'.join([username, password]))
+ http.request('DELETE', url, headers=headers, body=body)
+
+
+def publish_json(json_ojb, username, password, output_destination):
+ json_dump = json.dumps(json_ojb)
+ if output_destination == 'stdout':
+ print json_dump
+ else:
+ headers = urllib3.util.make_headers(basic_auth=':'.join([username, password]))
+ http.request('POST', output_destination, headers=headers, body=json_dump)
+
+
+def _get_nr_of_hits(elastic_json):
+ return elastic_json['hits']['total']
+
+
+def get_elastic_data(elastic_url, username, password, body, field='_source'):
+ # 1. get the number of results
+ headers = urllib3.util.make_headers(basic_auth=':'.join([username, password]))
+ elastic_json = json.loads(http.request('GET', elastic_url + '/_search?size=0', headers=headers, body=body).data)
+ nr_of_hits = _get_nr_of_hits(elastic_json)
+
+ # 2. get all results
+ elastic_json = json.loads(http.request('GET', elastic_url + '/_search?size={}'.format(nr_of_hits), headers=headers, body=body).data)
+
+ elastic_data = []
+ for hit in elastic_json['hits']['hits']:
+ elastic_data.append(hit[field])
+ return elastic_data