|
|
@ -4,6 +4,7 @@ from markupsafe import escape |
|
|
|
|
|
|
|
|
import os |
|
|
import os |
|
|
import requests |
|
|
import requests |
|
|
|
|
|
import datetime |
|
|
|
|
|
|
|
|
app = Flask(__name__) |
|
|
app = Flask(__name__) |
|
|
|
|
|
|
|
|
@ -18,18 +19,44 @@ def hello(): |
|
|
|
|
|
|
|
|
@app.route('/ping/<name>') |
|
|
@app.route('/ping/<name>') |
|
|
def ping(name): |
|
|
def ping(name): |
|
|
personal = f'pinging, {name}' |
|
|
|
|
|
|
|
|
|
|
|
response = os.system("ping -c 1 " + name) |
|
|
response = os.system("ping -c 1 " + name) |
|
|
|
|
|
now = str(datetime.datetime.now()) |
|
|
if response == 0: |
|
|
if response == 0: |
|
|
instruc = ' is up!' |
|
|
instruc = ' up' |
|
|
address = 'http://%s' %name |
|
|
else: |
|
|
|
|
|
instruc = ' down' |
|
|
|
|
|
return now + instruc |
|
|
|
|
|
|
|
|
|
|
|
@app.route('/http/<name>') |
|
|
|
|
|
def http(name): |
|
|
|
|
|
address = 'http://%s' %name |
|
|
|
|
|
now = str(datetime.datetime.now()) |
|
|
|
|
|
try: |
|
|
r = requests.get(address) |
|
|
r = requests.get(address) |
|
|
status = r.status_code |
|
|
status = r.status_code |
|
|
status_string = str(status) |
|
|
status_string = ' %s' %str(status) |
|
|
else: |
|
|
except requests.exceptions.Timeout: |
|
|
instruc = ' is down!' |
|
|
status_string = " Timeout" |
|
|
return personal + instruc + status_string |
|
|
except requests.exceptions.TooManyRedirects: |
|
|
|
|
|
status_string = " TooManyRedirects" |
|
|
|
|
|
except requests.exceptions.RequestException as e: |
|
|
|
|
|
status_string = ' %s' %str(e) |
|
|
|
|
|
return now + status_string |
|
|
|
|
|
|
|
|
|
|
|
@app.route('/https/<name>') |
|
|
|
|
|
def https(name): |
|
|
|
|
|
address = 'https://%s' %name |
|
|
|
|
|
try: |
|
|
|
|
|
r = requests.get(address) |
|
|
|
|
|
status = r.status_code |
|
|
|
|
|
status_string = ' %s' %str(status) |
|
|
|
|
|
except requests.exceptions.Timeout: |
|
|
|
|
|
status_string = " Timeout" |
|
|
|
|
|
except requests.exceptions.TooManyRedirects: |
|
|
|
|
|
status_string = " TooManyRedirects" |
|
|
|
|
|
except requests.exceptions.RequestException as e: |
|
|
|
|
|
status_string = ' %s' %str(e) |
|
|
|
|
|
return now + status_string |
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
if __name__ == '__main__': |
|
|
app.run(debug=True) |
|
|
app.run(debug=True) |