|
|
@ -13,6 +13,7 @@ from datetime import datetime
|
|
|
|
from utils.transport import *
|
|
|
|
from utils.transport import *
|
|
|
|
import monitor
|
|
|
|
import monitor
|
|
|
|
import requests
|
|
|
|
import requests
|
|
|
|
|
|
|
|
|
|
|
|
class Manager() :
|
|
|
|
class Manager() :
|
|
|
|
def version(self):
|
|
|
|
def version(self):
|
|
|
|
return 1.1
|
|
|
|
return 1.1
|
|
|
@ -35,7 +36,7 @@ class Manager() :
|
|
|
|
self.plan = self.config['plan']
|
|
|
|
self.plan = self.config['plan']
|
|
|
|
|
|
|
|
|
|
|
|
self.DELAY = int(self.plan['metadata']['delay'])
|
|
|
|
self.DELAY = int(self.plan['metadata']['delay'])
|
|
|
|
|
|
|
|
self.host = args['host']
|
|
|
|
self.update() #-- Initializing status information
|
|
|
|
self.update() #-- Initializing status information
|
|
|
|
|
|
|
|
|
|
|
|
def update(self) :
|
|
|
|
def update(self) :
|
|
|
@ -43,13 +44,15 @@ class Manager() :
|
|
|
|
This method inspect the plans for the current account and makes sure it can/should proceed
|
|
|
|
This method inspect the plans for the current account and makes sure it can/should proceed
|
|
|
|
The user must be subscribed and to the service otherwise this is not going to work
|
|
|
|
The user must be subscribed and to the service otherwise this is not going to work
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
# url="https://the-phi.com/store/status/monitor"
|
|
|
|
|
|
|
|
# r = requests.get(url,headers={"uid":self.key})
|
|
|
|
|
|
|
|
# plans = json.loads(r.text)
|
|
|
|
|
|
|
|
# meta = [item['metadata'] for item in plans if item['status']=='active' ]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
url="http://:host/monitor/init/collector".replace(':host',self.host)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
r = requests.post(url,headers={"key":self.key,"id":self.id})
|
|
|
|
|
|
|
|
r = json.loads(r.text)
|
|
|
|
|
|
|
|
# meta = [item['metadata'] for item in plans if item['status']=='active' ]
|
|
|
|
|
|
|
|
self.plan = r['plan']
|
|
|
|
meta = self.plan['metadata']
|
|
|
|
meta = self.plan['metadata']
|
|
|
|
|
|
|
|
print meta
|
|
|
|
if meta :
|
|
|
|
if meta :
|
|
|
|
self.DELAY = 60* int(meta['delay'])
|
|
|
|
self.DELAY = 60* int(meta['delay'])
|
|
|
|
self.LIMIT = int(meta['limit'])
|
|
|
|
self.LIMIT = int(meta['limit'])
|
|
|
@ -218,6 +221,7 @@ class Manager() :
|
|
|
|
COUNT_STOP = int(24*60/ self.DELAY)
|
|
|
|
COUNT_STOP = int(24*60/ self.DELAY)
|
|
|
|
write_class = self.config['store']['class']['write']
|
|
|
|
write_class = self.config['store']['class']['write']
|
|
|
|
read_args = self.config['store']['args']
|
|
|
|
read_args = self.config['store']['args']
|
|
|
|
|
|
|
|
print self.agents
|
|
|
|
while True :
|
|
|
|
while True :
|
|
|
|
COUNT += 1
|
|
|
|
COUNT += 1
|
|
|
|
if COUNT > COUNT_STOP :
|
|
|
|
if COUNT > COUNT_STOP :
|
|
|
@ -230,13 +234,14 @@ class Manager() :
|
|
|
|
label = agent.getName()
|
|
|
|
label = agent.getName()
|
|
|
|
node = '@'.join([label,self.id])
|
|
|
|
node = '@'.join([label,self.id])
|
|
|
|
row = {}
|
|
|
|
row = {}
|
|
|
|
|
|
|
|
|
|
|
|
if label == 'folders':
|
|
|
|
if label == 'folders':
|
|
|
|
row = [ dict({"id":self.id}, **_row) for _row in data]
|
|
|
|
row = [ dict({"id":self.id}, **_row) for _row in data]
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
#label = id
|
|
|
|
#label = id
|
|
|
|
row = data
|
|
|
|
row = data
|
|
|
|
if type(row)==list and len(row) == 0 :
|
|
|
|
if type(row)==list and len(row) == 0 :
|
|
|
|
|
|
|
|
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
#
|
|
|
@ -245,12 +250,13 @@ class Manager() :
|
|
|
|
|
|
|
|
|
|
|
|
if len(self.actors) > index and self.actors[index].getName() == agent.getName() :
|
|
|
|
if len(self.actors) > index and self.actors[index].getName() == agent.getName() :
|
|
|
|
actor = self.actors[index]
|
|
|
|
actor = self.actors[index]
|
|
|
|
print actor.analyze(row)
|
|
|
|
actor.analyze(row)
|
|
|
|
|
|
|
|
|
|
|
|
# self.lock.acquire()
|
|
|
|
# self.lock.acquire()
|
|
|
|
store = self.factory.instance(type=write_class,args=read_args)
|
|
|
|
store = self.factory.instance(type=write_class,args=read_args)
|
|
|
|
store.flush(size=self.LIMIT)
|
|
|
|
store.flush(size=self.LIMIT)
|
|
|
|
store.write(label=node,row=row)
|
|
|
|
store.write(label=node,row=[row])
|
|
|
|
# self.lock.release()
|
|
|
|
# self.lock.release()
|
|
|
|
|
|
|
|
print (["Falling asleep ",self.DELAY/60])
|
|
|
|
time.sleep(self.DELAY)
|
|
|
|
time.sleep(self.DELAY)
|
|
|
|
|
|
|
|
|
|
|
|