kumistatus/portsopen.py
Klaus-Uwe Mitterer 8fcfe72f5b Some refactoring
2017-03-19 21:11:16 +01:00

20 lines
546 B
Python
Executable file

#!/usr/bin/python3
import time, setuptools, porttools, twitools
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))
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)