|
|
|
@ -13,28 +13,33 @@
|
|
|
|
|
- Add socketio, so that each section of the dashboard updates independently
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from flask import Flask, session, request, redirect, Response
|
|
|
|
|
from flask import Flask, session, request, redirect, Response, stream_with_context
|
|
|
|
|
from flask.templating import render_template
|
|
|
|
|
import requests
|
|
|
|
|
from flask_session import Session
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
import os
|
|
|
|
|
import json
|
|
|
|
|
import re
|
|
|
|
|
import monitor
|
|
|
|
|
# import monitor
|
|
|
|
|
import uuid
|
|
|
|
|
|
|
|
|
|
from utils.register import Register
|
|
|
|
|
from utils.transport import *
|
|
|
|
|
from utils.agents import actor
|
|
|
|
|
# from utils.register import Register
|
|
|
|
|
|
|
|
|
|
from utils.charting import *
|
|
|
|
|
from utils.transport import *
|
|
|
|
|
from utils.ml.analytics import *
|
|
|
|
|
# from utils.agents import actor
|
|
|
|
|
from threading import Thread
|
|
|
|
|
#from utils.ml import ML,AnomalyDetection,AnalyzeAnomaly
|
|
|
|
|
import utils.params as SYS_ARGS
|
|
|
|
|
# from utils.agents.actor import *
|
|
|
|
|
import utils.agents.actor as actor
|
|
|
|
|
# import utils.agents.actor as actor
|
|
|
|
|
import pickle
|
|
|
|
|
from utils.agents.manager import Manager
|
|
|
|
|
# from utils.agents.manager import Manager
|
|
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
app.config['SECRET_KEY'] = '!h8-[0v8]247-4-360'
|
|
|
|
@ -49,6 +54,8 @@ f.close()
|
|
|
|
|
#
|
|
|
|
|
#from threading import Thread, RLock
|
|
|
|
|
p = CONFIG['store']['args']
|
|
|
|
|
global SYS_STORE
|
|
|
|
|
SYS_STORE = CONFIG['store']
|
|
|
|
|
class_read = CONFIG['store']['class']['read']
|
|
|
|
|
class_write= CONFIG['store']['class']['write']
|
|
|
|
|
factory = DataSourceFactory()
|
|
|
|
@ -80,43 +87,324 @@ def home():
|
|
|
|
|
print (e)
|
|
|
|
|
return render_template('dashboard.html',context=context,title=title,app_names=apps)
|
|
|
|
|
|
|
|
|
|
@app.route('/register',methods=['POST'])
|
|
|
|
|
def update_plan(uid,plan,auid=None):
|
|
|
|
|
url = ":protocol://:host/subscribe/smart-top"
|
|
|
|
|
url = url.replace(":protocol",CONFIG['protocol']).replace(":host",CONFIG['api'])
|
|
|
|
|
try:
|
|
|
|
|
args = {"type":SYS_STORE['class']['read'],"args":SYS_STORE['args']}
|
|
|
|
|
# reader = factory.instance(**args)
|
|
|
|
|
|
|
|
|
|
headers = {"uid":uid}
|
|
|
|
|
if plan :
|
|
|
|
|
headers['pid'] = plan
|
|
|
|
|
if auid is not None:
|
|
|
|
|
headers["auid"]=json.dumps([auid])
|
|
|
|
|
r = requests.post(url,headers=headers)
|
|
|
|
|
|
|
|
|
|
return json.loads( r.text)
|
|
|
|
|
|
|
|
|
|
except Exception,e:
|
|
|
|
|
print e
|
|
|
|
|
return None
|
|
|
|
|
def set_userdata(key):
|
|
|
|
|
"""
|
|
|
|
|
This function will pull an authenticated user data into the session
|
|
|
|
|
@param key user key
|
|
|
|
|
"""
|
|
|
|
|
args = {"type":SYS_STORE['class']['read'],"args":SYS_STORE['args']}
|
|
|
|
|
reader = factory.instance(**args)
|
|
|
|
|
views = []
|
|
|
|
|
for id in views :
|
|
|
|
|
r = reader.view(id,key=key)
|
|
|
|
|
session[id] = r
|
|
|
|
|
pass
|
|
|
|
|
@app.route('/1/register',methods=['POST'])
|
|
|
|
|
def register() :
|
|
|
|
|
"""
|
|
|
|
|
This function registers a user and provides
|
|
|
|
|
This function registers a user and provides, if we already have a
|
|
|
|
|
if the customer/user already exists a new key will be generated for her with an unchanged subscription
|
|
|
|
|
"""
|
|
|
|
|
global p
|
|
|
|
|
|
|
|
|
|
body = request.get_json(silent=True)
|
|
|
|
|
uid = body['uid']
|
|
|
|
|
default_plan = CONFIG['plan']
|
|
|
|
|
if 'plan' not in body :
|
|
|
|
|
plan = CONFIG['plan']
|
|
|
|
|
|
|
|
|
|
# session['info'] = body
|
|
|
|
|
uid = body['user']['uid']
|
|
|
|
|
args = {"type":SYS_STORE['class']['read'],"args":SYS_STORE['args']}
|
|
|
|
|
reader = factory.instance(**args)
|
|
|
|
|
key = None
|
|
|
|
|
|
|
|
|
|
if 'key' not in session :
|
|
|
|
|
key = reader.view('users/uid_map',key=uid)
|
|
|
|
|
# if key :
|
|
|
|
|
# session['key'] = key
|
|
|
|
|
if key :
|
|
|
|
|
plans = reader.view('users/active_plan',key=str(key))
|
|
|
|
|
else:
|
|
|
|
|
plan = body['plan']
|
|
|
|
|
handler = Register(write=class_write,read=class_read,store=p,default=default_plan,uid=uid)
|
|
|
|
|
r = handler.register(plan)
|
|
|
|
|
session['key'] = r['key']
|
|
|
|
|
plans = None
|
|
|
|
|
plan = body['plan'] if 'plan' in body else CONFIG['default_plan']#-- default plan
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plans = update_plan(uid,plan)
|
|
|
|
|
key = reader.view('users/uid_map',key=uid)
|
|
|
|
|
|
|
|
|
|
if 'key' not in session :
|
|
|
|
|
args = {"type":SYS_STORE['class']['write'],"args":SYS_STORE['args']}
|
|
|
|
|
args['args']['uid'] = key
|
|
|
|
|
|
|
|
|
|
writer = factory.instance(**args)
|
|
|
|
|
auid = str(uuid.uuid5(uuid.NAMESPACE_DNS,str(key)))
|
|
|
|
|
writer.write(label='hash',data=auid)
|
|
|
|
|
session['key'] = key
|
|
|
|
|
|
|
|
|
|
if plans :
|
|
|
|
|
session['user-plan'] = plans
|
|
|
|
|
return ('',204)
|
|
|
|
|
return "",403
|
|
|
|
|
@app.route('/1/store/<id>',methods=['POST'])
|
|
|
|
|
def store_data(id) :
|
|
|
|
|
"""
|
|
|
|
|
This function stores data into the session coming from a client/dashboard
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
body = request.get_json(silent=True)
|
|
|
|
|
session[id] = body
|
|
|
|
|
|
|
|
|
|
return ('',204)
|
|
|
|
|
@app.route('/1/apps',methods=['GET'])
|
|
|
|
|
def apps() :
|
|
|
|
|
|
|
|
|
|
if 'key' in session :
|
|
|
|
|
args = {"type":SYS_STORE['class']['read'],"args":SYS_STORE['args']}
|
|
|
|
|
args['args']['uid'] = session['key']
|
|
|
|
|
factory = DataSourceFactory()
|
|
|
|
|
reader = factory.instance(**args)
|
|
|
|
|
logs = reader.read()['apps']
|
|
|
|
|
logs = logs[len(logs)-1]
|
|
|
|
|
|
|
|
|
|
WEB_ARGS = {}
|
|
|
|
|
WEB_ARGS['grid'] = {"fields":[{"name":"name","title":"Name","headercss":"small bold"},{"name":"mem","title":"Memory","headercss":"small bold","type":"number"},{"name":"cpu","title":"CPU","headercss":"small bold","type":"number"},{"name":"started","title":"Started", "headercss":"small bold","width":"65px"},{"name":"status","title":"Status","headercss":"small bold"}]}
|
|
|
|
|
WEB_ARGS['grid']['data'] = logs
|
|
|
|
|
WEB_ARGS['context'] = SYS_ARGS.PARAMS['context']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return render_template('dashboard/apps/data-grid.html',**WEB_ARGS)
|
|
|
|
|
else:
|
|
|
|
|
return render_template('error.html')
|
|
|
|
|
@app.route("/1/plan",methods=['GET'])
|
|
|
|
|
def active_plan():
|
|
|
|
|
args = {"type":SYS_STORE['class']['read'],"args":SYS_STORE['args']}
|
|
|
|
|
factory = DataSourceFactory()
|
|
|
|
|
reader = factory.instance(**args)
|
|
|
|
|
if 'key' in session :
|
|
|
|
|
return (json.dumps(plans),200)
|
|
|
|
|
else:
|
|
|
|
|
return ('',403)
|
|
|
|
|
@app.route("/1/board",methods=["GET"])
|
|
|
|
|
def get_board():
|
|
|
|
|
session['key'] = 'cus_D2x3ItYNfWjSY3'
|
|
|
|
|
|
|
|
|
|
if 'key' in session :
|
|
|
|
|
args = {"type":SYS_STORE['class']['read'],"args":SYS_STORE['args']}
|
|
|
|
|
args['args']['uid'] = session['key']
|
|
|
|
|
args['context'] = SYS_ARGS.PARAMS['context']
|
|
|
|
|
# if 'nodes' not in session :
|
|
|
|
|
handler = didact(config=args,key=session['key'])
|
|
|
|
|
args['nodes'] = handler.get('nodes')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for id in handler.cache :
|
|
|
|
|
session[id] = handler.cache[id]
|
|
|
|
|
|
|
|
|
|
args['app_logs'] = session['apps.logs']
|
|
|
|
|
args['app_summary'] = session['apps.summary']
|
|
|
|
|
args['app_grid'] = session['apps.grid']
|
|
|
|
|
args['folders_summary'] = session['folders.summary']
|
|
|
|
|
|
|
|
|
|
args['folder_size'] = session['folders.max_size']
|
|
|
|
|
|
|
|
|
|
return render_template("dashboard/apps/summary.html",**args)
|
|
|
|
|
else:
|
|
|
|
|
return ('',403)
|
|
|
|
|
@app.route("/1/clients",methods=['GET'])
|
|
|
|
|
def get_clients():
|
|
|
|
|
|
|
|
|
|
if 'key' in session :
|
|
|
|
|
if request.method == 'GET' :
|
|
|
|
|
args = {"type":SYS_STORE['class']['read'],"args":SYS_STORE['args']}
|
|
|
|
|
args['args']['uid'] = session['key']
|
|
|
|
|
reader = factory.instance(**args)
|
|
|
|
|
document = reader.read()
|
|
|
|
|
lclients = document['clients'] if 'clients' in document else []
|
|
|
|
|
args = {"clients":lclients}
|
|
|
|
|
args['context'] = SYS_ARGS.PARAMS['context'] if 'context' in SYS_ARGS.PARAMS else ''
|
|
|
|
|
args['grid'] = {"fields":[{"name":"key","width":"45%","css":"small","headercss":"small bold"},{"name":"node","title":"Alias","headercss":"small bold","css":"small","type":"text"},{"name":"apps.length","title":"Apps","css":"small","headercss":"small bold","type":"number","width":"65px"},{"name":"folders.length","title":"Folders","css":"small","headercss":"small bold","type":"number","width":"65px"}]}
|
|
|
|
|
args['grid']['data'] = lclients
|
|
|
|
|
args['hash'] = document['hash']
|
|
|
|
|
args['features'] = {"clients":1}
|
|
|
|
|
args['context'] = SYS_ARGS.PARAMS['context']
|
|
|
|
|
if 'user-info' in session :
|
|
|
|
|
args['uid'] = session['user-info']['uid']
|
|
|
|
|
if 'user-plan' in session :
|
|
|
|
|
features = json.loads(session['user-plan'][0]['metadata']['features'])
|
|
|
|
|
# features = json.loads(session['user-plan']['metadata']['features'])
|
|
|
|
|
args['client_count'] = features['clients']
|
|
|
|
|
return render_template('dashboard/client-keys.html',**args)
|
|
|
|
|
# elif request.method == 'POST' :
|
|
|
|
|
# clients = request.get_json(silent=True)
|
|
|
|
|
# #
|
|
|
|
|
# # We can NOT have uncontrolled writes
|
|
|
|
|
# #
|
|
|
|
|
# # N = session['user-plan'][0]['metadata']['features']
|
|
|
|
|
# # clients = client[:N] if len(clients) > N else clients
|
|
|
|
|
|
|
|
|
|
# args = {"type":SYS_STORE['class']['write'],"args":SYS_STORE['args']}
|
|
|
|
|
# args['args']['uid'] = session['key']
|
|
|
|
|
# writer = factory.instance(**args)
|
|
|
|
|
# # writer.set({"clients":clients})
|
|
|
|
|
# writer.set(clients=clients)
|
|
|
|
|
# return ('',200)
|
|
|
|
|
|
|
|
|
|
# pass
|
|
|
|
|
else:
|
|
|
|
|
return ('',403)
|
|
|
|
|
@app.route('/1/clients',methods=['POST'])
|
|
|
|
|
def set_clients() :
|
|
|
|
|
if 'key' in session :
|
|
|
|
|
clients = request.get_json(silent=True)
|
|
|
|
|
#
|
|
|
|
|
# We should try to run a thread that loads the data for the user so when she requests it it is ready
|
|
|
|
|
# @TODO:
|
|
|
|
|
# We can NOT have uncontrolled writes
|
|
|
|
|
#
|
|
|
|
|
try:
|
|
|
|
|
session['plan'] = r
|
|
|
|
|
key = r['key']
|
|
|
|
|
args = json.loads(json.dumps(p))
|
|
|
|
|
args['dbname'] = r['name']
|
|
|
|
|
gReader = factory.instance(type=class_read,args=args)
|
|
|
|
|
session['logs'] = {}
|
|
|
|
|
for id in ['app_status','log_size','emails'] :
|
|
|
|
|
session['logs'][id] = gReader.view('summary/'+id.strip(),key=key)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print (e)
|
|
|
|
|
# N = session['user-plan'][0]['metadata']['features']
|
|
|
|
|
# clients = client[:N] if len(clients) > N else clients
|
|
|
|
|
|
|
|
|
|
args = {"type":SYS_STORE['class']['write'],"args":SYS_STORE['args']}
|
|
|
|
|
args['args']['uid'] = session['key']
|
|
|
|
|
writer = factory.instance(**args)
|
|
|
|
|
# writer.set({"clients":clients})
|
|
|
|
|
writer.set(clients=clients)
|
|
|
|
|
return ('',200)
|
|
|
|
|
|
|
|
|
|
@app.route("/1/emails",methods=['GET'])
|
|
|
|
|
def get_emails():
|
|
|
|
|
"""
|
|
|
|
|
This function retrieves a list of emails for a given user
|
|
|
|
|
@session.has('key')
|
|
|
|
|
"""
|
|
|
|
|
if 'key' in session:
|
|
|
|
|
user_key = session['key']
|
|
|
|
|
if request.method == 'GET' :
|
|
|
|
|
args = {"type":SYS_STORE['class']['read'],"args":SYS_STORE['args']}
|
|
|
|
|
args['args']['uid'] = session['key']
|
|
|
|
|
reader = factory.instance(**args)
|
|
|
|
|
document = reader.read()
|
|
|
|
|
emails = document['emails'] if 'emails' in document else []
|
|
|
|
|
|
|
|
|
|
args = {"emails":[{"email":value} for value in emails]}
|
|
|
|
|
args['context'] = SYS_ARGS.PARAMS['context'] if 'context' in SYS_ARGS.PARAMS else ''
|
|
|
|
|
args['uid'] = str(emails[0])
|
|
|
|
|
return render_template('dashboard/user-emails.html',**args)
|
|
|
|
|
else:
|
|
|
|
|
return ('',403)
|
|
|
|
|
@app.route("/1/emails",methods=['POST'])
|
|
|
|
|
def set_emails():
|
|
|
|
|
"""
|
|
|
|
|
This function is designed to add an email to the list of contacts
|
|
|
|
|
@header content-type application/json
|
|
|
|
|
@body [email_o,email_i,...]
|
|
|
|
|
@session.has('key')
|
|
|
|
|
"""
|
|
|
|
|
if 'key' in session:
|
|
|
|
|
user_key = session['key']
|
|
|
|
|
emails = request.get_json(silent=True)
|
|
|
|
|
args = {"type":SYS_STORE['class']['write'],"args":SYS_STORE['args']}
|
|
|
|
|
args['args']['uid'] = session['key']
|
|
|
|
|
writer = factory.instance(**args)
|
|
|
|
|
writer.set(emails=list(set(emails)))
|
|
|
|
|
return ('',200)
|
|
|
|
|
else:
|
|
|
|
|
return ('',403)
|
|
|
|
|
@app.route("/1/client/login",methods=['POST'])
|
|
|
|
|
def client_login():
|
|
|
|
|
"""
|
|
|
|
|
This function establishes a connection and session with the calling code
|
|
|
|
|
and will return the the features provided the keys supplied are found
|
|
|
|
|
:request application/json {id:<value>,key:<value>}
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
return json.dumps(r)
|
|
|
|
|
key = request.headers['id']+'@'+request.headers['key']
|
|
|
|
|
|
|
|
|
|
if 'client' not in session :
|
|
|
|
|
args = {"type":SYS_STORE['class']['read'],"args":SYS_STORE['args']}
|
|
|
|
|
# args['args']['uid'] = session['key']
|
|
|
|
|
reader = factory.instance(**args)
|
|
|
|
|
features = reader.view('clients/config',key=key)
|
|
|
|
|
|
|
|
|
|
if features :
|
|
|
|
|
session['client'] = {key:features}
|
|
|
|
|
uid = reader.view('clients/uid_map',key=key)
|
|
|
|
|
session['key'] = uid
|
|
|
|
|
else:
|
|
|
|
|
return "",403
|
|
|
|
|
else:
|
|
|
|
|
features = session['client'][key]
|
|
|
|
|
return json.dumps(features),200
|
|
|
|
|
@app.route("/1/client/log",methods=['POST'])
|
|
|
|
|
def client_log():
|
|
|
|
|
|
|
|
|
|
if 'client' in session and 'key' in session:
|
|
|
|
|
key = request.headers['id']+'@'+request.headers['key']
|
|
|
|
|
context = request.headers['context']
|
|
|
|
|
body = request.get_json(silent=True)
|
|
|
|
|
now = datetime.now()
|
|
|
|
|
date = {"month":now.month,"day":now.day,"year":now.year,"hour":now.hour,"minute":now.minute,"second":now.second,"long":time.mktime(now.timetuple())}
|
|
|
|
|
|
|
|
|
|
args = dict({"type":SYS_STORE['class']['write'],"args":SYS_STORE['args']})
|
|
|
|
|
args['args']['uid'] = session['key']
|
|
|
|
|
row = {"node":request.headers['id'],"date":date,"log":body}
|
|
|
|
|
#
|
|
|
|
|
# We should make sure that we don't have to archive the data
|
|
|
|
|
writer = factory.instance(**args)
|
|
|
|
|
writer.write (label=context,row=row)
|
|
|
|
|
return "",200
|
|
|
|
|
else :
|
|
|
|
|
return "",403
|
|
|
|
|
@app.route("/1/log",methods=['POST'])
|
|
|
|
|
def log():
|
|
|
|
|
key = request.headers['key']
|
|
|
|
|
id = request.headers['id']
|
|
|
|
|
label = request.headers['label'] if 'label' in request.headers else None
|
|
|
|
|
row = request.get_json(silent=True)
|
|
|
|
|
if row and label :
|
|
|
|
|
args = {"type":SYS_STORE['class']['read'],"args":SYS_STORE['args']}
|
|
|
|
|
reader = factory.instance(**args)
|
|
|
|
|
r = reader.view('users/clients',key=key)
|
|
|
|
|
|
|
|
|
|
if r:
|
|
|
|
|
args = {"type":SYS_STORE['class']['write'],"args":SYS_STORE['args']}
|
|
|
|
|
writer = factory.instance(**args)
|
|
|
|
|
writer.write(label=label, row=row)
|
|
|
|
|
return ('1',200)
|
|
|
|
|
else:
|
|
|
|
|
return ('0',403) #-- not authorized (sorry)
|
|
|
|
|
else :
|
|
|
|
|
return ('',400) #-- malformed request i.e missing stuff
|
|
|
|
|
|
|
|
|
|
@app.route("/1/notify/<key>",methods=["POST"])
|
|
|
|
|
def notify(key):
|
|
|
|
|
"""
|
|
|
|
|
This function is designed to notify parties via email, the notification is a report of sorts
|
|
|
|
|
@TODO: Create HTML/PDF and email it to a variety of parties.
|
|
|
|
|
"""
|
|
|
|
|
#
|
|
|
|
|
# TODO: Does the user have permission and is her plan still active.
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
@app.route('/1/get/nodes')
|
|
|
|
|
def get_nodes():
|
|
|
|
|
"""
|
|
|
|
|
@deprecate
|
|
|
|
|
This function returns the labels of applications for every node registered
|
|
|
|
|
@param None
|
|
|
|
|
"""
|
|
|
|
@ -133,6 +421,7 @@ def get_nodes():
|
|
|
|
|
@app.route('/1/get/apps')
|
|
|
|
|
def get_apps():
|
|
|
|
|
"""
|
|
|
|
|
@deprecate
|
|
|
|
|
This function returns the applications for a given node
|
|
|
|
|
@param node identifier e.g: apps@zulu.org
|
|
|
|
|
"""
|
|
|
|
@ -147,8 +436,77 @@ def get_apps():
|
|
|
|
|
print (e)
|
|
|
|
|
return json.dumps(r)
|
|
|
|
|
|
|
|
|
|
def get_logs(key,view_name):
|
|
|
|
|
"""
|
|
|
|
|
This function will execute a view provided a key and a name for the view
|
|
|
|
|
The calling code will insure the preconditions are met i.e session ...
|
|
|
|
|
@param key user's key
|
|
|
|
|
@param view_name name of the view to execute
|
|
|
|
|
"""
|
|
|
|
|
store = CONFIG['store']['args']
|
|
|
|
|
args = str(json.dumps(store))
|
|
|
|
|
args = json.loads(args)
|
|
|
|
|
args['dbname'] = plan['name']
|
|
|
|
|
args['uid'] = key
|
|
|
|
|
|
|
|
|
|
session['store'] = args
|
|
|
|
|
session['key'] = key
|
|
|
|
|
|
|
|
|
|
gReader = factory.instance(type=class_read,args=args)
|
|
|
|
|
return gReader.view(view_name)
|
|
|
|
|
@app.route('/1/get/logs/apps/<id>')
|
|
|
|
|
def app_logs(id):
|
|
|
|
|
"""
|
|
|
|
|
This function returns application log information for a given user
|
|
|
|
|
@param id <usage|usage-details|status|status-details|emails|log-size|nodes>
|
|
|
|
|
"""
|
|
|
|
|
x = {'usage':'app_resources','status-details':'app_status_details','usage-details':'app_resource_usage_details','status':'app_status',"nodes":"nodes"}
|
|
|
|
|
r = "{}"
|
|
|
|
|
#
|
|
|
|
|
# let's make sure we have an active session otherwise, nothing is to be done
|
|
|
|
|
#
|
|
|
|
|
key = session['key'] if 'key' in session else None
|
|
|
|
|
if key is None and 'key' in request.headers:
|
|
|
|
|
key = request.headers['key']
|
|
|
|
|
status=403
|
|
|
|
|
plan = session['plan'] if 'plan' in session else None
|
|
|
|
|
if id in x and key and plan:
|
|
|
|
|
status = 200
|
|
|
|
|
try:
|
|
|
|
|
view_name='summary/'+x[id].strip()
|
|
|
|
|
r = get_logs(key,view_name)
|
|
|
|
|
except Exception,e:
|
|
|
|
|
print e;
|
|
|
|
|
return r,status
|
|
|
|
|
|
|
|
|
|
@app.route('/1/get/logs/folders/<id>')
|
|
|
|
|
def folder_logs(id):
|
|
|
|
|
x = {"info":"folder_info","nodes":"nodes"}
|
|
|
|
|
r = "{}"
|
|
|
|
|
#
|
|
|
|
|
# let's make sure we have an active session otherwise, nothing is to be done
|
|
|
|
|
#
|
|
|
|
|
key = session['key'] if 'key' in session else None
|
|
|
|
|
if key is None and 'key' in request.headers:
|
|
|
|
|
key = request.headers['key']
|
|
|
|
|
status=403
|
|
|
|
|
plan = session['plan'] if 'plan' in session else None
|
|
|
|
|
if id in x and key and plan:
|
|
|
|
|
status = 200
|
|
|
|
|
try:
|
|
|
|
|
# store = CONFIG['store']['args']
|
|
|
|
|
view_name='summary/'+x[id].strip()
|
|
|
|
|
r = get_logs(key,view_name)
|
|
|
|
|
|
|
|
|
|
except Exception,e:
|
|
|
|
|
print e;
|
|
|
|
|
return r,status
|
|
|
|
|
|
|
|
|
|
@app.route('/1/get/logs')
|
|
|
|
|
def get_logs() :
|
|
|
|
|
"""
|
|
|
|
|
@deprecate
|
|
|
|
|
"""
|
|
|
|
|
r = {}
|
|
|
|
|
#session['key'] = 'c259e8b1-e2fb-40df-bf03-f521f8ee352d'
|
|
|
|
|
key = session['key'] if 'key' in session else None
|
|
|
|
@ -204,17 +562,21 @@ def update_profile():
|
|
|
|
|
def send_to_app () :
|
|
|
|
|
"""
|
|
|
|
|
This function will send a message to an agent, that will execute the appropriate command
|
|
|
|
|
@TODO: Provide some kind of feedback
|
|
|
|
|
@TODO: Provide some kind of feedback, insure the user's plan is verified so they do NOT do something unauthorized
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
msg = {}
|
|
|
|
|
try:
|
|
|
|
|
body = request.get_json(silent=True)
|
|
|
|
|
key = session['key']
|
|
|
|
|
args = {"host":CONFIG['api'],"qid":body["node"],"uid":key}
|
|
|
|
|
print key
|
|
|
|
|
body = dict(body,**info)
|
|
|
|
|
qhandler= factory.instance(type='QueueWriter',args=args)
|
|
|
|
|
label=body["node"]
|
|
|
|
|
qhandler.write(label=label,row=body)
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print e
|
|
|
|
|
msg = {'error':e.message}
|
|
|
|
|
return '',204
|
|
|
|
|
@app.route("/1/message/folder",methods=["POST"])
|
|
|
|
|
def send_to_folder():
|
|
|
|
@ -222,7 +584,7 @@ def send_to_folder():
|
|
|
|
|
@app.route("/1/sys/usage/trend")
|
|
|
|
|
def get_usage_trend():
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
@deprecate
|
|
|
|
|
This function returns cpu/memory usage for the entire system being monitored. It will return the 24 most recent observations in the logs
|
|
|
|
|
@param None
|
|
|
|
|
@return {memory_usage:[],cpu_usage:[],app_count:value,memory_available:[]}
|
|
|
|
@ -239,6 +601,7 @@ def get_usage_trend():
|
|
|
|
|
@app.route("/1/app/usage/trend")
|
|
|
|
|
def get_usage_detail():
|
|
|
|
|
"""
|
|
|
|
|
@deprecate
|
|
|
|
|
This function returns detailed information about usage per application monitored. It will return the 24 most recent observations in the logs
|
|
|
|
|
|
|
|
|
|
@param node node identifier e.g: apps@zulu.io
|
|
|
|
@ -277,6 +640,7 @@ def get_usage_detail():
|
|
|
|
|
@app.route('/1/app/status')
|
|
|
|
|
def app_status() :
|
|
|
|
|
"""
|
|
|
|
|
@deprecate
|
|
|
|
|
This function aggregates the number of crashes/running/idle instances found in the past 24 log entries
|
|
|
|
|
for a particular application
|
|
|
|
|
@param nid node identifier e.g: app@zulu.io
|
|
|
|
@ -378,6 +742,7 @@ def init_collector():
|
|
|
|
|
Invalid parameters were sent
|
|
|
|
|
"""
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
return json.dumps(r)
|
|
|
|
|
def InitCollector():
|
|
|
|
|
"""
|
|
|
|
@ -464,7 +829,7 @@ def sandbox():
|
|
|
|
|
try:
|
|
|
|
|
handler.init(conf[id])
|
|
|
|
|
r.append (dict(handler.composite(),**{"label":id}))
|
|
|
|
|
except Exception,e:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
|
@ -579,7 +944,7 @@ def user():
|
|
|
|
|
#_info = params[name]
|
|
|
|
|
#try:
|
|
|
|
|
#xo = ML.Filter('label',name,d)
|
|
|
|
|
#except Exception,e:
|
|
|
|
|
#except Exception as e:
|
|
|
|
|
#xo = []
|
|
|
|
|
##print name,e
|
|
|
|
|
#if len(xo) == 0:
|
|
|
|
@ -663,12 +1028,55 @@ def user():
|
|
|
|
|
#d = []
|
|
|
|
|
|
|
|
|
|
#return json.dumps(d)
|
|
|
|
|
|
|
|
|
|
@app.route("/1/plot/<format>/<id>/<key>",methods=['GET'])
|
|
|
|
|
def get_charts(format,id,key):
|
|
|
|
|
remove = request.args['no'].split(',') if 'no' in request.args else []
|
|
|
|
|
series = ['series_1']
|
|
|
|
|
|
|
|
|
|
# args = dict(session[key],**{"remove":remove})
|
|
|
|
|
# print session['cloud-info']
|
|
|
|
|
# if id == 'pie' :
|
|
|
|
|
# X = list(np.arange(3) * np.random.randn() + 10)
|
|
|
|
|
# X[2] = 23.5
|
|
|
|
|
# else :
|
|
|
|
|
# X = []
|
|
|
|
|
# series = []
|
|
|
|
|
# for i in range(0,3):
|
|
|
|
|
# X.append([ np.random.randn()+10 for i in range(0,3)])
|
|
|
|
|
# series.append('series '+str(i))
|
|
|
|
|
# labels = session['cloud-info']['labels'] #['Foo','Boo','Joo']
|
|
|
|
|
# title = 'Do More'
|
|
|
|
|
# series = [ 'Series '+str(i+1) for i in range(len(labels))]
|
|
|
|
|
# args = {"x":X,"labels":labels,"title":title,"series":series,"remove":remove}
|
|
|
|
|
|
|
|
|
|
args = session[key]
|
|
|
|
|
if isinstance(args,list) :
|
|
|
|
|
index = int(request.args['index'])
|
|
|
|
|
args = args[index]
|
|
|
|
|
|
|
|
|
|
# if remove is not None :
|
|
|
|
|
args['remove'] = remove
|
|
|
|
|
|
|
|
|
|
info = Graph.instance(format,id,**args)
|
|
|
|
|
if format in ['image','png','jpeg','jpg'] :
|
|
|
|
|
# g = ImageGraphs()
|
|
|
|
|
# stream = g.pie(X,labels,title)
|
|
|
|
|
return Response(info,mimetype='image/png')
|
|
|
|
|
else:
|
|
|
|
|
args = {'chart_id': ('g_'+id)}
|
|
|
|
|
args['config'] = info
|
|
|
|
|
args['context'] = SYS_ARGS.PARAMS['context'] if 'context' in SYS_ARGS.PARAMS else ''
|
|
|
|
|
return render_template('dashboard/graphs/chart.html',**args)
|
|
|
|
|
if __name__== '__main__':
|
|
|
|
|
app.config.from_object(__name__)
|
|
|
|
|
|
|
|
|
|
# ThreadManager.start(CONFIG)
|
|
|
|
|
SESSION_PERMANENT=True
|
|
|
|
|
app.config['SESSION_TYPE'] = 'filesystem'
|
|
|
|
|
app.config['MAX_CONTENT_LENGTH'] = 1600 * 1024 * 1024
|
|
|
|
|
app.secret_key = '360-8y-[0v@t10n]+kr81v17y'
|
|
|
|
|
if 'port' not in SYS_ARGS.PARAMS :
|
|
|
|
|
SYS_ARGS.PARAMS['port'] = 8484
|
|
|
|
|
PORT = int(SYS_ARGS.PARAMS['port'])
|
|
|
|
|
|
|
|
|
|
app.run(host='0.0.0.0' ,port=PORT,debug=True,threaded=True)
|
|
|
|
|
|
|
|
|
|