Replace portsopen.py, siteup.py, sksup.py and sslexpiry.py by twitter.py
This commit is contained in:
parent
feac1be289
commit
d82ec2a995
8 changed files with 74 additions and 23 deletions
|
@ -1,8 +1,11 @@
|
||||||
import urllib.request, urllib.error
|
import urllib.request, urllib.error
|
||||||
|
|
||||||
def getStatus(url):
|
def getStatus(url):
|
||||||
|
if not "://" in url:
|
||||||
|
url = "http://" + url
|
||||||
|
req = urllib.request.Request(url, data=None, headers={'User-Agent': 'KumiStatus/0.8.15 (+https://kumig.it/kumitterer/kumistatus)'})
|
||||||
try:
|
try:
|
||||||
return urllib.request.urlopen(url).getcode()
|
return urllib.request.urlopen(req).getcode()
|
||||||
except urllib.error.HTTPError as e:
|
except urllib.error.HTTPError as e:
|
||||||
return e.code
|
return e.code
|
||||||
except urllib.error.URLError:
|
except urllib.error.URLError:
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
import time, setuptools, httptools, twitools
|
import time, setuptools, httptools, twitools
|
||||||
|
|
||||||
|
arg = "w"
|
||||||
|
|
||||||
def check(site, recipient, two = twitools.twObject()):
|
def check(site, recipient, two = twitools.twObject()):
|
||||||
status = httptools.getStatus(site)
|
status = httptools.getStatus(site)
|
||||||
if not status == 200:
|
if not status == 200:
|
||||||
|
@ -10,7 +12,7 @@ def check(site, recipient, two = twitools.twObject()):
|
||||||
else:
|
else:
|
||||||
two.tweet("@%s Site %s returns status code %s!" % (recipient, site, status))
|
two.tweet("@%s Site %s returns status code %s!" % (recipient, site, status))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def run():
|
||||||
sites = setuptools.getListSetting("HTTP", "sites")
|
sites = setuptools.getListSetting("HTTP", "sites")
|
||||||
|
|
||||||
for s in sites:
|
for s in sites:
|
|
@ -2,13 +2,15 @@
|
||||||
|
|
||||||
import time, setuptools, porttools, twitools
|
import time, setuptools, porttools, twitools
|
||||||
|
|
||||||
|
arg = "p"
|
||||||
|
|
||||||
def check(host, port, recipient, two = twitools.twObject()):
|
def check(host, port, recipient, two = twitools.twObject()):
|
||||||
if not porttools.isPortOpen(host, port):
|
if not porttools.isPortOpen(host, port):
|
||||||
time.sleep(retry)
|
time.sleep(retry)
|
||||||
if not porttools.isPortOpen(host, port):
|
if not porttools.isPortOpen(host, port):
|
||||||
two.tweet("@%s Port %s is not open on host %s!" % (recipient, port, host))
|
two.tweet("@%s Port %s is not open on host %s!" % (recipient, port, host))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def run():
|
||||||
hosts = setuptools.getListSetting("Ports", "hosts")
|
hosts = setuptools.getListSetting("Ports", "hosts")
|
||||||
retry = int(setuptools.getSetting("Ports", "retry"))
|
retry = int(setuptools.getSetting("Ports", "retry"))
|
||||||
|
|
|
@ -3,15 +3,15 @@
|
||||||
import setuptools, servertools, socketserver, syslog, threading
|
import setuptools, servertools, socketserver, syslog, threading
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
socketserver.TCPServer.allow_reuse_address = True
|
servertools.TCPServer.allow_reuse_address = True
|
||||||
bind = setuptools.getSetting("Server", "bind") or "0.0.0.0"
|
bind = setuptools.getSetting("Server", "bind") or "0.0.0.0"
|
||||||
port = int(setuptools.getSetting("Server", "port")) or 5747
|
port = int(setuptools.getSetting("Server", "port")) or 5747
|
||||||
try:
|
try:
|
||||||
server = servertools.TCPServer((bind, port), servertools.TCPHandler)
|
server = servertools.TCPServer((bind, port), servertools.TCPHandler)
|
||||||
except:
|
except:
|
||||||
servertools.logger("Unable to bind on %s:%i. Make sure the port is not in use or use a different port." % (bind, port))
|
print("Unable to bind on %s:%i. Make sure the port is not in use or use a different port." % (bind, port))
|
||||||
servertools.shutdown(status=1)
|
servertools.shutdown(status=1)
|
||||||
servertools.logger("Kumi Status server running on %s:%i." % (bind, port))
|
print("Kumi Status server running on %s:%i." % (bind, port))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
thread = threading.Thread(target=server.serve_forever(), daemon=True)
|
thread = threading.Thread(target=server.serve_forever(), daemon=True)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import datetime
|
import datetime
|
||||||
import encodings.idna
|
import encodings.idna
|
||||||
|
import httptools
|
||||||
import os
|
import os
|
||||||
import porttools
|
import porttools
|
||||||
import setuptools
|
import setuptools
|
||||||
|
@ -19,6 +20,7 @@ SILENT = 9 # Quiet mode
|
||||||
SSL = 0
|
SSL = 0
|
||||||
PORT = 1
|
PORT = 1
|
||||||
SKS = 2
|
SKS = 2
|
||||||
|
HTTP = 3
|
||||||
|
|
||||||
logging = STDOUT
|
logging = STDOUT
|
||||||
|
|
||||||
|
@ -47,7 +49,7 @@ def logger(message, prio=syslog.LOG_INFO, sink=logging):
|
||||||
|
|
||||||
def listIncluded(host, section):
|
def listIncluded(host, section):
|
||||||
if not setuptools.getListSetting("Server", "ignorelist"):
|
if not setuptools.getListSetting("Server", "ignorelist"):
|
||||||
for i in setuptools.getListSetting("SSL" if section == SSL else "Ports" if section == PORT else "SKS", "hosts"):
|
for i in setuptools.getListSetting("HTTP" if section == HTTP else "SSL" if section == SSL else "Ports" if section == PORT else "SKS", "sites" if section == HTTP else "hosts"):
|
||||||
if encodings.idna.ToASCII(i[0].lower()).decode("UTF-8") == encodings.idna.ToASCII(host.lower()).decode("UTF-8"):
|
if encodings.idna.ToASCII(i[0].lower()).decode("UTF-8") == encodings.idna.ToASCII(host.lower()).decode("UTF-8"):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
@ -120,7 +122,7 @@ class TCPHandler(socketserver.StreamRequestHandler):
|
||||||
host = encodings.idna.ToASCII(str(content[1])).decode("UTF-8")
|
host = encodings.idna.ToASCII(str(content[1])).decode("UTF-8")
|
||||||
if listIncluded(host, SKS):
|
if listIncluded(host, SKS):
|
||||||
if skstools.getStatus(host):
|
if skstools.getStatus(host):
|
||||||
return "OK: SKS is running on %s and included in the pools." % content[1]
|
return "OK: SKS is running on %s and included in the pools." % content[0]
|
||||||
else:
|
else:
|
||||||
return "ER: The SKS keyserver at %s is not included in the pools." % content[1]
|
return "ER: The SKS keyserver at %s is not included in the pools." % content[1]
|
||||||
else:
|
else:
|
||||||
|
@ -132,6 +134,19 @@ class TCPHandler(socketserver.StreamRequestHandler):
|
||||||
elif command == "help":
|
elif command == "help":
|
||||||
return "UA: Not currently implemented."
|
return "UA: Not currently implemented."
|
||||||
|
|
||||||
|
elif command in ("http", "web"):
|
||||||
|
site = encodings.idna.ToASCII(str(content[1])).decode("UTF-8")
|
||||||
|
if listIncluded(site, HTTP):
|
||||||
|
status = httptools.getStatus(site)
|
||||||
|
if status == 200:
|
||||||
|
return "OK: Site %s seems to be working fine." % content[1]
|
||||||
|
elif status == None:
|
||||||
|
return "ER: Site %s looks down from here!" % content[1]
|
||||||
|
else:
|
||||||
|
return "ER: Site %s returns status code %s!" % (content[1], status)
|
||||||
|
else:
|
||||||
|
return "NM: %s is not being monitored!" % content[1]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return "IM: Unknown command %s." % command
|
return "IM: Unknown command %s." % command
|
||||||
|
|
||||||
|
@ -141,6 +156,7 @@ class TCPHandler(socketserver.StreamRequestHandler):
|
||||||
return "IM: Invalid values passed to %s. Try HELP %s." % (command, command)
|
return "IM: Invalid values passed to %s. Try HELP %s." % (command, command)
|
||||||
|
|
||||||
def handle(self):
|
def handle(self):
|
||||||
|
try:
|
||||||
remote = self.client_address[0] + ":" + str(self.client_address[1])
|
remote = self.client_address[0] + ":" + str(self.client_address[1])
|
||||||
logger("New connection from %s." % remote, syslog.LOG_INFO)
|
logger("New connection from %s." % remote, syslog.LOG_INFO)
|
||||||
self.sendString(self.worker("hi"))
|
self.sendString(self.worker("hi"))
|
||||||
|
@ -150,10 +166,15 @@ class TCPHandler(socketserver.StreamRequestHandler):
|
||||||
logger("Connection from %s closed." % remote, syslog.LOG_DEBUG)
|
logger("Connection from %s closed." % remote, syslog.LOG_DEBUG)
|
||||||
break
|
break
|
||||||
logger("%s said: %s" % (remote, message))
|
logger("%s said: %s" % (remote, message))
|
||||||
|
try:
|
||||||
response = self.worker(message)
|
response = self.worker(message)
|
||||||
|
except:
|
||||||
|
response = "EM: Something went terribly wrong. Sorry about that."
|
||||||
if response:
|
if response:
|
||||||
self.sendString(response)
|
self.sendString(response)
|
||||||
logger("Sent to %s: %s" % (remote, response), syslog.LOG_DEBUG)
|
logger("Sent to %s: %s" % (remote, response), syslog.LOG_DEBUG)
|
||||||
|
except Exception as e:
|
||||||
|
logger(e, syslog.LOG_CRIT)
|
||||||
|
|
||||||
class TCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
|
class TCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -2,11 +2,13 @@
|
||||||
|
|
||||||
import time, setuptools, skstools, twitools
|
import time, setuptools, skstools, twitools
|
||||||
|
|
||||||
|
arg = "k"
|
||||||
|
|
||||||
def check(server, recipient, two = twitools.twObject()):
|
def check(server, recipient, two = twitools.twObject()):
|
||||||
if skstools.getStatus(server) == False:
|
if skstools.getStatus(server) == False:
|
||||||
two.tweet("@%s Something seems to be wrong with the %s keyserver!" % (recipient, site))
|
two.tweet("@%s Something seems to be wrong with the %s keyserver!" % (recipient, site))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def run():
|
||||||
servers = setuptools.getListSetting("SKS", "servers")
|
servers = setuptools.getListSetting("SKS", "servers")
|
||||||
for s in servers:
|
for s in servers:
|
||||||
check(s[0], s[1])
|
check(s[0], s[1])
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
import logging, datetime, setuptools, ssltools, twitools
|
import logging, datetime, setuptools, ssltools, twitools
|
||||||
|
|
||||||
|
arg = "s"
|
||||||
|
|
||||||
def getExpiry(host, port, notify, two = twitools.twObject()):
|
def getExpiry(host, port, notify, two = twitools.twObject()):
|
||||||
pbefore = int(setuptools.getSetting("SSL", "pbefore"))
|
pbefore = int(setuptools.getSetting("SSL", "pbefore"))
|
||||||
pafter = int(setuptools.getSetting("SSL", "pafter"))
|
pafter = int(setuptools.getSetting("SSL", "pafter"))
|
||||||
|
@ -18,7 +20,7 @@ def getExpiry(host, port, notify, two = twitools.twObject()):
|
||||||
logging.exception("Could not verify certificate.")
|
logging.exception("Could not verify certificate.")
|
||||||
two.tweet("@%s Could not verify SSL certificate on %s:%i. Is the server down?" % (notify, host, port))
|
two.tweet("@%s Could not verify SSL certificate on %s:%i. Is the server down?" % (notify, host, port))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def run():
|
||||||
hosts = setuptools.getListSetting("SSL", "hosts")
|
hosts = setuptools.getListSetting("SSL", "hosts")
|
||||||
|
|
||||||
for h in hosts:
|
for h in hosts:
|
19
twitter.py
Executable file
19
twitter.py
Executable file
|
@ -0,0 +1,19 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import argparse, importlib, setuptools
|
||||||
|
|
||||||
|
p = argparse.ArgumentParser(description="Kumi Status Twitter Helpers")
|
||||||
|
|
||||||
|
for mod in setuptools.getListSetting("KumiStatus", "modules"):
|
||||||
|
try:
|
||||||
|
name = mod + ".twitter"
|
||||||
|
temp = importlib.import_module(name)
|
||||||
|
p.add_argument("--" + mod, "-" + temp.arg, action="store_const", const=temp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
args = p.parse_args()
|
||||||
|
|
||||||
|
for arg in vars(args):
|
||||||
|
if vars(args)[arg]:
|
||||||
|
vars(args)[arg].run()
|
Loading…
Reference in a new issue