Browse Source

added http and https

master
Domagoj Zecevic 3 years ago
parent
commit
3a997382fe
  1. 43
      ping_engine.py

43
ping_engine.py

@ -4,6 +4,7 @@ from markupsafe import escape
import os
import requests
import datetime
app = Flask(__name__)
@ -18,18 +19,44 @@ def hello():
@app.route('/ping/<name>')
def ping(name):
personal = f'pinging, {name}'
response = os.system("ping -c 1 " + name)
now = str(datetime.datetime.now())
if response == 0:
instruc = ' is up!'
address = 'http://%s' %name
instruc = ' up'
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)
status = r.status_code
status_string = str(status)
else:
instruc = ' is down!'
return personal + instruc + status_string
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
@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__':
app.run(debug=True)
Loading…
Cancel
Save