-
Notifications
You must be signed in to change notification settings - Fork 3
/
new_relic_connector.py
executable file
·79 lines (61 loc) · 2.54 KB
/
new_relic_connector.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import sys
import os
import re
import unittest
from lib.etl.dispatcher import ETLDispatcher
from lib.history.dao import create_tables
from lib.new_relic.client import NewRelicClient
from tests.test_app_loads import AppLoadsTestCase
from tests.test_errors import ExceptionsTestCase, CrashesTestCase
from tests.test_history import HistoryTestCase
from tests.test_performance import PerformanceTestCase
from tests.test_transactions import TransactionsTestCase
from tests.test_crittercism_client import CrittercismClientTestCase
from tests.test_crittercism_models import CrittercismModelsTestCase
from tests.test_etl import EtlTestCase
sys.path.insert(0, os.path.abspath('..'))
from clint.arguments import Args
from clint.textui import puts, colored, indent
all_args = Args()
logging.getLogger().addHandler(logging.StreamHandler())
logging.getLogger().setLevel(logging.DEBUG)
NR_ACCOUNT_ID = str(os.environ.get('NR_ACCOUNT_ID'))
NR_INSERT_KEY = str(os.environ.get('NR_INSERT_KEY'))
MODE_SPECIFIER = ('^test|upload$')
with indent(4, quote='>>>'):
puts(colored.green('Arguments passed in: ') + str(all_args.all))
args = all_args.not_flags
if not len(args):
puts(colored.red('Mode Required. Valid input: %s' % MODE_SPECIFIER))
raise Exception('Invalid Input')
puts(colored.green('Mode: ') + str(args[0]))
if not re.match(MODE_SPECIFIER, args[0]):
puts(colored.red('Invalid Mode. Valid input: %s' % MODE_SPECIFIER))
raise Exception('Invalid Input')
if re.match('^test$', args[0]):
for tc in (HistoryTestCase, TransactionsTestCase, ExceptionsTestCase,
CrashesTestCase, PerformanceTestCase,
AppLoadsTestCase, CrittercismClientTestCase,
CrittercismModelsTestCase, EtlTestCase):
suite = unittest.TestLoader().loadTestsFromTestCase(tc)
unittest.TextTestRunner(verbosity=2).run(suite)
exit()
structured_args = {
'mode': str(args[0]),
'verbose': bool(len(all_args.flags.all_with('verbose'))),
}
create_tables()
id_list = None
if len(args) > 1:
id_list = args[1:]
puts(colored.blue('Ids: ') + id_list)
structured_args['ids'] = id_list
if structured_args['mode'] == 'upload':
logging.getLogger().info('Beginning Upload app_ids=%s', id_list)
nrc = NewRelicClient(NR_ACCOUNT_ID, NR_INSERT_KEY)
for app_id in id_list:
dispatcher = ETLDispatcher(nrc, app_id)
dispatcher.handle_etl()