CORD-933: Add Mixpanel aggregate analytics to cord in a box to track failures, errors, and also track cord-in-a-box usage.

Change-Id: I8d443198b9861bed079a47c6d282533c6eceae3b
diff --git a/elk-logger/mixpanel b/elk-logger/mixpanel
new file mode 100644
index 0000000..6a473e7
--- /dev/null
+++ b/elk-logger/mixpanel
@@ -0,0 +1,59 @@
+#!/usr/bin/python
+
+from mixpanel import Mixpanel
+
+import sys
+import getpass
+import socket
+import subprocess
+import os
+
+from os.path import expanduser
+home = expanduser("~")
+
+try:
+    mp = Mixpanel("7d5ca3b3ff870dbeda89c9d5af59e9e9")
+    hostname = socket.gethostname()
+
+    context = {}
+    context['debian-version'] = open('/etc/debian_version').read().strip()
+
+
+    os.chdir(home+'/cord/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()
+    for l in config:
+        if 'cord_profile:' in l:
+            context['profile'] = l.rstrip().rsplit(' ')[-1].replace("'","")
+
+    context['user'] = getpass.getuser()
+
+    name = ''
+    idx=0
+    lst = hostname.split('.')
+    lst.reverse()
+    for i in lst:
+        name='.'.join([name,i]).lstrip('.')
+
+        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()
+        snapshot = logfile[-20:]
+        snapshot = filter(lambda x:x, snapshot)
+        context['snapshot'] = snapshot
+
+    try:
+        build_id = open('/tmp/cord-build').read().rstrip()
+    except:
+        build_id = context['user'] + name
+    mp.track(build_id, sys.argv[1], context)
+except Exception,e:
+    print str(e)
+    pass