-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
37 lines (32 loc) · 1.26 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import requests as req
import socket
import logging
import time
logging.basicConfig(
filename='status_site.log',
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
def get_site(url_para_ip):
try:
return socket.gethostbyname(url_para_ip)
except socket.gaierror as e:
logging.error(f'Erro ao obter o IP do site {e}')
def checarStatus(url, url_para_ip):
try:
response = req.get(url)
if response.status_code == 200:
logging.info(f"Site funcionando OK! Status: {response.status_code}, IP: {get_site(url_para_ip)}")
print(f"Site funcionando OK! Status: {response.status_code}, IP: {get_site(url_para_ip)}")
else:
logging.warning(f"Site caiu (NOK)! Status code: {response.status_code}, IP: {get_site(url_para_ip)}")
print(f"Site caiu (NOK)! Status code: {response.status_code}, IP: {get_site(url_para_ip)}")
except req.exceptions.RequestException as e:
logging.error(f"Exception ao enviar requisição. {e}")
def monitoramento(url, url_para_ip):
while True:
checarStatus(url, url_para_ip)
time.sleep(3)
if __name__ == '__main__':
link = input('digite o link do site http://')
monitoramento(f'https://{link}', link)