-
Notifications
You must be signed in to change notification settings - Fork 1
/
stats_consolidation_report
executable file
·70 lines (54 loc) · 1.57 KB
/
stats_consolidation_report
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
#!/usr/bin/env python
import argparse
import sys
from stats_consolidation.config import Config
from stats_consolidation.db import DB_Stats
DEFAULT_CONFIG_FILE = "/etc/stats-consolidation.conf"
parser = argparse.ArgumentParser()
parser.add_argument('--config_file', default=DEFAULT_CONFIG_FILE)
args = parser.parse_args()
try:
config = open(args.config_file)
except IOError as e:
msg = str(e) + '\n'
sys.stderr.write(msg)
sys.exit(1)
config = Config(args.config_file)
db = DB_Stats(config.db_name, config.db_user, config.db_pass, config.db_dialect)
db.create()
connection = db.connect()
cursor = connection.cursor()
result = cursor.execute("""SELECT
usages.ts usages_ts,
usages.user_hash usages_user_hash,
usages.resource_name usages_resource_name,
usages.start_date usages_start_date,
usages.data_type usages_data_type,
usages.data usages_data,
users.hash users_hash,
users.uuid users_uuid,
users.machine_sn users_machine_sn,
users.age users_age,
users.school users_school,
users.sw_version users_sw_version,
users.ts users_ts
FROM usages LEFT JOIN users ON (usages.user_hash = users.hash)""")
cols = [
'usages_ts',
'usages_user_hash',
'usages_resource_name',
'usages_start_date',
'usages_data_type',
'usages_data',
'users_hash',
'users_uuid',
'users_machine_sn',
'users_age',
'users_school',
'users_sw_version',
'users_ts',
]
sys.stdout.write(','.join(cols) + '\n')
for row in result:
sys.stdout.write(','.join([str(cell) for cell in row]) + '\n')
connection.close()