2015-02-24 16:40:01 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# Copyright (C) 2014 GNS3 Technologies Inc.
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2015-03-05 23:11:43 +00:00
|
|
|
import os
|
2015-03-05 16:44:01 +00:00
|
|
|
import sys
|
|
|
|
import struct
|
2017-02-27 10:31:51 +00:00
|
|
|
import aiohttp
|
2015-03-05 16:44:01 +00:00
|
|
|
import platform
|
2018-09-12 13:38:20 +00:00
|
|
|
import locale
|
2018-10-04 14:32:49 +00:00
|
|
|
import distro
|
2015-02-24 16:40:01 +00:00
|
|
|
|
2015-03-31 19:52:00 +00:00
|
|
|
try:
|
|
|
|
import raven
|
2016-07-25 17:34:08 +00:00
|
|
|
from raven.transport.http import HTTPTransport
|
2015-03-31 19:52:00 +00:00
|
|
|
RAVEN_AVAILABLE = True
|
|
|
|
except ImportError:
|
2015-04-04 01:08:29 +00:00
|
|
|
# raven is not installed with deb package in order to simplify packaging
|
2015-03-31 19:52:00 +00:00
|
|
|
RAVEN_AVAILABLE = False
|
|
|
|
|
2015-11-05 09:50:37 +00:00
|
|
|
from .version import __version__, __version_info__
|
2015-02-24 16:40:01 +00:00
|
|
|
from .config import Config
|
2015-05-28 09:29:30 +00:00
|
|
|
from .utils.get_resource import get_resource
|
2015-02-24 16:40:01 +00:00
|
|
|
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2016-05-18 09:23:45 +00:00
|
|
|
# Dev build
|
2015-11-05 09:50:37 +00:00
|
|
|
if __version_info__[3] != 0:
|
2015-05-28 10:17:56 +00:00
|
|
|
import faulthandler
|
|
|
|
|
2015-05-28 10:17:25 +00:00
|
|
|
# Display a traceback in case of segfault crash. Usefull when frozen
|
|
|
|
# Not enabled by default for security reason
|
|
|
|
log.info("Enable catching segfault")
|
2017-05-16 17:28:47 +00:00
|
|
|
try:
|
|
|
|
faulthandler.enable()
|
|
|
|
except Exception:
|
|
|
|
pass # Could fail when loaded into tests
|
2015-05-28 10:17:25 +00:00
|
|
|
|
|
|
|
|
2015-02-24 16:40:01 +00:00
|
|
|
class CrashReport:
|
|
|
|
|
|
|
|
"""
|
|
|
|
Report crash to a third party service
|
|
|
|
"""
|
|
|
|
|
2019-09-30 08:24:26 +00:00
|
|
|
DSN = "https://7f7ec6fa8e1344ff9cfe0757efb00eb2:1e0a0b09cdcf4d169b937b7a40dc620c@sentry.io/38482"
|
2015-03-05 23:11:43 +00:00
|
|
|
if hasattr(sys, "frozen"):
|
2015-05-28 09:29:30 +00:00
|
|
|
cacert = get_resource("cacert.pem")
|
2015-05-28 11:24:45 +00:00
|
|
|
if cacert is not None and os.path.isfile(cacert):
|
2015-03-06 18:20:28 +00:00
|
|
|
DSN += "?ca_certs={}".format(cacert)
|
|
|
|
else:
|
2015-03-06 18:25:25 +00:00
|
|
|
log.warning("The SSL certificate bundle file '{}' could not be found".format(cacert))
|
2015-02-24 16:40:01 +00:00
|
|
|
_instance = None
|
|
|
|
|
2015-02-24 19:22:10 +00:00
|
|
|
def __init__(self):
|
|
|
|
self._client = None
|
|
|
|
|
2015-06-23 17:27:28 +00:00
|
|
|
# We don't want sentry making noise if an error is catched when you don't have internet
|
|
|
|
sentry_errors = logging.getLogger('sentry.errors')
|
|
|
|
sentry_errors.disabled = True
|
|
|
|
|
|
|
|
sentry_uncaught = logging.getLogger('sentry.errors.uncaught')
|
|
|
|
sentry_uncaught.disabled = True
|
|
|
|
|
2015-03-02 08:05:32 +00:00
|
|
|
def capture_exception(self, request=None):
|
2015-03-31 19:52:00 +00:00
|
|
|
if not RAVEN_AVAILABLE:
|
|
|
|
return
|
2015-04-24 16:30:31 +00:00
|
|
|
if os.path.exists(".git"):
|
|
|
|
log.warning("A .git directory exist crash report is turn off for developers")
|
|
|
|
return
|
2015-02-24 16:40:01 +00:00
|
|
|
server_config = Config.instance().get_section_config("Server")
|
|
|
|
if server_config.getboolean("report_errors"):
|
|
|
|
if self._client is None:
|
2016-07-25 17:34:08 +00:00
|
|
|
self._client = raven.Client(CrashReport.DSN, release=__version__, raise_send_errors=True, transport=HTTPTransport)
|
2015-03-02 08:05:32 +00:00
|
|
|
if request is not None:
|
|
|
|
self._client.http_context({
|
|
|
|
"method": request.method,
|
|
|
|
"url": request.path,
|
|
|
|
"data": request.json,
|
|
|
|
})
|
2018-09-12 13:38:20 +00:00
|
|
|
|
|
|
|
context = {
|
2015-03-05 16:44:01 +00:00
|
|
|
"os:name": platform.system(),
|
|
|
|
"os:release": platform.release(),
|
2015-03-05 19:12:56 +00:00
|
|
|
"os:win_32": " ".join(platform.win32_ver()),
|
|
|
|
"os:mac": "{} {}".format(platform.mac_ver()[0], platform.mac_ver()[2]),
|
2018-10-04 14:32:49 +00:00
|
|
|
"os:linux": " ".join(distro.linux_distribution()),
|
2017-02-27 10:31:51 +00:00
|
|
|
"aiohttp:version": aiohttp.__version__,
|
2015-03-05 16:44:01 +00:00
|
|
|
"python:version": "{}.{}.{}".format(sys.version_info[0],
|
|
|
|
sys.version_info[1],
|
|
|
|
sys.version_info[2]),
|
|
|
|
"python:bit": struct.calcsize("P") * 8,
|
2015-03-05 23:11:43 +00:00
|
|
|
"python:encoding": sys.getdefaultencoding(),
|
|
|
|
"python:frozen": "{}".format(hasattr(sys, "frozen"))
|
2018-09-12 13:38:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if sys.platform.startswith("linux") and not hasattr(sys, "frozen"):
|
|
|
|
# add locale information
|
|
|
|
try:
|
|
|
|
language, encoding = locale.getlocale()
|
|
|
|
context["locale:language"] = language
|
|
|
|
context["locale:encoding"] = encoding
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
# add GNS3 VM version if it exists
|
|
|
|
home = os.path.expanduser("~")
|
|
|
|
gns3vm_version = os.path.join(home, ".config", "GNS3", "gns3vm_version")
|
|
|
|
if os.path.isfile(gns3vm_version):
|
|
|
|
try:
|
|
|
|
with open(gns3vm_version) as fd:
|
|
|
|
context["gns3vm:version"] = fd.readline().strip()
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
self._client.tags_context(context)
|
2015-03-03 12:04:30 +00:00
|
|
|
try:
|
2015-03-05 23:11:43 +00:00
|
|
|
report = self._client.captureException()
|
2015-03-03 12:04:30 +00:00
|
|
|
except Exception as e:
|
2015-03-05 23:11:43 +00:00
|
|
|
log.error("Can't send crash report to Sentry: {}".format(e))
|
2015-03-14 04:42:25 +00:00
|
|
|
return
|
2015-03-05 23:11:43 +00:00
|
|
|
log.info("Crash report sent with event ID: {}".format(self._client.get_ident(report)))
|
2015-02-24 16:40:01 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def instance(cls):
|
|
|
|
if cls._instance is None:
|
|
|
|
cls._instance = CrashReport()
|
|
|
|
return cls._instance
|