Implement port monitoring, improve punycode handling, other minor improvements
This commit is contained in:
parent
eae9d81f2a
commit
3e333a9538
|
@ -1,4 +1,4 @@
|
||||||
import datetime, encodings.idna, os, setuptools, socketserver, ssltools, sys, syslog, threading
|
import datetime, encodings.idna, os, porttools, setuptools, socket, socketserver, ssltools, sys, syslog, threading
|
||||||
|
|
||||||
SYSLOG = 0
|
SYSLOG = 0
|
||||||
STDOUT = 1
|
STDOUT = 1
|
||||||
|
@ -34,10 +34,12 @@ def logger(message, prio=syslog.LOG_INFO, sink=logging):
|
||||||
logger(message, prio, logging)
|
logger(message, prio, logging)
|
||||||
|
|
||||||
def listIncluded(host, section):
|
def listIncluded(host, section):
|
||||||
for i in setuptools.getListSetting("SSL" if section == SSL else "Ports", "hosts"):
|
if not setuptools.getListSetting("Server", "ignorelist"):
|
||||||
if encodings.idna.ToASCII(i[0].lower()).decode("UTF-8") == encodings.idna.ToASCII(host.lower()).decode("UTF-8"):
|
for i in setuptools.getListSetting("SSL" if section == SSL else "Ports", "hosts"):
|
||||||
return True
|
if encodings.idna.ToASCII(i[0].lower()).decode("UTF-8") == encodings.idna.ToASCII(host.lower()).decode("UTF-8"):
|
||||||
return False
|
return True
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
class TCPHandler(socketserver.StreamRequestHandler):
|
class TCPHandler(socketserver.StreamRequestHandler):
|
||||||
def readString(self):
|
def readString(self):
|
||||||
|
@ -53,8 +55,11 @@ class TCPHandler(socketserver.StreamRequestHandler):
|
||||||
content = message.split()
|
content = message.split()
|
||||||
command = content[0].lower()
|
command = content[0].lower()
|
||||||
try:
|
try:
|
||||||
if command in ("hi"):
|
if command == "hi":
|
||||||
return "HI: Kumi Status v0.8.15 (KSP)"
|
try:
|
||||||
|
return "HI: Kumi Status v0.8.15 (KSP) at %s" % setuptools.getSetting("Server", "host") or socket.gethostname()
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
elif command in ("heartbeat", "hb", "ping"):
|
elif command in ("heartbeat", "hb", "ping"):
|
||||||
return "OK: Still here? Wow."
|
return "OK: Still here? Wow."
|
||||||
elif command in ("stat", "status"):
|
elif command in ("stat", "status"):
|
||||||
|
@ -85,7 +90,15 @@ class TCPHandler(socketserver.StreamRequestHandler):
|
||||||
print(e)
|
print(e)
|
||||||
return "ER: Could not verify SSL certificate on %s:%i. Is the server down?" % (content[1], int(content[2]))
|
return "ER: Could not verify SSL certificate on %s:%i. Is the server down?" % (content[1], int(content[2]))
|
||||||
elif command == "port":
|
elif command == "port":
|
||||||
return "UA: Not currently implemented."
|
host = encodings.idna.ToASCII(str(content[1])).decode("UTF-8")
|
||||||
|
port = int(content[2])
|
||||||
|
if listIncluded(host, PORT):
|
||||||
|
if porttools.isPortOpen(host, port):
|
||||||
|
return "OK: Port %i is open on %s." % (port, content[1])
|
||||||
|
else:
|
||||||
|
return "ER: Port %i is not open on %s." % (port, content[1])
|
||||||
|
else:
|
||||||
|
return "NM: %s is not being monitored!" % content[1]
|
||||||
elif command in ("req", "request"):
|
elif command in ("req", "request"):
|
||||||
return "NI: Requesting monitoring is not yet implemented."
|
return "NI: Requesting monitoring is not yet implemented."
|
||||||
elif command == "help":
|
elif command == "help":
|
||||||
|
|
Loading…
Reference in a new issue