Some refactoring
This commit is contained in:
parent
c2a0db14bb
commit
8fcfe72f5b
3 changed files with 32 additions and 27 deletions
22
portsopen.py
22
portsopen.py
|
@ -2,19 +2,19 @@
|
||||||
|
|
||||||
import time, setuptools, porttools, twitools
|
import time, setuptools, porttools, twitools
|
||||||
|
|
||||||
hosts = setuptools.getListSetting("Ports", "hosts")
|
def check(host, port, recipient, two = twitools.twObject()):
|
||||||
retry = int(setuptools.getSetting("Ports", "retry"))
|
|
||||||
two = twitools.twObject()
|
|
||||||
|
|
||||||
def check(host, port, recipient):
|
|
||||||
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))
|
||||||
|
|
||||||
for h in hosts:
|
if __name__ == "__main__":
|
||||||
try:
|
hosts = setuptools.getListSetting("Ports", "hosts")
|
||||||
for p in h[1]:
|
retry = int(setuptools.getSetting("Ports", "retry"))
|
||||||
check(h[0], p, h[2])
|
|
||||||
except TypeError:
|
for h in hosts:
|
||||||
check(*h)
|
try:
|
||||||
|
for p in h[1]:
|
||||||
|
check(h[0], p, h[2])
|
||||||
|
except TypeError:
|
||||||
|
check(*h)
|
||||||
|
|
12
siteup.py
12
siteup.py
|
@ -2,10 +2,7 @@
|
||||||
|
|
||||||
import time, setuptools, httptools, twitools
|
import time, setuptools, httptools, twitools
|
||||||
|
|
||||||
sites = setuptools.getListSetting("HTTP", "sites")
|
def check(site, recipient, two = twitools.twObject()):
|
||||||
two = twitools.twObject()
|
|
||||||
|
|
||||||
def check(site, recipient):
|
|
||||||
status = httptools.getStatus(site)
|
status = httptools.getStatus(site)
|
||||||
if not status == 200:
|
if not status == 200:
|
||||||
if status == None:
|
if status == None:
|
||||||
|
@ -13,5 +10,8 @@ def check(site, recipient):
|
||||||
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))
|
||||||
|
|
||||||
for s in sites:
|
if __name__ == "__main__":
|
||||||
check(s[0], s[1])
|
sites = setuptools.getListSetting("HTTP", "sites")
|
||||||
|
|
||||||
|
for s in sites:
|
||||||
|
check(s[0], s[1])
|
||||||
|
|
25
sslexpiry.py
25
sslexpiry.py
|
@ -1,20 +1,25 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import datetime, setuptools, ssltools, twitools
|
import logging, datetime, setuptools, ssltools, twitools
|
||||||
|
|
||||||
hosts = setuptools.getListSetting("SSL", "hosts")
|
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"))
|
||||||
two = twitools.twObject()
|
|
||||||
|
|
||||||
for h in hosts:
|
|
||||||
try:
|
try:
|
||||||
expiry = ssltools.getRemoteExpiry(h[0], h[1])
|
expiry = ssltools.getRemoteExpiry(host, port)
|
||||||
diff = expiry - datetime.datetime.now()
|
diff = expiry - datetime.datetime.now()
|
||||||
if diff < datetime.timedelta(days=pbefore):
|
if diff < datetime.timedelta(days=pbefore):
|
||||||
if expiry > datetime.datetime.now():
|
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():
|
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:
|
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])
|
||||||
|
|
Loading…
Reference in a new issue