From c0e8299d34ff42eafe6269db48d9134da9d4e9c8 Mon Sep 17 00:00:00 2001 From: Reiko Kaps Date: Thu, 18 Jun 2020 18:45:11 +0200 Subject: [PATCH] =?UTF-8?q?Etwas=20aufger=C3=A4umt=20und=20vereinfacht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jitsi-log.py | 109 ++++++++++++++++++++++----------------------------- 1 file changed, 47 insertions(+), 62 deletions(-) diff --git a/jitsi-log.py b/jitsi-log.py index 7753e2b..d91868b 100755 --- a/jitsi-log.py +++ b/jitsi-log.py @@ -4,20 +4,12 @@ import re import sys import threading -import time from time import sleep from os.path import basename - from datetime import datetime from argparse import ArgumentParser from http.server import BaseHTTPRequestHandler, HTTPServer - -try: - from pygtail import Pygtail - -except ImportError as e: - print('[Error] Please install pygtail via pip! {}'.format(e)) - sys.exit(1) +from urllib.parse import urlparse try: from sh import tail @@ -27,6 +19,32 @@ except ImportError as e: sys.exit(1) +# active room dictionary +roomList = {} + +# @see https://regex101.com/r/R1B1OL/1 +regex = r"(Jicofo)\s(\d+-\d+-\d+)\s(\d+\:\d+\:\d+\.\d+)\s(\w+):\s\[(\d+)\]\s(.*)\(\)\s(.*)" +prog = re.compile(regex) + +## +# new jitsi room +room_regex = r"(^Joining\sthe\sroom):(.*)" +room = re.compile(room_regex) + +# disposed room +disposed_regex = r"^Disposed\sconference\sfor\sroom\:\s(.*)@(.*)\sconference\scount:\s(\d+)" +disposed = re.compile(disposed_regex) + +## +# get the room owner +owner_regex = r"Granted\sowner\sto\s([a-z0-9-]+)\@(.*)\/(.*)" +owner = re.compile(owner_regex) + +# get member for room +member_regex = r"^Member\s(.*)@(.*)\/(.*)\sjoined." +member = re.compile(member_regex) + + class MeetingRoom(): """ represent a Jitsi Meetingroom @@ -74,23 +92,22 @@ class logThread(threading.Thread): class MyServer(BaseHTTPRequestHandler): def do_GET(self): - self.send_response(200) - self.send_header("Content-type", "text/html") - self.end_headers() - self.wfile.write(bytes("Jitsi Stats", "utf-8")) - self.wfile.write(bytes("

Request: %s

" % self.path, "utf-8")) - self.wfile.write(bytes("", "utf-8")) - self.wfile.write(bytes("

This is an example web server.

", "utf-8")) if basename(self.path) in roomList: - self.wfile.write(bytes("

"+basename(self.path)+": "+str(roomList[basename(self.path)].ctime)+"

", "utf-8")) - self.wfile.write(bytes("

Participants: "+str(len(roomList[basename(self.path)].members))+"

", "utf-8")) + self.send_response(200) + self.send_header("Content-type", "text/plain") + self.end_headers() + response_string = bytes(basename(self.path) + + '|' + + str(roomList[basename(self.path)].ctime) + + '|' + + str(len(roomList[basename(self.path)].members)) + + '|', "utf-8") + self.wfile.write(response_string) else: - for key, value in roomList.items(): - link = '

{}

'.format(value.jid, key) - self.wfile.write(bytes(link, "utf-8")) + self.send_response(404) + self.send_header("Content-type", "text/plain") + self.end_headers() - - self.wfile.write(bytes("", "utf-8")) def getRoomName(jid): @@ -101,36 +118,6 @@ def mkDatetime(str_date, str_time): return datetime.fromisoformat('{} {}'.format(str_date, str_time)) -# active room dictionary -roomList = {} -testList = { - 'test': 'Nichts wichtiges', - 'lounge': 'lounge@meet.leinelab.de' -} - -# @see https://regex101.com/r/R1B1OL/1 -regex = r"(Jicofo)\s(\d+-\d+-\d+)\s(\d+\:\d+\:\d+\.\d+)\s(\w+):\s\[(\d+)\]\s(.*)\(\)\s(.*)" -prog = re.compile(regex) - -## -# new jitsi room -room_regex = r"(^Joining\sthe\sroom):(.*)" -room = re.compile(room_regex) - -# disposed room -disposed_regex = r"^Disposed\sconference\sfor\sroom\:\s(.*)@(.*)\sconference\scount:\s(\d+)" -disposed = re.compile(disposed_regex) - -## -# get the room owner -owner_regex = r"Granted\sowner\sto\s([a-z0-9-]+)\@(.*)\/(.*)" -owner = re.compile(owner_regex) - -# get member for room -member_regex = r"^Member\s(.*)@(.*)\/(.*)\sjoined." -member = re.compile(member_regex) - - def process_line(line): """ process a logfile line, using global object and vars @@ -187,15 +174,19 @@ def getLogMsg(logfile): for line in tail("-f", logfile, _iter=True): process_line(line) + if __name__ == '__main__': # start cmdline processing parser = ArgumentParser(description='Jitsi Meet Conference Stats') parser.add_argument('--log', '-l', - help='full path to jicofo logfile eg. /var/log/jitsi/jicofo.log') + help='full path to jicofo logfile eg.' + + ' /var/log/jitsi/jicofo.log') parser.add_argument('--verbose', '-v', - help='be verbose eg. for debugging', action='store_true') + help='be verbose eg. for debugging', + action='store_true') parser.add_argument('--logwatch', '-w', - help='run as logwatch module, dont start the webserver and only run once') + help='run as logwatch module, ' + + ' dont start the webserver and only run once') args = parser.parse_args() @@ -215,9 +206,3 @@ if __name__ == '__main__': webServer.serve_forever() except: pass - - # for key in roomList: - # print('Room : {}'.format(roomList[key].jid)) - # print(' Created: {}'.format(roomList[key].ctime)) - # print(' Owner : {}'.format(roomList[key].getOwner())) - # print(' Members: {}'.format(roomList[key].getMembers()))