Hieronder een klein simpel script om even snel een aantal urls te testen op stabiliteit:
from urllib.request import urlopen
import time
def write_log(m):
f = open('error.txt', 'a')
f.write(time.strftime("%Y-%m-%d %H:%M:%S ", time.gmtime()))
f.write(m + '\n')
f.close()
urls = ['http://hostname1:8080/pagina.php', 'http://hostname2:8180/pagina.php']
for i in range(86400): #86400 = 1 dag
print(i)
for url in urls:
#print("url = " + url)
try:
with urlopen(url) as response:
healty = 0
for line in response:
line = line.decode('utf-8') # Decoding the binary data to text.
#print(line)
if('status: healthy' in line):
#print("Found")
healty = 1
if(healty == 0):
write_log(url + " Not healty")
except:
write_log('ERROR in opening ' + url )
time.sleep(1)