From 44fb3f9f1054ad905c7b653f820e0ae439f54f2a Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Wed, 30 Mar 2016 18:11:49 +0200 Subject: [PATCH] Allow sslexpiry to be directly executed through an import --- sslexpiry.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/sslexpiry.py b/sslexpiry.py index c6a6360..220f986 100755 --- a/sslexpiry.py +++ b/sslexpiry.py @@ -2,17 +2,16 @@ import datetime, setuptools, ssltools, twitools -if __name__ == "__main__": - hosts = setuptools.getListSetting("SSL", "hosts") - pbefore = int(setuptools.getSetting("SSL", "pbefore")) - pafter = int(setuptools.getSetting("SSL", "pafter")) - two = twitools.twObject() +hosts = setuptools.getListSetting("SSL", "hosts") +pbefore = int(setuptools.getSetting("SSL", "pbefore")) +pafter = int(setuptools.getSetting("SSL", "pafter")) +two = twitools.twObject() - for h in hosts: - 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)) +for h in hosts: + 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))