Commit 8fcfe72f authored by Klaus-Uwe Mitterer's avatar Klaus-Uwe Mitterer

Some refactoring

parent c2a0db14
......@@ -2,19 +2,19 @@
import time, setuptools, porttools, twitools
hosts = setuptools.getListSetting("Ports", "hosts")
retry = int(setuptools.getSetting("Ports", "retry"))
two = twitools.twObject()
def check(host, port, recipient):
def check(host, port, recipient, two = twitools.twObject()):
if not porttools.isPortOpen(host, port):
time.sleep(retry)
if not porttools.isPortOpen(host, port):
two.tweet("@%s Port %s is not open on host %s!" % (recipient, port, host))
for h in hosts:
try:
for p in h[1]:
check(h[0], p, h[2])
except TypeError:
check(*h)
if __name__ == "__main__":
hosts = setuptools.getListSetting("Ports", "hosts")
retry = int(setuptools.getSetting("Ports", "retry"))
for h in hosts:
try:
for p in h[1]:
check(h[0], p, h[2])
except TypeError:
check(*h)
......@@ -2,10 +2,7 @@
import time, setuptools, httptools, twitools
sites = setuptools.getListSetting("HTTP", "sites")
two = twitools.twObject()
def check(site, recipient):
def check(site, recipient, two = twitools.twObject()):
status = httptools.getStatus(site)
if not status == 200:
if status == None:
......@@ -13,5 +10,8 @@ def check(site, recipient):
else:
two.tweet("@%s Site %s returns status code %s!" % (recipient, site, status))
for s in sites:
check(s[0], s[1])
if __name__ == "__main__":
sites = setuptools.getListSetting("HTTP", "sites")
for s in sites:
check(s[0], s[1])
#!/usr/bin/python3
import datetime, setuptools, ssltools, twitools
import logging, datetime, setuptools, ssltools, twitools
hosts = setuptools.getListSetting("SSL", "hosts")
pbefore = int(setuptools.getSetting("SSL", "pbefore"))
pafter = int(setuptools.getSetting("SSL", "pafter"))
two = twitools.twObject()
def getExpiry(host, port, notify, two = twitools.twObject()):
pbefore = int(setuptools.getSetting("SSL", "pbefore"))
pafter = int(setuptools.getSetting("SSL", "pafter"))
for h in hosts:
try:
expiry = ssltools.getRemoteExpiry(h[0], h[1])
expiry = ssltools.getRemoteExpiry(host, port)
diff = expiry - datetime.datetime.now()
if diff < datetime.timedelta(days=pbefore):
if expiry > datetime.datetime.now():
two.tweet("@%s %s certificate expiring soon (%s). Please renew." % (h[2], h[0], expiry))
two.tweet("@%s %s certificate expiring soon (%s). Please renew." % (notify, host, expiry))
elif expiry + datetime.timedelta(days=pafter) < datetime.datetime.now():
two.tweet("@%s %s certificate has expired! (%s) Please renew ASAP!" % (h[2], h[0], expiry))
two.tweet("@%s %s certificate has expired! (%s) Please renew ASAP!" % (notify, host, expiry))
except:
two.tweet("@%s Could not verify SSL certificate on %s:%i. Is the server down?" % (h[2], h[0], h[1]))
logging.exception("Could not verify certificate.")
two.tweet("@%s Could not verify SSL certificate on %s:%i. Is the server down?" % (notify, host, port))
if __name__ == "__main__":
hosts = setuptools.getListSetting("SSL", "hosts")
for h in hosts:
getExpiry(h[0], h[1], h[2])
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