|
|
|
@ -1,5 +1,5 @@ |
|
|
|
from glob import escape |
|
|
|
from flask import Flask,request,json |
|
|
|
from flask import Flask,request,jsonify |
|
|
|
from markupsafe import escape |
|
|
|
|
|
|
|
import os |
|
|
|
@ -26,15 +26,17 @@ def ping(name): |
|
|
|
if apiToken == token: |
|
|
|
response = os.system("ping -c 1 " + name) |
|
|
|
if response == 0: |
|
|
|
instruc = ' up' |
|
|
|
instruc = 'up' |
|
|
|
else: |
|
|
|
instruc = ' down' |
|
|
|
instruc = 'down' |
|
|
|
else: |
|
|
|
instruc = ' wrong token' |
|
|
|
ip_addr = request.remote_addr |
|
|
|
out = '%s - Unauthorized from IP: %s' %(now, ip_addr) |
|
|
|
print (out) |
|
|
|
return now + instruc |
|
|
|
return jsonify( |
|
|
|
time = now, |
|
|
|
status = instruc) |
|
|
|
|
|
|
|
@app.route('/http/<name>/') |
|
|
|
def http(name): |
|
|
|
@ -45,19 +47,21 @@ def http(name): |
|
|
|
try: |
|
|
|
r = requests.get(address) |
|
|
|
status = r.status_code |
|
|
|
status_string = ' %s' %str(status) |
|
|
|
status_string = '%s' %str(status) |
|
|
|
except requests.exceptions.Timeout: |
|
|
|
status_string = " Timeout" |
|
|
|
status_string = "Timeout" |
|
|
|
except requests.exceptions.TooManyRedirects: |
|
|
|
status_string = " TooManyRedirects" |
|
|
|
status_string = "TooManyRedirects" |
|
|
|
except requests.exceptions.RequestException as e: |
|
|
|
status_string = ' %s' %str(e) |
|
|
|
status_string = '%s' %str(e) |
|
|
|
else: |
|
|
|
status_string = ' wrong token' |
|
|
|
status_string = 'wrong token' |
|
|
|
ip_addr = request.remote_addr |
|
|
|
out = '%s - Unauthorized from IP: %s' %(now, ip_addr) |
|
|
|
print (out) |
|
|
|
return now + status_string |
|
|
|
return jsonify ( |
|
|
|
time = now, |
|
|
|
status = status_string) |
|
|
|
|
|
|
|
@app.route('/https/<name>/') |
|
|
|
def https(name): |
|
|
|
@ -68,19 +72,22 @@ def https(name): |
|
|
|
try: |
|
|
|
r = requests.get(address) |
|
|
|
status = r.status_code |
|
|
|
status_string = ' %s' %str(status) |
|
|
|
status_string = '%s' %str(status) |
|
|
|
except requests.exceptions.Timeout: |
|
|
|
status_string = " Timeout" |
|
|
|
status_string = "Timeout" |
|
|
|
except requests.exceptions.TooManyRedirects: |
|
|
|
status_string = " TooManyRedirects" |
|
|
|
status_string = "TooManyRedirects" |
|
|
|
except requests.exceptions.RequestException as e: |
|
|
|
status_string = ' %s' %str(e) |
|
|
|
status_string = '%s' %str(e) |
|
|
|
else: |
|
|
|
status_string = ' wrong token' |
|
|
|
ip_addr = request.remote_addr |
|
|
|
out = '%s - Unauthorized from IP: %s' %(now, ip_addr) |
|
|
|
print (out) |
|
|
|
return now + status_string |
|
|
|
return jsonify ( |
|
|
|
time = now, |
|
|
|
status = status_string) |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
app.run(debug=True) |