Skip to content

Commit

Permalink
Fixed bug regarding servers not properly being marked as offline..
Browse files Browse the repository at this point in the history
  • Loading branch information
gmemstr committed Feb 28, 2017
1 parent ed0b9c3 commit 454ede4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions App.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@

elif config.Get("enable_webserver") is True:
print("Webserver starting up")
# scnp = Process(target=scn.Loop()).start()
scnp = Process(target=scn.Loop()).start()
wsp = Process(target=ws.Run()).start()


elif config.Get("enable_slackbot") is True:
print("Slackbot enabled")
# scnp = Process(target=scn.Loop()).start()
scnp = Process(target=scn.Loop()).start()
sbp = Process(target=sb.Loop()).start()

else:
Expand Down
10 changes: 5 additions & 5 deletions src/Cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@ def Get(self,server="all",offline="all"):
self.c.execute("SELECT * FROM "+self.sqltable+" WHERE id="+str(server))
return self.c.fetchall()

def SetStatus(self,panel,status,cpu,memory,disk):
def SetStatus(self,panel,online,cpu,memory,disk):
self.c.execute("SELECT * FROM "+self.sqltable+" WHERE id="+str(panel))
udtime = self.c.fetchone()[5]
if udtime is None:
udtime = 0

if udtime >= 0 and status == "offline":
if udtime >= 0 and online == False:
# Server just went offline
self.c.execute("UPDATE "+self.sqltable+" SET online=false, udtime=0 WHERE id="+str(panel))
elif udtime >= 0 and status == "online":
elif udtime >= 0 and online == True:
# Increment uptime (online)
self.c.execute("UPDATE "+self.sqltable+" SET udtime="+
str(udtime + self.config.Get("scan_interval"))+", cpu="+
cpu + ", memory="+memory+",disk="+disk+" WHERE id="+str(panel))
elif udtime <= 0 and status == "offline":
elif udtime <= 0 and online == False:
# Deincrement uptime (offline)
self.c.execute("UPDATE "+self.sqltable+" SET udtime="+
str(udtime - self.config.Get("scan_interval"))+
" WHERE id="+str(panel))
elif udtime <= 0 and status == "online":
elif udtime <= 0 and online == True:
# Set reset uptime and set as online
self.c.execute("UPDATE "+self.sqltable+" SET online=true, udtime=0, cpu="+
cpu + ", memory="+memory+",disk="+disk+" WHERE id="+str(panel))
Expand Down
12 changes: 6 additions & 6 deletions src/Statuses.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ def Fetch(self,panel="all"):
return self.Scan(s[0])

def Scan(self, panel):
print(panel)
# print(panel)
id = panel[0]
res = {}
offline = ""
online = False
# Iterate through the list of servers
try:
# TODO: Except if stats are not found but page loads (non-404)
# Attempts to fetch platy stats from panel.
request = requests.get("http://" + panel[2] + config.Get("stats_path"),
timeout=config.Get("scan_timeout"))
print(panel[0], "online")
offline = "online"
online = True
if request.status_code == 404:
cpu = 0 # CPU
memory = 0 # RAM
Expand All @@ -46,12 +46,12 @@ def Scan(self, panel):
cpu=0
disk=0
memory=0
status = "offline"
online = False

handler.SetStatus(id,offline,str(cpu),str(memory),str(disk))
handler.SetStatus(id,online,str(cpu),str(memory),str(disk))

res[panel[0]] = {"name": panel[1],
"online": panel[4],
"online": online,
"location": panel[3],
"cpu": cpu,
"memory":memory,
Expand Down
3 changes: 2 additions & 1 deletion src/static/platypus.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ function setRow(text,panel,row){
//console.log(text);
//console.log(panel)
res = JSON.parse(text);
if (res[panel]['online'] == 0 || res[panel]['online'] == null) {
console.log(res[panel]['online']);
if (res[panel]['online'] == false || res[panel]['online'] == null) {
row.cells[0].innerHTML = res[panel]['name'] + "<strong>OFFLINE</strong>";
row.cells[2].innerHTML = "0%";
row.cells[3].innerHTML = "0%";
Expand Down
2 changes: 1 addition & 1 deletion src/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h1>GGServers Server Status</h1>
<th>Disk Free</th>
{% for s in stats %}
<tr id="{{ s[0] }}">
<td>{{ s[1] }} {% if s[4] != 1 %}<strong>OFFLINE</strong>{% endif %}</td>
<td>{{ s[1] }} {% if s[4] == 0 %}<strong>OFFLINE</strong>{% endif %}</td>
<td>{{ s[3] }}</td>
<td>{{ s[6] }}%</td>
<td>{{ s[7] }}%</td>
Expand Down

0 comments on commit 454ede4

Please sign in to comment.