CORD-933: Better interface for Mixpanel tracker
Change-Id: I649a90a32e2f63012e66a4326f8302671e965e64
diff --git a/elk-logger/mixpanel b/elk-logger/mixpanel
old mode 100644
new mode 100755
index 6a473e7..e460fcb
--- a/elk-logger/mixpanel
+++ b/elk-logger/mixpanel
@@ -2,6 +2,7 @@
from mixpanel import Mixpanel
+import argparse
import sys
import getpass
import socket
@@ -9,7 +10,16 @@
import os
from os.path import expanduser
-home = expanduser("~")
+
+parse = argparse.ArgumentParser(description='Send CORD logs to mixpanel.')
+parse.add_argument('--corddir', dest='corddir', action='store',default=None, help='CORD Directory')
+parse.add_argument('--event', dest='event', action='store',default=None, help='Event Name')
+parse.add_argument('--finish', dest='finish', action='store_true',default=False, help='Finish')
+parse.add_argument('--status', dest='status', action='store',default=None, help='Exit status')
+
+args = parse.parse_args()
+
+corddir = expanduser(args.corddir)
try:
mp = Mixpanel("7d5ca3b3ff870dbeda89c9d5af59e9e9")
@@ -19,14 +29,17 @@
context['debian-version'] = open('/etc/debian_version').read().strip()
- os.chdir(home+'/cord/orchestration/xos')
+ os.chdir(corddir+'/orchestration/xos')
p = subprocess.Popen(['git','rev-parse','HEAD'], stdout=subprocess.PIPE,stderr=subprocess.PIPE,stdin=subprocess.PIPE)
git_hash,err = p.communicate()
context['last-commit'] = git_hash
- config = open(home + '/cord/build/config/cord_in_a_box.yml').read().splitlines()
+ if (args.status):
+ context['status'] = args.status
+
+ config = open(corddir+'/build/config/cord_in_a_box.yml').read().splitlines()
for l in config:
if 'cord_profile:' in l:
context['profile'] = l.rstrip().rsplit(' ')[-1].replace("'","")
@@ -43,8 +56,8 @@
context['level-%d'%idx] = name
idx+=1
- if (len(sys.argv)>2 and 'finish' in sys.argv[2]):
- logfile = open(home + '/cord/install.out').read().splitlines()
+ if (args.finish):
+ logfile = open(corddir+'/install.out').read().splitlines()
snapshot = logfile[-20:]
snapshot = filter(lambda x:x, snapshot)
context['snapshot'] = snapshot
@@ -53,7 +66,7 @@
build_id = open('/tmp/cord-build').read().rstrip()
except:
build_id = context['user'] + name
- mp.track(build_id, sys.argv[1], context)
+ mp.track(build_id, args.event, context)
except Exception,e:
print str(e)
pass
diff --git a/scripts/cord-in-a-box.sh b/scripts/cord-in-a-box.sh
index 0d59ff2..ea03c5f 100755
--- a/scripts/cord-in-a-box.sh
+++ b/scripts/cord-in-a-box.sh
@@ -13,8 +13,7 @@
function finish {
EXIT=$?
- set +x
- python $CORDDIR/build/elk-logger/mixpanel FINISH-$EXIT --finish
+ python $CORDDIR/build/elk-logger/mixpanel --event FINISH --corddir $CORDDIR --finish --status $EXIT
}
function add_box() {
@@ -24,14 +23,14 @@
function run_stage {
cd $CORDDIR
- python build/elk-logger/mixpanel $1-start
+ python build/elk-logger/mixpanel --event $1-start --corddir $CORDDIR
echo "==> "$1": Starting"
$1
echo "==> "$1": Complete"
cd $CORDDIR
- python build/elk-logger/mixpanel $1-end
+ python build/elk-logger/mixpanel --event $1-end --corddir $CORDDIR
}
function cleanup_from_previous_test() {