diff options
Diffstat (limited to 'scripts/send-error-report')
-rwxr-xr-x | scripts/send-error-report | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/scripts/send-error-report b/scripts/send-error-report index cfbcaa52cb..cc1bc7c2b1 100755 --- a/scripts/send-error-report +++ b/scripts/send-error-report | |||
@@ -6,6 +6,7 @@ | |||
6 | # Copyright (C) 2013 Intel Corporation | 6 | # Copyright (C) 2013 Intel Corporation |
7 | # Author: Andreea Proca <andreea.b.proca@intel.com> | 7 | # Author: Andreea Proca <andreea.b.proca@intel.com> |
8 | # Author: Michael Wood <michael.g.wood@intel.com> | 8 | # Author: Michael Wood <michael.g.wood@intel.com> |
9 | # Author: Thomas Perrot <thomas.perrot@bootlin.com> | ||
9 | # | 10 | # |
10 | # SPDX-License-Identifier: GPL-2.0-only | 11 | # SPDX-License-Identifier: GPL-2.0-only |
11 | # | 12 | # |
@@ -22,7 +23,7 @@ scripts_lib_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'li | |||
22 | sys.path.insert(0, scripts_lib_path) | 23 | sys.path.insert(0, scripts_lib_path) |
23 | import argparse_oe | 24 | import argparse_oe |
24 | 25 | ||
25 | version = "0.3" | 26 | version = "0.4" |
26 | 27 | ||
27 | log = logging.getLogger("send-error-report") | 28 | log = logging.getLogger("send-error-report") |
28 | logging.basicConfig(format='%(levelname)s: %(message)s') | 29 | logging.basicConfig(format='%(levelname)s: %(message)s') |
@@ -65,7 +66,7 @@ def edit_content(json_file_path): | |||
65 | 66 | ||
66 | def prepare_data(args): | 67 | def prepare_data(args): |
67 | # attempt to get the max_log_size from the server's settings | 68 | # attempt to get the max_log_size from the server's settings |
68 | max_log_size = getPayloadLimit(args.protocol+args.server+"/ClientPost/JSON") | 69 | max_log_size = getPayloadLimit(args.server+"/ClientPost/JSON") |
69 | 70 | ||
70 | if not os.path.isfile(args.error_file): | 71 | if not os.path.isfile(args.error_file): |
71 | log.error("No data file found.") | 72 | log.error("No data file found.") |
@@ -135,19 +136,38 @@ def send_data(data, args): | |||
135 | headers={'Content-type': 'application/json', 'User-Agent': "send-error-report/"+version} | 136 | headers={'Content-type': 'application/json', 'User-Agent': "send-error-report/"+version} |
136 | 137 | ||
137 | if args.json: | 138 | if args.json: |
138 | url = args.protocol+args.server+"/ClientPost/JSON/" | 139 | url = args.server+"/ClientPost/JSON/" |
139 | else: | 140 | else: |
140 | url = args.protocol+args.server+"/ClientPost/" | 141 | url = args.server+"/ClientPost/" |
141 | 142 | ||
142 | req = urllib.request.Request(url, data=data, headers=headers) | 143 | req = urllib.request.Request(url, data=data, headers=headers) |
144 | |||
145 | log.debug(f"Request URL: {url}") | ||
146 | log.debug(f"Request Headers: {headers}") | ||
147 | log.debug(f"Request Data: {data.decode('utf-8')}") | ||
148 | |||
143 | try: | 149 | try: |
144 | response = urllib.request.urlopen(req) | 150 | response = urllib.request.urlopen(req) |
145 | except urllib.error.HTTPError as e: | 151 | except urllib.error.HTTPError as e: |
146 | logging.error(str(e)) | 152 | log.error(f"HTTP Error {e.code}: {e.reason}") |
153 | log.debug(f"Response Content: {e.read().decode('utf-8')}") | ||
147 | sys.exit(1) | 154 | sys.exit(1) |
148 | 155 | ||
156 | log.debug(f"Response Status: {response.status}") | ||
157 | log.debug(f"Response Headers: {response.getheaders()}") | ||
149 | print(response.read().decode('utf-8')) | 158 | print(response.read().decode('utf-8')) |
150 | 159 | ||
160 | def validate_server_url(args): | ||
161 | # Get the error report server from an argument | ||
162 | server = args.server or 'https://errors.yoctoproject.org' | ||
163 | |||
164 | if not server.startswith('http://') and not server.startswith('https://'): | ||
165 | log.error("Missing a URL scheme either http:// or https:// in the server name: " + server) | ||
166 | sys.exit(1) | ||
167 | |||
168 | # Construct the final URL | ||
169 | return f"{server}" | ||
170 | |||
151 | 171 | ||
152 | if __name__ == '__main__': | 172 | if __name__ == '__main__': |
153 | arg_parse = argparse_oe.ArgumentParser(description="This scripts will send an error report to your specified error-report-web server.") | 173 | arg_parse = argparse_oe.ArgumentParser(description="This scripts will send an error report to your specified error-report-web server.") |
@@ -164,8 +184,7 @@ if __name__ == '__main__': | |||
164 | arg_parse.add_argument("-s", | 184 | arg_parse.add_argument("-s", |
165 | "--server", | 185 | "--server", |
166 | help="Server to send error report to", | 186 | help="Server to send error report to", |
167 | type=str, | 187 | type=str) |
168 | default="errors.yoctoproject.org") | ||
169 | 188 | ||
170 | arg_parse.add_argument("-e", | 189 | arg_parse.add_argument("-e", |
171 | "--email", | 190 | "--email", |
@@ -190,18 +209,22 @@ if __name__ == '__main__': | |||
190 | help="Return the result in json format, silences all other output", | 209 | help="Return the result in json format, silences all other output", |
191 | action="store_true") | 210 | action="store_true") |
192 | 211 | ||
193 | arg_parse.add_argument("--no-ssl", | 212 | arg_parse.add_argument("-d", |
194 | help="Use http instead of https protocol", | 213 | "--debug", |
195 | dest="protocol", | 214 | help="Enable debug mode to print request/response details", |
196 | action="store_const", const="http://", default="https://") | 215 | action="store_true") |
197 | |||
198 | |||
199 | 216 | ||
200 | args = arg_parse.parse_args() | 217 | args = arg_parse.parse_args() |
201 | 218 | ||
219 | args.server = validate_server_url(args) | ||
220 | |||
202 | if (args.json == False): | 221 | if (args.json == False): |
203 | print("Preparing to send errors to: "+args.server) | 222 | print("Preparing to send errors to: "+args.server) |
204 | 223 | ||
224 | # Enable debugging if requested | ||
225 | if args.debug: | ||
226 | log.setLevel(logging.DEBUG) | ||
227 | |||
205 | data = prepare_data(args) | 228 | data = prepare_data(args) |
206 | send_data(data, args) | 229 | send_data(data, args) |
207 | 230 | ||