blob: e460fcb5db2d63dc99a8bdf9f6b9051eb404b8f9 [file] [log] [blame]
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +01001#!/usr/bin/python
2
3from mixpanel import Mixpanel
4
Sapan Bhatiaeb7819c2017-03-01 15:26:17 +01005import argparse
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +01006import sys
7import getpass
8import socket
9import subprocess
10import os
11
12from os.path import expanduser
Sapan Bhatiaeb7819c2017-03-01 15:26:17 +010013
14parse = argparse.ArgumentParser(description='Send CORD logs to mixpanel.')
15parse.add_argument('--corddir', dest='corddir', action='store',default=None, help='CORD Directory')
16parse.add_argument('--event', dest='event', action='store',default=None, help='Event Name')
17parse.add_argument('--finish', dest='finish', action='store_true',default=False, help='Finish')
18parse.add_argument('--status', dest='status', action='store',default=None, help='Exit status')
19
20args = parse.parse_args()
21
22corddir = expanduser(args.corddir)
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010023
24try:
25 mp = Mixpanel("7d5ca3b3ff870dbeda89c9d5af59e9e9")
26 hostname = socket.gethostname()
27
28 context = {}
29 context['debian-version'] = open('/etc/debian_version').read().strip()
30
31
Sapan Bhatiaeb7819c2017-03-01 15:26:17 +010032 os.chdir(corddir+'/orchestration/xos')
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010033 p = subprocess.Popen(['git','rev-parse','HEAD'], stdout=subprocess.PIPE,stderr=subprocess.PIPE,stdin=subprocess.PIPE)
34
35 git_hash,err = p.communicate()
36
37 context['last-commit'] = git_hash
38
Sapan Bhatiaeb7819c2017-03-01 15:26:17 +010039 if (args.status):
40 context['status'] = args.status
41
42 config = open(corddir+'/build/config/cord_in_a_box.yml').read().splitlines()
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010043 for l in config:
44 if 'cord_profile:' in l:
45 context['profile'] = l.rstrip().rsplit(' ')[-1].replace("'","")
46
47 context['user'] = getpass.getuser()
48
49 name = ''
50 idx=0
51 lst = hostname.split('.')
52 lst.reverse()
53 for i in lst:
54 name='.'.join([name,i]).lstrip('.')
55
56 context['level-%d'%idx] = name
57 idx+=1
58
Sapan Bhatiaeb7819c2017-03-01 15:26:17 +010059 if (args.finish):
60 logfile = open(corddir+'/install.out').read().splitlines()
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010061 snapshot = logfile[-20:]
62 snapshot = filter(lambda x:x, snapshot)
63 context['snapshot'] = snapshot
64
65 try:
66 build_id = open('/tmp/cord-build').read().rstrip()
67 except:
68 build_id = context['user'] + name
Sapan Bhatiaeb7819c2017-03-01 15:26:17 +010069 mp.track(build_id, args.event, context)
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010070except Exception,e:
71 print str(e)
72 pass