| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- """
- This is a data-collector client, that is intended to perform data-collection operations and submit them to an endpoint
- @required:
- - key application/service key
- - id node identifier
- """
- from utils.params import PARAMS as SYS_ARGS
- import requests
- import pickle
- import json
- from threading import Thread, RLock
- ENDPOINT="https://the-phi.com/monitor"
- class Collector(Thread) :
- def __init__(self):
- Thread.__init__(self)
- """
- This function initializes the data collector with critical information
- The process will include validating the user's account and plan
- @param key customer's key
- @param id node identifier
-
- """
- for id in ['apps','folders']:
- if id in SYS_ARGS :
- SYS_ARGS[id] = SYS_ARGS[id].split(',')
-
-
- headers = {"key":SYS_ARGS["key"],"id":SYS_ARGS["id"]} #,"scope":json.dumps(scope)}
- headers['content-type'] = 'application/json'
- try:
- url = "/".join([ENDPOINT,"init/collector"])
- r = requests.post(url,headers=headers,data=json.dumps(SYS_ARGS))
- r = json.loads(r.text)
-
- self.monitor = pickle.loads(r[0])
- self.monitor.lock = RLock()
- #:w
- #self.monitor.set('lock',RLock())
- except Exception,e:
- print e.message
- self.monitor = None
- def run(self):
- """
- This funtion runs the authorized features and
- """
- #self.monitor.start()
-
-
- thread = Thread(target=self.monitor.run)
- thread.start()
- # print self.monitor.config['store']
- # for agent in self.pool :
- # try:
- # agent = pickle.loads(agent)
- # agent.start()
- # #p = pickle.loads(self.pool[key])
- # #p.init(SYS_ARGS[key].split(','))
- # #p.start()
- # except Exception,e:
- # print e
- if __name__ == '__main__' :
- thread = Collector()
- thread.start()
|