|
|
@ -22,7 +22,8 @@ import re
|
|
|
|
import monitor
|
|
|
|
import monitor
|
|
|
|
import Queue
|
|
|
|
import Queue
|
|
|
|
from utils.transport import *
|
|
|
|
from utils.transport import *
|
|
|
|
|
|
|
|
from utils.workers import ThreadManager, Factory
|
|
|
|
|
|
|
|
import atexit
|
|
|
|
PARAMS = {'context':''}
|
|
|
|
PARAMS = {'context':''}
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
|
|
|
|
|
|
|
@ -47,34 +48,36 @@ app.config['SECRET_KEY'] = '!h8-[0v8]247-4-360'
|
|
|
|
|
|
|
|
|
|
|
|
f = open(PARAMS['path'])
|
|
|
|
f = open(PARAMS['path'])
|
|
|
|
CONFIG = json.loads(f.read())
|
|
|
|
CONFIG = json.loads(f.read())
|
|
|
|
HANDLERS= {}
|
|
|
|
#HANDLERS= {}
|
|
|
|
|
|
|
|
|
|
|
|
for key in CONFIG['monitor'] :
|
|
|
|
#for key in CONFIG['monitor'] :
|
|
|
|
|
|
|
|
|
|
|
|
className = CONFIG['monitor'][key]['class']
|
|
|
|
#className = CONFIG['monitor'][key]['class']
|
|
|
|
ref = "".join(["monitor.",className,"()"])
|
|
|
|
#ref = "".join(["monitor.",className,"()"])
|
|
|
|
ref = eval(ref)
|
|
|
|
#ref = eval(ref)
|
|
|
|
HANDLERS[key] = {"class":ref,"config":CONFIG['monitor'][key]["config"]}
|
|
|
|
#HANDLERS[key] = {"class":ref,"config":CONFIG['monitor'][key]["config"]}
|
|
|
|
|
|
|
|
|
|
|
|
f.close()
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
from threading import Thread, RLock
|
|
|
|
#from threading import Thread, RLock
|
|
|
|
p = CONFIG['store']['args']
|
|
|
|
p = CONFIG['store']['args']
|
|
|
|
class_read = CONFIG['store']['class']['read']
|
|
|
|
class_read = CONFIG['store']['class']['read']
|
|
|
|
class_write= CONFIG['store']['class']['write']
|
|
|
|
class_write= CONFIG['store']['class']['write']
|
|
|
|
factory = DataSourceFactory()
|
|
|
|
factory = DataSourceFactory()
|
|
|
|
#gWriter = factory.instance(type='CouchdbWritera',args=p)
|
|
|
|
#gWriter = factory.instance(type='CouchdbWritera',args=p)
|
|
|
|
#gReader = factory.instance(type='CouchdbReader',args=p)
|
|
|
|
#gReader = factory.instance(type='CouchdbReader',args=p)
|
|
|
|
p['qid'] = HANDLERS['processes']['config'].keys()
|
|
|
|
#p['qid'] = HANDLERS['processes']['config'].keys()
|
|
|
|
gReader = factory.instance(type=class_read,args=p)
|
|
|
|
gReader = factory.instance(type=class_read,args=p)
|
|
|
|
gWriter = factory.instance(type=class_write,args=p)
|
|
|
|
#gWriter = factory.instance(type=class_write,args=p)
|
|
|
|
mthread = monitor.Monitor(HANDLERS,gWriter,'processes',)
|
|
|
|
#mthread = monitor.Monitor(HANDLERS,gWriter,'processes',)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
atexit.register(ThreadManager.stop)
|
|
|
|
@app.route('/get/<id>')
|
|
|
|
@app.route('/get/<id>')
|
|
|
|
def procs(id):
|
|
|
|
def procs(id):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
|
|
|
|
gReader = factory.instance(type=class_read,args=p)
|
|
|
|
d = gReader.read()
|
|
|
|
d = gReader.read()
|
|
|
|
|
|
|
|
|
|
|
|
r = {}
|
|
|
|
r = {}
|
|
|
@ -93,10 +96,16 @@ def procs(id):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
@app.route('/sandbox')
|
|
|
|
@app.route('/sandbox')
|
|
|
|
def sandbox():
|
|
|
|
def sandbox():
|
|
|
|
if 'sandbox' in HANDLERS:
|
|
|
|
global CONFIG
|
|
|
|
handler = HANDLERS['sandbox']['class']
|
|
|
|
print CONFIG['monitor']
|
|
|
|
conf = HANDLERS['sandbox']['config']
|
|
|
|
if 'sandbox' in CONFIG['monitor']:
|
|
|
|
|
|
|
|
#handler = HANDLERS['sandbox']['class']
|
|
|
|
|
|
|
|
#conf = HANDLERS['sandbox']['config']
|
|
|
|
r = []
|
|
|
|
r = []
|
|
|
|
|
|
|
|
p = Factory.instance('sandbox',CONFIG)
|
|
|
|
|
|
|
|
handler = p['class']
|
|
|
|
|
|
|
|
conf = p['config']
|
|
|
|
|
|
|
|
|
|
|
|
for id in conf:
|
|
|
|
for id in conf:
|
|
|
|
handler.init(conf[id])
|
|
|
|
handler.init(conf[id])
|
|
|
|
r.append (dict(handler.composite(),**{"label":id}))
|
|
|
|
r.append (dict(handler.composite(),**{"label":id}))
|
|
|
@ -171,7 +180,7 @@ def anomalies_get():
|
|
|
|
|
|
|
|
|
|
|
|
if __name__== '__main__':
|
|
|
|
if __name__== '__main__':
|
|
|
|
|
|
|
|
|
|
|
|
mthread.start()
|
|
|
|
ThreadManager.start(CONFIG)
|
|
|
|
app.run(host='0.0.0.0',debug=True,threaded=True)
|
|
|
|
app.run(host='0.0.0.0',debug=True,threaded=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|