summaryrefslogtreecommitdiffstats
path: root/scripts/send-error-report
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/send-error-report')
-rwxr-xr-xscripts/send-error-report114
1 files changed, 114 insertions, 0 deletions
diff --git a/scripts/send-error-report b/scripts/send-error-report
new file mode 100755
index 0000000000..01c292ead1
--- /dev/null
+++ b/scripts/send-error-report
@@ -0,0 +1,114 @@
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", "/Errors/")
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 sys.exit(1)
66 return
67
68 with open(json_file) as f:
69 data = f.read()
70
71 try:
72 jsondata = json.loads(data)
73 jsondata['username'] = username.strip()
74 jsondata['email'] = email.strip()
75 data = json.dumps(jsondata, indent=4, sort_keys=True)
76 except:
77 print("Invalid json data")
78 sys.exit(1)
79 return
80
81 try:
82 conn = handle_connection(server, data)
83 response = conn.getresponse()
84 print response.status, response.reason
85 res = response.read()
86 if response.status == 200:
87 print(res)
88 else:
89 print("There was a problem submiting your data, response written in %s.response.html" % json_file)
90 with open("%s.response.html" % json_file, "w") as f:
91 f.write(res)
92 sys.exit(1)
93 conn.close()
94 except Exception as e:
95 print("Server connection failed: %s" % e)
96 sys.exit(1)
97 else:
98 print("No data file found.")
99 sys.exit(1)
100
101
102if __name__ == '__main__':
103 print ("\nSends an error report (if the report-error class was enabled) to a remote server.")
104 print("\nThis scripts sends the contents of the error to a public upstream server.")
105 print("\nPlease remove any identifying information before sending.")
106 if len(sys.argv) < 2:
107 print("\nUsage: send-error-report <error_fileName> [server]")
108 print("\nIf this is the first when sending a report you'll be asked for your name and optionally your email address.")
109 print("They will be associated with your report.\n")
110
111 elif len(sys.argv) == 3:
112 sendData(sys.argv[1], sys.argv[2])
113 else:
114 sendData(sys.argv[1], "errors.yoctoproject.org")