Tag recorded events with CORD version

Change-Id: I447f54dda7b8249bcbdfc8b9f20e71ce6a9dbd9f
diff --git a/elk-logger/mixpanel b/elk-logger/mixpanel
index e460fcb..b9e9b4d 100755
--- a/elk-logger/mixpanel
+++ b/elk-logger/mixpanel
@@ -1,6 +1,7 @@
 #!/usr/bin/python
 
 from mixpanel import Mixpanel
+import pdb
 
 import argparse
 import sys
@@ -20,6 +21,8 @@
 args = parse.parse_args()
 
 corddir = expanduser(args.corddir)
+build_version_file = '/tmp/cord-build'
+cord_version_file = '/tmp/cord-build-version'
 
 try:
     mp = Mixpanel("7d5ca3b3ff870dbeda89c9d5af59e9e9")
@@ -28,7 +31,6 @@
     context = {}
     context['debian-version'] = open('/etc/debian_version').read().strip()
 
-
     os.chdir(corddir+'/orchestration/xos')
     p = subprocess.Popen(['git','rev-parse','HEAD'], stdout=subprocess.PIPE,stderr=subprocess.PIPE,stdin=subprocess.PIPE)
 
@@ -63,9 +65,29 @@
         context['snapshot'] = snapshot
 
     try:
-        build_id = open('/tmp/cord-build').read().rstrip()
+        build_id = open(build_version_file).read().rstrip()
     except:
         build_id = context['user'] + name
+
+    # Figure out whether we're in master or what
+    try:
+    	cord_version = open(cord_version_file).read().rstrip()
+    except:
+	os.chdir(corddir)
+	possible_versions = ['master','cord-1.0','cord-2.0']
+
+	cord_version = 'personal'
+	try:
+	    for v in possible_versions:
+		diff = os.popen('repo forall -c "git stash 2>/dev/null 1>/dev/null;git diff -b opencord/%s 2>/dev/null;git stash pop 2>/dev/null 1>/dev/null"'%v).read()
+		if (not diff):
+		    cord_version = v
+		    break
+	except:
+	    pass
+        
+    open(cord_version_file,'w').write(cord_version)
+    context['version'] = cord_version
     mp.track(build_id, args.event, context)
 except Exception,e:
     print str(e)
diff --git a/scripts/cord-in-a-box.sh b/scripts/cord-in-a-box.sh
index 35415f7..e11a5f3 100755
--- a/scripts/cord-in-a-box.sh
+++ b/scripts/cord-in-a-box.sh
@@ -50,6 +50,8 @@
 
 function bootstrap() {
   echo "Generating build id"
+  rm -f /tmp/cord-build-version
+
   dd bs=18 count=1 if=/dev/urandom | base64 | tr +/ _. > /tmp/cord-build
   cd ~
   sudo apt-get update