Add closed port notifier

This commit is contained in:
Klaus-Uwe Mitterer 2016-03-30 18:15:30 +02:00
parent 44fb3f9f10
commit 79ac25dd4d
2 changed files with 23 additions and 0 deletions

13
portsopen.py Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/python3
import time, setuptools, porttools, twitools
hosts = setuptools.getListSetting("Ports", "hosts")
retry = int(setuptools.getSetting("Ports", "retry"))
two = twitools.twObject()
for h in hosts:
if not porttools.isPortOpen(h[0], h[1]):
time.sleep(retry)
if not porttools.isPortOpen(h[0], h[1]):
two.tweet("@%s Port %s is not open on host %s!" % (h[2], h[1], h[0]))

10
porttools/__init__.py Normal file
View File

@ -0,0 +1,10 @@
import socket
def isPortOpen(host, port):
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
sock.connect((host, port))
except:
return False
return True