-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
upService.py
168 lines (134 loc) · 4.83 KB
/
upService.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
from flask import Flask, jsonify, request
import subprocess
import uptime
import json
import db
import reporting_db as rdb
import updatecron as uc
app = Flask(__name__)
@app.route('/', methods=['GET'])
def homePage():
return "There's nothing here. Find your own way!"
# Manually updates all statuses and updates the database
@app.route('/updateStatus', methods=['GET'])
def getJson():
data = json.loads(uptime.sites())
return data
@app.route('/getCurrentStatus', methods=['GET'])
def getCurrentStatus():
page = request.args.get('page',default=1,type=int)
limit = request.args.get('limit',default=10,type=int)
data = rdb.getCurrentStatus(page, limit)
return jsonify(data)
@app.route('/getSites', methods=['GET'])
def getSites():
page = request.args.get('page',default=1,type=int)
limit = request.args.get('limit',default=100,type=int)
data = rdb.getSites(page, limit)
return jsonify(data)
@app.route('/addSite', methods=['POST'])
def addSite():
siteName = request.form['siteName']
url = request.form['url']
status = 0 # default is site is offline until checked
active = 1 # default active
email = request.form['email']
visible = 1 # default visible
try:
data = db.addSite(siteName, url, status, active, email, visible)
# obj = {"status": "successfully added site"}
# return json.dumps(obj)
return jsonify(data)
except:
obj = {"status": "Failed to add site"}
return json.dumps(obj)
@app.route('/updateSite', methods=['PUT'])
def updateSite():
id = request.form['id']
siteName = request.form['siteName']
url = request.form['url']
# status = request.form['status'] # should only be updated by site check
active = request.form['active']
email = request.form['email']
visible = 1 # default visible
try:
data = db.updateSite(id, siteName, url, active, email, visible)
return jsonify(data)
except:
obj = {"status": "Failed to update site"}
return json.dumps(obj)
@app.route('/getActivity', methods=['GET'])
def getActivity():
page = request.args.get('page',default=1,type=int)
limit = request.args.get('limit',default=25,type=int)
data = rdb.getActivity(page, limit)
return jsonify(data)
@app.route('/getOutages', methods=['GET'])
def getOutages():
page = request.args.get('page',default=1,type=int)
limit = request.args.get('limit',default=25,type=int)
data = rdb.getOutages(page, limit)
return jsonify(data)
@app.route('/getDowntimeCounts', methods=['GET'])
def getDowntimeCounts():
page = request.args.get('page',default=1,type=int)
limit = request.args.get('limit',default=25,type=int)
data = rdb.getDowntimeCounts(page, limit)
return jsonify(data)
@app.route('/getCron', methods=['GET'])
def getCron():
data = rdb.getCronSettings()
return jsonify(data)
@app.route('/getNotifications', methods=['GET'])
def getNotifications():
page = request.args.get('page', default=1, type=int)
limit = request.args.get('limit', default=25, type=int)
data = rdb.getNotifications(page, limit)
return jsonify(data)
# define green LED Override via POST
@app.route('/overrideGreen', methods=['PUT'])
def overrideGreen():
status = request.form['status']
try:
db.changeLedStatus('green', status)
obj = {"status": "successfully changed LED status"}
return json.dumps(obj)
except:
obj = {"status": "Failed to change LED status"}
return json.dumps(obj)
@app.route('/getLeds', methods=['GET'])
def getLedStatus():
data = rdb.getLedStatus()
return jsonify(data)
@app.route('/changeLedActive', methods=['PUT'])
def changeLedActive():
color = request.form['color']
active = request.form['active']
print(color, active)
data = db.overrideLedActive(color, active)
return jsonify(data)
# This will only update the checkSites cron since it only accepts the interval at which sites are
# checked unlike the others
@app.route('/checkFrequency', methods=['PUT'])
def checkFrequency():
# comment = request.form['comment']
name = request.form['cronName']
val = request.form['cronVal']
enabled = request.form['enabled']
uc.updateCheckFrequency('checkSites', val, enabled)
data = db.updateCron('checkSites', name, val, enabled)
return jsonify(data)
@app.route('/updateCron', methods=['POST', 'PUT'])
def updateCron():
if request.method == 'PUT':
comment = request.form['comment']
name = request.form['cronName']
val = request.form['cronVal']
enabled = request.form['enabled']
uc.updateCron(comment, val, enabled)
data = db.updateCron(comment, name, val, enabled)
return jsonify(data)
elif request.method == 'POST':
return 'POST Method not set'
else:
return 'Only accepts PUT or POST'