From 454ede49789757dc130aa5eb6ff85cd88fd7f7c6 Mon Sep 17 00:00:00 2001 From: gmemstr Date: Tue, 28 Feb 2017 11:59:25 -0800 Subject: [PATCH] Fixed bug regarding servers not properly being marked as offline.. --- App.py | 4 ++-- src/Cache.py | 10 +++++----- src/Statuses.py | 12 ++++++------ src/static/platypus.js | 3 ++- src/templates/index.html | 2 +- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/App.py b/App.py index 7e9b91d..b17aa1a 100644 --- a/App.py +++ b/App.py @@ -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: diff --git a/src/Cache.py b/src/Cache.py index 2261861..87c39d9 100644 --- a/src/Cache.py +++ b/src/Cache.py @@ -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)) diff --git a/src/Statuses.py b/src/Statuses.py index da18f99..5bb5459 100644 --- a/src/Statuses.py +++ b/src/Statuses.py @@ -20,10 +20,10 @@ 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) @@ -31,7 +31,7 @@ def Scan(self, 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 @@ -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, diff --git a/src/static/platypus.js b/src/static/platypus.js index 45ec78a..d3a58fa 100644 --- a/src/static/platypus.js +++ b/src/static/platypus.js @@ -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'] + "OFFLINE"; row.cells[2].innerHTML = "0%"; row.cells[3].innerHTML = "0%"; diff --git a/src/templates/index.html b/src/templates/index.html index 7470aea..278a589 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -32,7 +32,7 @@

GGServers Server Status

Disk Free {% for s in stats %} - {{ s[1] }} {% if s[4] != 1 %}OFFLINE{% endif %} + {{ s[1] }} {% if s[4] == 0 %}OFFLINE{% endif %} {{ s[3] }} {{ s[6] }}% {{ s[7] }}%