summaryrefslogtreecommitdiffstats
path: root/scripts/send-error-report
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/send-error-report')
-rwxr-xr-xscripts/send-error-report110
1 files changed, 110 insertions, 0 deletions
diff --git a/scripts/send-error-report b/scripts/send-error-report
new file mode 100755
index 0000000000..48d983bc0e
--- /dev/null
+++ b/scripts/send-error-report
@@ -0,0 +1,110 @@
1#!/usr/bin/env python
2
3# Sends an error report (if the report-error class was enabled) to a remote server.
4#
5# Copyright (C) 2013 Intel Corporation
6# Author: Andreea Proca <andreea.b.proca@intel.com>
7
8
9
10import httplib, urllib, os, sys, json, base64
11from urllib2 import _parse_proxy as parseproxy
12
13
14def handle_connection(server, data):
15 params = urllib.urlencode({'data': data})
16 headers = {"Content-type": "application/json"}
17 proxyrequired = False
18 if os.environ.get("http_proxy") or os.environ.get("HTTP_PROXY"):
19 proxyrequired = True
20 # we need to check that the server isn't a local one, as in no_proxy
21 try:
22 temp = httplib.HTTPConnection(server, strict=True, timeout=5)
23 temp.request("GET", "/")
24 tempres = temp.getresponse()
25 if tempres.status == 200:
26 proxyrequired = False
27 temp.close()
28 except:
29 pass
30
31 if proxyrequired:
32 proxy = parseproxy(os.environ.get("http_proxy") or os.environ.get("HTTP_PROXY"))
33 if proxy[1] and proxy[2]:
34 auth = base64.encodestring("%s:%s" % (proxy[1], proxy[2]))
35 headers["Authorization"] = "Basic %s" % auth
36 conn = httplib.HTTPConnection(proxy[3])
37 conn.request("POST", "http://%s/ClientPost/" % server, params, headers)
38 else:
39 conn = httplib.HTTPConnection(server)
40 conn.request("POST", "/ClientPost/", params, headers)
41
42 return conn
43
44
45def sendData(json_file, server):
46
47 if os.path.isfile(json_file):
48
49 home = os.path.expanduser("~")
50 userfile = os.path.join(home, ".oe-send-error")
51 if os.path.isfile(userfile):
52 with open(userfile) as g:
53 username = g.readline()
54 email = g.readline()
55 else:
56 print("Please enter your name and your email (optionally), they'll be saved in the file you send.")
57 username = raw_input("Name: ")
58 email = raw_input("E-mail (not required): ")
59 if len(username) > 0 and len(username) < 50:
60 with open(userfile, "w") as g:
61 g.write(username + "\n")
62 g.write(email + "\n")
63 else:
64 print("Invalid inputs, try again.")
65 return
66
67 with open(json_file) as f:
68 data = f.read()
69
70 try:
71 jsondata = json.loads(data)
72 jsondata['username'] = username.strip()
73 jsondata['email'] = email.strip()
74 data = json.dumps(jsondata, indent=4, sort_keys=True)
75 except:
76 print("Invalid json data")
77 return
78
79 try:
80 conn = handle_connection(server, data)
81 response = conn.getresponse()
82 print response.status, response.reason
83 res = response.read()
84 if response.status == 200:
85 print(res)
86 else:
87 print("There was a problem submiting your data, response written in %s.response.html" % json_file)
88 with open("%s.response.html" % json_file, "w") as f:
89 f.write(res)
90 conn.close()
91 except Exception as e:
92 print("Server connection failed: %s" % e)
93
94 else:
95 print("No data file found.")
96
97
98if __name__ == '__main__':
99 print ("\nSends an error report (if the report-error class was enabled) to a remote server.")
100 print("\nThis scripts sends the contents of the error to a public upstream server.")
101 print("\nPlease remove any identifying information before sending.")
102 if len(sys.argv) < 2:
103 print("\nUsage: send-error-report <error_fileName> [server]")
104 print("\nIf this is the first when sending a report you'll be asked for your name and optionally your email address.")
105 print("They will be associated with your report.\n")
106
107 elif len(sys.argv) == 3:
108 sendData(sys.argv[1], sys.argv[2])
109 else:
110 sendData(sys.argv[1], "errors.yoctoproject.org")