.BANCHO. Add Sentry logging
This commit is contained in:
parent
ec2bce8893
commit
97262eda12
|
@ -44,11 +44,18 @@ from events import matchTransferHostEvent
|
||||||
from events import matchFailedEvent
|
from events import matchFailedEvent
|
||||||
from events import matchInviteEvent
|
from events import matchInviteEvent
|
||||||
from events import matchChangeTeamEvent
|
from events import matchChangeTeamEvent
|
||||||
|
|
||||||
|
# Exception tracking
|
||||||
|
import tornado.web
|
||||||
|
import tornado.gen
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
from raven.contrib.tornado import SentryMixin
|
||||||
from helpers import logHelper as log
|
from helpers import logHelper as log
|
||||||
|
|
||||||
class handler(requestHelper.asyncRequestHandler):
|
class handler(SentryMixin, requestHelper.asyncRequestHandler):
|
||||||
|
@tornado.web.asynchronous
|
||||||
|
@tornado.gen.engine
|
||||||
def asyncPost(self):
|
def asyncPost(self):
|
||||||
try:
|
try:
|
||||||
# Track time if needed
|
# Track time if needed
|
||||||
|
@ -195,17 +202,15 @@ class handler(requestHelper.asyncRequestHandler):
|
||||||
else:
|
else:
|
||||||
self.write(responseData)
|
self.write(responseData)
|
||||||
except:
|
except:
|
||||||
msg = "Unhandled exception in mainHandler:\n```\n{}\n{}\n```".format(sys.exc_info(), traceback.format_exc())
|
log.error("Unknown error!\n```\n{}\n{}```".format(sys.exc_info(), traceback.format_exc()))
|
||||||
log.error("{}".format(msg), True)
|
if glob.sentry:
|
||||||
|
yield tornado.gen.Task(self.captureException, exc_info=True)
|
||||||
finally:
|
finally:
|
||||||
try:
|
|
||||||
if not self._finished:
|
|
||||||
self.finish()
|
self.finish()
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
@tornado.web.asynchronous
|
||||||
|
@tornado.gen.engine
|
||||||
def asyncGet(self):
|
def asyncGet(self):
|
||||||
try:
|
|
||||||
html = "<html><head><title>MA MAURO ESISTE?</title><style type='text/css'>body{width:30%}</style></head><body><pre>"
|
html = "<html><head><title>MA MAURO ESISTE?</title><style type='text/css'>body{width:30%}</style></head><body><pre>"
|
||||||
html += " _ __<br>"
|
html += " _ __<br>"
|
||||||
html += " (_) / /<br>"
|
html += " (_) / /<br>"
|
||||||
|
@ -227,5 +232,5 @@ class handler(requestHelper.asyncRequestHandler):
|
||||||
html += "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>"
|
html += "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>"
|
||||||
html += "</marquee><br><strike>reverse engineering a protocol impossible to reverse engineer since always</strike><br>we are actually reverse engineering bancho successfully. for the third time.</pre></body></html>"
|
html += "</marquee><br><strike>reverse engineering a protocol impossible to reverse engineer since always</strike><br>we are actually reverse engineering bancho successfully. for the third time.</pre></body></html>"
|
||||||
self.write(html)
|
self.write(html)
|
||||||
finally:
|
#yield tornado.gen.Task(self.captureMessage, "test")
|
||||||
self.finish()
|
self.finish()
|
||||||
|
|
|
@ -59,6 +59,9 @@ class config:
|
||||||
self.config.get("debug","packets")
|
self.config.get("debug","packets")
|
||||||
self.config.get("debug","time")
|
self.config.get("debug","time")
|
||||||
|
|
||||||
|
self.config.get("sentry","enable")
|
||||||
|
self.config.get("sentry","dns")
|
||||||
|
|
||||||
self.config.get("discord","enable")
|
self.config.get("discord","enable")
|
||||||
self.config.get("discord","boturl")
|
self.config.get("discord","boturl")
|
||||||
self.config.get("discord","devgroup")
|
self.config.get("discord","devgroup")
|
||||||
|
@ -95,6 +98,10 @@ class config:
|
||||||
self.config.set("debug", "packets", "0")
|
self.config.set("debug", "packets", "0")
|
||||||
self.config.set("debug", "time", "0")
|
self.config.set("debug", "time", "0")
|
||||||
|
|
||||||
|
self.config.add_section("sentry")
|
||||||
|
self.config.set("sentry", "enable", "0")
|
||||||
|
self.config.set("sentry", "dns", "")
|
||||||
|
|
||||||
self.config.add_section("discord")
|
self.config.add_section("discord")
|
||||||
self.config.set("discord", "enable", "0")
|
self.config.set("discord", "enable", "0")
|
||||||
self.config.set("discord", "boturl", "")
|
self.config.set("discord", "boturl", "")
|
||||||
|
|
|
@ -3,6 +3,8 @@ import tornado.web
|
||||||
import tornado.gen
|
import tornado.gen
|
||||||
from tornado.ioloop import IOLoop
|
from tornado.ioloop import IOLoop
|
||||||
from objects import glob
|
from objects import glob
|
||||||
|
from raven.contrib.tornado import SentryMixin
|
||||||
|
from raven.contrib.tornado import AsyncSentryClient
|
||||||
|
|
||||||
class asyncRequestHandler(tornado.web.RequestHandler):
|
class asyncRequestHandler(tornado.web.RequestHandler):
|
||||||
"""
|
"""
|
||||||
|
@ -14,12 +16,18 @@ class asyncRequestHandler(tornado.web.RequestHandler):
|
||||||
@tornado.web.asynchronous
|
@tornado.web.asynchronous
|
||||||
@tornado.gen.engine
|
@tornado.gen.engine
|
||||||
def get(self, *args, **kwargs):
|
def get(self, *args, **kwargs):
|
||||||
|
try:
|
||||||
yield tornado.gen.Task(runBackground, (self.asyncGet, tuple(args), dict(kwargs)))
|
yield tornado.gen.Task(runBackground, (self.asyncGet, tuple(args), dict(kwargs)))
|
||||||
|
except Exception as e:
|
||||||
|
yield tornado.gen.Task(self.captureException, exc_info=True)
|
||||||
|
|
||||||
@tornado.web.asynchronous
|
@tornado.web.asynchronous
|
||||||
@tornado.gen.engine
|
@tornado.gen.engine
|
||||||
def post(self, *args, **kwargs):
|
def post(self, *args, **kwargs):
|
||||||
|
try:
|
||||||
yield tornado.gen.Task(runBackground, (self.asyncPost, tuple(args), dict(kwargs)))
|
yield tornado.gen.Task(runBackground, (self.asyncPost, tuple(args), dict(kwargs)))
|
||||||
|
except Exception as e:
|
||||||
|
yield tornado.gen.Task(self.captureException, exc_info=True)
|
||||||
|
|
||||||
def asyncGet(self, *args, **kwargs):
|
def asyncGet(self, *args, **kwargs):
|
||||||
self.send_error(405)
|
self.send_error(405)
|
||||||
|
|
|
@ -4,6 +4,7 @@ from objects import tokenList
|
||||||
from objects import channelList
|
from objects import channelList
|
||||||
from objects import matchList
|
from objects import matchList
|
||||||
from objects import fileLocks
|
from objects import fileLocks
|
||||||
|
from raven import Client
|
||||||
|
|
||||||
VERSION = "1.2"
|
VERSION = "1.2"
|
||||||
|
|
||||||
|
@ -17,10 +18,10 @@ restarting = False
|
||||||
pool = None
|
pool = None
|
||||||
fLocks = fileLocks.fileLocks()
|
fLocks = fileLocks.fileLocks()
|
||||||
|
|
||||||
|
|
||||||
debug = False
|
debug = False
|
||||||
outputRequestTime = False
|
outputRequestTime = False
|
||||||
outputPackets = False
|
outputPackets = False
|
||||||
discord = False
|
discord = False
|
||||||
gzip = False
|
gzip = False
|
||||||
localize = False
|
localize = False
|
||||||
|
sentry = False
|
||||||
|
|
22
pep.py
22
pep.py
|
@ -9,6 +9,9 @@ import tornado.web
|
||||||
import tornado.httpserver
|
import tornado.httpserver
|
||||||
import tornado.gen
|
import tornado.gen
|
||||||
|
|
||||||
|
# Raven
|
||||||
|
from raven.contrib.tornado import AsyncSentryClient
|
||||||
|
|
||||||
# pep.py files
|
# pep.py files
|
||||||
from constants import bcolors
|
from constants import bcolors
|
||||||
from helpers import configHelper
|
from helpers import configHelper
|
||||||
|
@ -20,12 +23,14 @@ from helpers import databaseHelperNew
|
||||||
from helpers import generalFunctions
|
from helpers import generalFunctions
|
||||||
from helpers import logHelper as log
|
from helpers import logHelper as log
|
||||||
|
|
||||||
|
|
||||||
from handlers import mainHandler
|
from handlers import mainHandler
|
||||||
from handlers import apiIsOnlineHandler
|
from handlers import apiIsOnlineHandler
|
||||||
from handlers import apiOnlineUsersHandler
|
from handlers import apiOnlineUsersHandler
|
||||||
from handlers import apiServerStatusHandler
|
from handlers import apiServerStatusHandler
|
||||||
from handlers import ciTriggerHandler
|
from handlers import ciTriggerHandler
|
||||||
|
|
||||||
|
|
||||||
def make_app():
|
def make_app():
|
||||||
return tornado.web.Application([
|
return tornado.web.Application([
|
||||||
(r"/", mainHandler.handler),
|
(r"/", mainHandler.handler),
|
||||||
|
@ -152,11 +157,24 @@ if __name__ == "__main__":
|
||||||
except:
|
except:
|
||||||
consoleHelper.printColored("[!] Invalid server port! Please check your config.ini and run the server again", bcolors.RED)
|
consoleHelper.printColored("[!] Invalid server port! Please check your config.ini and run the server again", bcolors.RED)
|
||||||
|
|
||||||
|
# Make app
|
||||||
|
#application = tornado.httpserver.HTTPServer(make_app())
|
||||||
|
application = make_app()
|
||||||
|
|
||||||
|
# Set up sentry
|
||||||
|
try:
|
||||||
|
glob.sentry = generalFunctions.stringToBool(glob.conf.config["sentry"]["enable"])
|
||||||
|
if glob.sentry == True:
|
||||||
|
application.sentry_client = AsyncSentryClient(glob.conf.config["sentry"]["dns"])
|
||||||
|
else:
|
||||||
|
consoleHelper.printColored("[!] Warning! Sentry logging is disabled!", bcolors.YELLOW)
|
||||||
|
except:
|
||||||
|
consoleHelper.printColored("[!] Error while starting sentry client! Please check your config.ini and run the server again", bcolors.RED)
|
||||||
|
|
||||||
# Server start message and console output
|
# Server start message and console output
|
||||||
log.logMessage("Server started!", discord=True, of="info.txt", stdout=False)
|
log.logMessage("Server started!", discord=True, of="info.txt", stdout=False)
|
||||||
consoleHelper.printColored("> Tornado listening for clients on 127.0.0.1:{}...".format(serverPort), bcolors.GREEN)
|
consoleHelper.printColored("> Tornado listening for clients on 127.0.0.1:{}...".format(serverPort), bcolors.GREEN)
|
||||||
|
|
||||||
# Start tornado
|
# Start tornado
|
||||||
app = tornado.httpserver.HTTPServer(make_app())
|
application.listen(serverPort)
|
||||||
app.listen(serverPort)
|
|
||||||
tornado.ioloop.IOLoop.instance().start()
|
tornado.ioloop.IOLoop.instance().start()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user