forked from cisco-system-traffic-generator/trex-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnalyticsWebReport.py
executable file
·37 lines (33 loc) · 1.32 KB
/
AnalyticsWebReport.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
import sys
import ELKConnect as ec
import AnalyticsConnect as ac
import TRexDataAnalysis as tr
import time
import datetime
def main(verbose=False, source='elk', detailed_test_stats=False):
current_date = time.strftime("%Y-%m-%d")
k_days_ago = datetime.datetime.now() - datetime.timedelta(days=15)
start_date = str(k_days_ago.date())
if source == 'ga':
if verbose:
print('Retrieving data from Google Analytics')
analytics = ac.initialize_analyticsreporting()
response = ac.get_report(analytics, start_date, current_date)
all_data_dict, setups = ac.export_to_tuples(response)
elif source == 'elk':
elk_manager = ec.ELKManager(hostname='sceasr-b20', index='trex_perf-*', port=9200)
all_data_dict = elk_manager.fetch_and_parse()
else:
raise Exception('Unknown source: %s, valid are ga and elk' % source)
dest_path = os.path.join(os.getcwd(), 'build', 'images')
if verbose:
print('Saving data to %s' % dest_path)
if detailed_test_stats:
print('generating detailed table for test results')
tr.create_all_data(all_data_dict, current_date, save_path=dest_path,
detailed_test_stats=detailed_test_stats)
if verbose:
print('Done without errors.')
if __name__ == "__main__":
main()