-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
53 lines (38 loc) · 1.63 KB
/
app.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from flask import Flask, jsonify, request
from pingExecutor import ping
app = Flask(__name__)
def errorResponse(message, error):
print(f'{message}: {error}')
return jsonify({'Status': 'Error', 'Message': message, 'Error': f'{error}'}), 403
@app.route('/Ping/<address>', methods=['GET'])
def Ping(address: str):
try:
interval = float(request.args.get('interval', 1.0))
size = int(request.args.get('size', 0))
ttl = int(request.args.get('ttl', 0))
ping.Ping(address, interval, size, ttl)
return jsonify({'Status': 'Success', 'Message': 'Successfully executed ping'})
except Exception as error:
return errorResponse('Error executing ping', error)
@app.route('/Close', methods=['GET'])
def Close():
try:
ping.Close()
return jsonify({'Status': 'Success', 'Message': 'Successfully closed ping'})
except Exception as error:
return errorResponse('Error closing ping', error)
@app.route('/LastJsonResult', methods=['GET'])
def LastJsonResult():
try:
return jsonify({'Status': 'Success', 'Message': 'Successfully retrieved last json result',
'Result': ping.LastJsonResult()})
except Exception as error:
return errorResponse('Error retrieving last json result', error)
@app.route('/StartDateTime', methods=['GET'])
def StartDateTime():
return jsonify({'Status': 'Success', 'Message': f'Start date time {ping.StartDateTime()}'})
@app.route('/IsRunning', methods=['GET'])
def IsRunning():
return jsonify({'Status': 'Success', 'Message': f'ping is running: {ping.IsRunning()}'})
if __name__ == '__main__':
app.run()