kumistatus/sslexpiry.py
Klaus-Uwe Mitterer dd9e60fb9a portsopen.py: Take list of ports per host to test
sslexpiry.py: Handle unreachable port
2016-04-28 23:05:40 +02:00

20 lines
829 B
Python
Executable file

#!/usr/bin/python3
import datetime, setuptools, ssltools, twitools
hosts = setuptools.getListSetting("SSL", "hosts")
pbefore = int(setuptools.getSetting("SSL", "pbefore"))
pafter = int(setuptools.getSetting("SSL", "pafter"))
two = twitools.twObject()
for h in hosts:
try:
expiry = ssltools.getRemoteExpiry(h[0], h[1])
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))
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))
except:
two.tweet("@%s Could not verify SSL certificate on %s:%i. Is the server down?" % (h[2], h[0], h[1]))