Skip to content

Commit 8ea2f59

Browse files
committed
Started work
Probably no changes will be happening in the near future though..
1 parent 9521171 commit 8ea2f59

File tree

12 files changed

+673
-0
lines changed

12 files changed

+673
-0
lines changed

.idea/PySysLogQt.iml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 146 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

__main__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""PySysLogQt entry point.
2+
3+
Author: Randy Paredis
4+
Date: 03/12/2020
5+
"""
6+
7+
from PyQt5 import QtWidgets
8+
from main.MainWindow import MainWindow
9+
import sys
10+
11+
12+
if __name__ == '__main__':
13+
NAME = "PySysLogQt"
14+
app = QtWidgets.QApplication(sys.argv)
15+
app.setApplicationName(NAME)
16+
app.setApplicationDisplayName(NAME)
17+
18+
mainwindow = MainWindow()
19+
mainwindow.show()
20+
code = app.exec_()

main/MainWindow.py

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
"""Main window of the app.
2+
3+
Author: Randy Paredis
4+
Date: 03/12/2020
5+
"""
6+
from PyQt5 import QtWidgets, QtCore, QtGui, uic
7+
import socketserver, datetime, re
8+
9+
from main.ServerDialog import ServerDialog
10+
from main.Threading import WorkerThread
11+
12+
TABLE = None
13+
14+
class SyslogUDPHandler(socketserver.BaseRequestHandler):
15+
levels = {
16+
0: "EMERGENCY",
17+
1: "ALERT",
18+
2: "CRITICAL",
19+
3: "ERROR",
20+
4: "WARNING",
21+
5: "NOTICE",
22+
6: "INFO",
23+
7: "DEBUG"
24+
}
25+
26+
facs = {
27+
0: "Kernel",
28+
1: "User-Level",
29+
2: "Mail System",
30+
3: "System Daemons",
31+
4: "Security 1",
32+
5: "Internal",
33+
6: "Line Printer",
34+
7: "Network News",
35+
8: "UUCP",
36+
9: "Clock Daemon",
37+
10: "Security 2",
38+
11: "FTP Daemon",
39+
12: "NTP",
40+
13: "Log Audit",
41+
14: "Log Alert",
42+
15: "Scheduling",
43+
16: "Local 0",
44+
17: "Local 1",
45+
18: "Local 2",
46+
19: "Local 3",
47+
20: "Local 4",
48+
21: "Local 5",
49+
22: "Local 6",
50+
23: "Local 7"
51+
}
52+
53+
colors = {
54+
"EMERGENCY": (255, 130, 130),
55+
"ALERT": (255, 130, 130),
56+
"CRITICAL": (255, 130, 130),
57+
"ERROR": (255, 153, 94),
58+
"WARNING": (255, 222, 130),
59+
"NOTICE": (130, 255, 150),
60+
"INFO": (130, 220, 255),
61+
"DEBUG": (212, 212, 212)
62+
}
63+
64+
def handle(self):
65+
data = bytes.decode(self.request[0].strip())
66+
match = re.search(r"^<\d+>", data)
67+
prio = int(match.group(0)[1:-1])
68+
69+
socket = self.request[1]
70+
f = socket.fileno()
71+
level = self.levels[prio ^ (f << 3)]
72+
73+
global TABLE
74+
row = TABLE.rowCount()
75+
TABLE.insertRow(row)
76+
TABLE.setItem(row, 0, QtWidgets.QTableWidgetItem(str(datetime.date.today())))
77+
TABLE.setItem(row, 1, QtWidgets.QTableWidgetItem(str(datetime.datetime.now().time())))
78+
TABLE.setItem(row, 2, QtWidgets.QTableWidgetItem(self.facs[f]))
79+
TABLE.setItem(row, 3, QtWidgets.QTableWidgetItem(level))
80+
TABLE.setItem(row, 4, QtWidgets.QTableWidgetItem(data[match.span(0)[1]:-1]))
81+
for i in range(5):
82+
if i in [2, 3]:
83+
TABLE.item(row, i).setTextAlignment(QtCore.Qt.AlignCenter)
84+
TABLE.item(row, i).setBackground(QtGui.QColor(*self.colors[level]))
85+
86+
class MainWindow(QtWidgets.QMainWindow):
87+
def __init__(self):
88+
super(MainWindow, self).__init__(flags=QtCore.Qt.WindowFlags())
89+
uic.loadUi("main/MainWindow.ui", self)
90+
self.server = None
91+
self.pb_change.clicked.connect(self.change)
92+
self.search.textChanged.connect(self.searchTable)
93+
94+
global TABLE
95+
TABLE = self.messages
96+
97+
self.thread = WorkerThread(self.run)
98+
self.change()
99+
100+
def searchTable(self, text):
101+
# TODO: fancy search
102+
# - Wildcards
103+
# - Column selectors
104+
# - ...
105+
global TABLE
106+
for r in range(TABLE.rowCount()):
107+
if text != "" and \
108+
text.lower() not in " ".join([x.lower() for x in [TABLE.item(r, i).text() for i in range(5)]]):
109+
TABLE.hideRow(r)
110+
else:
111+
TABLE.showRow(r)
112+
113+
def change(self):
114+
self.end()
115+
116+
dialog = ServerDialog()
117+
dialog.exec_()
118+
self.host.setText(dialog.host.text())
119+
self.port.setValue(dialog.port.value())
120+
121+
self.start()
122+
123+
def start(self):
124+
# TODO: catch "address already in use"
125+
self.server = socketserver.UDPServer((self.host.text(), self.port.value()), SyslogUDPHandler)
126+
self.thread.start()
127+
128+
def run(self):
129+
# print("STARTED")
130+
self.server.serve_forever(poll_interval=0.5)
131+
132+
def end(self):
133+
if self.server:
134+
self.server.shutdown()
135+
# print("ENDED")
136+
137+
def closeEvent(self, QCloseEvent):
138+
self.end()
139+
super(MainWindow, self).closeEvent(QCloseEvent)

0 commit comments

Comments
 (0)