Skip to content

Commit

Permalink
Actually implemented individual panel fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
gmemstr committed Mar 13, 2017
1 parent 577352d commit 2f9b38e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion App.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

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

elif config.Get("enable_slackbot") is True:
Expand Down
4 changes: 2 additions & 2 deletions src/SQL.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def CheckConnection(self):
except:
self.db = MySQLdb.connect(user=self.sqluser,passwd=self.sqlpass,db="platypus")

def Get(self,filter=None,arg=None):
def Get(self,filter=None,panel=None):
self.CheckConnection()
if filter == None:
self.c.execute("SELECT * FROM " + self.sqltable)
return self.c.fetchall()
if filter == "one":
self.c.execute("SELECT * FROM " + self.sqltable + " WHERE id=%s", (arg))
self.c.execute("SELECT * FROM " + self.sqltable + " WHERE id="+panel)
return self.c.fetchall()
else:
raise ValueError('Invalid filter for SQL query')
Expand Down
5 changes: 5 additions & 0 deletions src/Scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def Fetch(self,panel=None):
str(result['memory']),
str(result['disk']))

else:
panel = sql.Get("one", panel)[0]
print(panel)
return self.Check(panel)

def Check(self, panel):
id = panel[0]

Expand Down
7 changes: 5 additions & 2 deletions src/Webserver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Python modules
from flask import Flask, render_template, abort, g, request, redirect, url_for, jsonify
import requests
from multiprocessing.pool import ThreadPool

# Custom imports
from src.Login import LoginManager, User
Expand Down Expand Up @@ -28,9 +29,11 @@ def ReturnRawStats():

@app.route('/fetch/<panel>')
def MiddlemanStat(panel):
pool = ThreadPool(processes=1)

# Acts as a middleman for CORS reasons
res = scan.Fetch(panel)
return jsonify(res)
async_result = pool.apply_async(scan.Fetch, (panel,))
return jsonify(async_result.get())

@app.route("/login", methods=["GET", "POST"])
def LoginRoute():
Expand Down

0 comments on commit 2f9b38e

Please sign in to comment.