Created
October 11, 2019 17:07
-
-
Save leo-isso/66b355c833ed8278a20e1662e81f1cdb to your computer and use it in GitHub Desktop.
Check Telavita's Servers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import sys | |
from time import sleep | |
from datetime import datetime | |
servers = [ | |
{ | |
"value": 0, | |
"prefix": "", | |
"name": "Production" | |
}, | |
{ | |
"value": 1, | |
"prefix": "hmg", | |
"name": "Staging" | |
}, | |
{ | |
"value": 2, | |
"prefix": "dev", | |
"name": "Development" | |
}, | |
{ | |
"value": 3, | |
"prefix": "sup", | |
"name": "Support" | |
}, | |
{ | |
"value": 4, | |
"prefix": "trn", | |
"name": "Training" | |
}, | |
] | |
environments = [ | |
{ | |
"value": 0, | |
"sulfix": "/app/psicologia-online/encontre-seu-psicologo/", | |
"name": "Application" | |
}, | |
{ | |
"value": 1, | |
"sulfix": "/", | |
"name": "Institutional" | |
}, | |
] | |
def server_selection(): | |
print("\n### Select the server you want to check:\n") | |
for server in servers: | |
print("{} - {}".format(server["value"], server["name"])) | |
try: | |
selected_server_index = int(input("\n> ")) | |
except: | |
print("\n### Invalid server!!!") | |
return server_selection() | |
if selected_server_index > (len(servers) - 1) or selected_server_index < 0: | |
print("\n### Invalid server!!!") | |
return server_selection() | |
else: | |
return servers[selected_server_index] | |
def environment_selection(): | |
print("\n### Select the environment you want to check:\n") | |
for environment in environments: | |
print("{} - {}".format(environment["value"], environment["name"])) | |
try: | |
selected_environment_index = int(input("\n> ")) | |
except: | |
print("\n### Invalid environment!!!") | |
return environment_selection() | |
if selected_environment_index > (len(environments) - 1) or selected_environment_index < 0: | |
print("\n### Invalid environment!!!") | |
return environment_selection() | |
else: | |
return environments[selected_environment_index] | |
def create_url(selected_server, selected_environment): | |
prefix = selected_server["prefix"] | |
sulfix = selected_environment["sulfix"] | |
if selected_server["prefix"] != "": | |
prefix = "{}.".format(prefix) | |
return "https://{}telavita.com.br{}".format(prefix, sulfix) | |
def check_server(url): | |
start_time = datetime.now() | |
start_time_string = start_time.strftime("%d/%m/%Y, %H:%M:%S") | |
resolved = False | |
print("\nProcess started at: {}".format(start_time_string)) | |
while not resolved: | |
print("\nTrying to reach: {}".format(url)) | |
response = requests.get(url) | |
print("\nGotcha!") | |
if response.ok: | |
end_time = datetime.now() | |
end_time_string = end_time.strftime("%d/%m/%Y, %H:%M:%S") | |
total_time = end_time - start_time | |
print(response.status_code, "Site is up!\n\nProcess ended at: {}\n\nTotal time: {}".format(end_time_string, total_time)) | |
resolved = True | |
else: | |
print(response.status_code, "Site is down!") | |
sleep(10) | |
if __name__ == "__main__": | |
selected_server = server_selection() | |
selected_environment = environment_selection() | |
request_url = create_url(selected_server, selected_environment) | |
check_server(request_url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment