2016-03-16 15:49:56 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
2017-03-19 20:11:16 +00:00
|
|
|
import logging, datetime, setuptools, ssltools, twitools
|
2016-03-16 15:49:56 +00:00
|
|
|
|
2017-03-19 20:11:16 +00:00
|
|
|
def getExpiry(host, port, notify, two = twitools.twObject()):
|
|
|
|
pbefore = int(setuptools.getSetting("SSL", "pbefore"))
|
|
|
|
pafter = int(setuptools.getSetting("SSL", "pafter"))
|
2016-03-16 15:49:56 +00:00
|
|
|
|
2016-04-28 21:05:40 +00:00
|
|
|
try:
|
2017-03-19 20:11:16 +00:00
|
|
|
expiry = ssltools.getRemoteExpiry(host, port)
|
2016-04-28 21:05:40 +00:00
|
|
|
diff = expiry - datetime.datetime.now()
|
|
|
|
if diff < datetime.timedelta(days=pbefore):
|
|
|
|
if expiry > datetime.datetime.now():
|
2017-03-19 20:11:16 +00:00
|
|
|
two.tweet("@%s %s certificate expiring soon (%s). Please renew." % (notify, host, expiry))
|
2016-04-28 21:05:40 +00:00
|
|
|
elif expiry + datetime.timedelta(days=pafter) < datetime.datetime.now():
|
2017-03-19 20:11:16 +00:00
|
|
|
two.tweet("@%s %s certificate has expired! (%s) Please renew ASAP!" % (notify, host, expiry))
|
2016-04-28 21:05:40 +00:00
|
|
|
except:
|
2017-03-19 20:11:16 +00:00
|
|
|
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])
|