Commit 3e333a95 authored by Klaus-Uwe Mitterer's avatar Klaus-Uwe Mitterer

Implement port monitoring, improve punycode handling, other minor improvements

parent eae9d81f
Pipeline #184 skipped
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
STDOUT = 1
......@@ -34,10 +34,12 @@ def logger(message, prio=syslog.LOG_INFO, sink=logging):
logger(message, prio, logging)
def listIncluded(host, section):
for i in setuptools.getListSetting("SSL" if section == SSL else "Ports", "hosts"):
if encodings.idna.ToASCII(i[0].lower()).decode("UTF-8") == encodings.idna.ToASCII(host.lower()).decode("UTF-8"):
return True
return False
if not setuptools.getListSetting("Server", "ignorelist"):
for i in setuptools.getListSetting("SSL" if section == SSL else "Ports", "hosts"):
if encodings.idna.ToASCII(i[0].lower()).decode("UTF-8") == encodings.idna.ToASCII(host.lower()).decode("UTF-8"):
return True
return False
return True
class TCPHandler(socketserver.StreamRequestHandler):
def readString(self):
......@@ -53,8 +55,11 @@ class TCPHandler(socketserver.StreamRequestHandler):
content = message.split()
command = content[0].lower()
try:
if command in ("hi"):
return "HI: Kumi Status v0.8.15 (KSP)"
if command == "hi":
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"):
return "OK: Still here? Wow."
elif command in ("stat", "status"):
......@@ -85,7 +90,15 @@ class TCPHandler(socketserver.StreamRequestHandler):
print(e)
return "ER: Could not verify SSL certificate on %s:%i. Is the server down?" % (content[1], int(content[2]))
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"):
return "NI: Requesting monitoring is not yet implemented."
elif command == "help":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment