.BANCHO. Add Sentry to IRC server

This commit is contained in:
Nyo 2016-07-14 15:38:28 +02:00
parent 95df629e1c
commit a89ad31017
5 changed files with 62 additions and 51 deletions

View File

@ -60,7 +60,8 @@ class config:
self.config.get("debug","time")
self.config.get("sentry","enable")
self.config.get("sentry","dns")
self.config.get("sentry","banchodns")
self.config.get("sentry","ircdns")
self.config.get("discord","enable")
self.config.get("discord","boturl")
@ -106,7 +107,8 @@ class config:
self.config.add_section("sentry")
self.config.set("sentry", "enable", "0")
self.config.set("sentry", "dns", "")
self.config.set("sentry", "banchodns", "")
self.config.set("sentry", "ircdns", "")
self.config.add_section("discord")
self.config.set("discord", "enable", "0")

View File

@ -1,4 +1,5 @@
import sys
import traceback
import socket
import select
import time
@ -8,6 +9,7 @@ from helpers import logHelper as log
from objects import glob
from helpers import chatHelper as chat
import raven
class Client:
"""
@ -575,6 +577,10 @@ class Server:
def start(self):
"""Start IRC server main loop"""
# Sentry
if glob.sentry == True:
sentryClient = raven.Client(glob.conf.config["sentry"]["ircdns"])
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try:
@ -586,41 +592,45 @@ class Server:
lastAliveCheck = time.time()
# Main server loop
while True:
(iwtd, owtd, ewtd) = select.select(
[serversocket] + [x.socket for x in self.clients.values()],
[x.socket for x in self.clients.values()
if x.writeBufferSize() > 0],
[],
2)
try:
while True:
(iwtd, owtd, ewtd) = select.select(
[serversocket] + [x.socket for x in self.clients.values()],
[x.socket for x in self.clients.values()
if x.writeBufferSize() > 0],
[],
2)
# Handle incoming connections
for x in iwtd:
if x in self.clients:
self.clients[x].readSocket()
else:
(conn, addr) = x.accept()
try:
self.clients[conn] = Client(self, conn)
log.info("[IRC] Accepted connection from {}:{}".format(addr[0], addr[1]))
except socket.error as e:
# Handle incoming connections
for x in iwtd:
if x in self.clients:
self.clients[x].readSocket()
else:
(conn, addr) = x.accept()
try:
conn.close()
except:
pass
self.clients[conn] = Client(self, conn)
log.info("[IRC] Accepted connection from {}:{}".format(addr[0], addr[1]))
except socket.error as e:
try:
conn.close()
except:
pass
# Handle outgoing connections
for x in owtd:
if x in self.clients: # client may have been disconnected
self.clients[x].writeSocket()
# Make sure all IRC clients are still connected
now = time.time()
if lastAliveCheck + 10 < now:
for client in list(self.clients.values()):
client.checkAlive()
lastAliveCheck = now
# Handle outgoing connections
for x in owtd:
if x in self.clients: # client may have been disconnected
self.clients[x].writeSocket()
# Make sure all IRC clients are still connected
now = time.time()
if lastAliveCheck + 10 < now:
for client in list(self.clients.values()):
client.checkAlive()
lastAliveCheck = now
except:
log.error("[IRC] Unknown error!\n```\n{}\n{}```".format(sys.exc_info(), traceback.format_exc()))
if glob.sentry == True:
sentryClient.captureException()
def main(port=6667):
glob.ircServer = Server(port)

View File

@ -4,7 +4,6 @@ from objects import tokenList
from objects import channelList
from objects import matchList
from objects import fileLocks
from raven import Client
try:
with open("version") as f:

32
pep.py
View File

@ -154,6 +154,22 @@ if __name__ == "__main__":
if glob.debug == True:
consoleHelper.printColored("[!] Warning! Server running in debug mode!", bcolors.YELLOW)
# 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"]["banchodns"], release=glob.VERSION)
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)
# Cloudflare memes
glob.cloudflare = generalFunctions.stringToBool(glob.conf.config["server"]["cloudflare"])
# IRC start message and console output
glob.irc = generalFunctions.stringToBool(glob.conf.config["irc"]["enable"])
if glob.irc == True:
@ -174,22 +190,6 @@ if __name__ == "__main__":
except:
consoleHelper.printColored("[!] Invalid server port! Please check your config.ini and run the server again", bcolors.RED)
# 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"], release=glob.VERSION)
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)
# Cloudflare memes
glob.cloudflare = generalFunctions.stringToBool(glob.conf.config["server"]["cloudflare"])
# Server start message and console output
log.logMessage("Server started!", discord=True, of="info.txt", stdout=False)
consoleHelper.printColored("> Tornado listening for HTTP(s) clients on 127.0.0.1:{}...".format(serverPort), bcolors.GREEN)

View File

@ -1 +1 @@
1.6.1
1.6.2