|
@@ -1,10 +1,19 @@
|
|
|
-"""
|
|
|
+h="""
|
|
|
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
|
|
|
+ usage :
|
|
|
+ python data-collector.py --path config.json
|
|
|
+ The configuration file is structured as JSON object as follows :
|
|
|
+ {
|
|
|
+ id: node identifier
|
|
|
+ key: customer's identification key
|
|
|
+ apps:"app_1,app_2,...",
|
|
|
+ folders:"path_1,path_2, ..."
|
|
|
+ }
|
|
|
"""
|
|
|
-from utils.params import PARAMS as SYS_ARGS
|
|
|
+from utils.params import PARAMS as SYS_ARGS, Logger
|
|
|
import requests
|
|
|
import pickle
|
|
|
import json
|
|
@@ -29,16 +38,24 @@ class Collector(Thread) :
|
|
|
headers = {"key":SYS_ARGS["key"],"id":SYS_ARGS["id"]} #,"scope":json.dumps(scope)}
|
|
|
headers['content-type'] = 'application/json'
|
|
|
try:
|
|
|
+ Logger.log(subject='Collector',object='api',action='request',value=ENDPOINT)
|
|
|
url = "/".join([ENDPOINT,"init/collector"])
|
|
|
- r = requests.post(url,headers=headers,data=json.dumps(SYS_ARGS))
|
|
|
+ data = {}
|
|
|
+ for id in SYS_ARGS :
|
|
|
+ if id not in ['id','key'] :
|
|
|
+ data[id] = SYS_ARGS[id]
|
|
|
+
|
|
|
+ r = requests.post(url,headers=headers,data=json.dumps(data))
|
|
|
r = json.loads(r.text)
|
|
|
|
|
|
self.monitor = pickle.loads(r[0])
|
|
|
self.monitor.lock = RLock()
|
|
|
#:w
|
|
|
#self.monitor.set('lock',RLock())
|
|
|
+ Logger.log(subject='Collector',object='api',action='load',value='')
|
|
|
except Exception,e:
|
|
|
- print e.message
|
|
|
+
|
|
|
+ Logger.log(subject='Collector',object='api',action='error',value=str(e))
|
|
|
self.monitor = None
|
|
|
|
|
|
def run(self):
|
|
@@ -47,7 +64,7 @@ class Collector(Thread) :
|
|
|
"""
|
|
|
#self.monitor.start()
|
|
|
|
|
|
-
|
|
|
+ Logger.log(subject='Collector',object='monitor',action='start',value='')
|
|
|
thread = Thread(target=self.monitor.run)
|
|
|
thread.start()
|
|
|
# print self.monitor.config['store']
|
|
@@ -62,6 +79,17 @@ class Collector(Thread) :
|
|
|
# except Exception,e:
|
|
|
# print e
|
|
|
|
|
|
-if __name__ == '__main__' :
|
|
|
+if __name__ == '__main__' and 'path' in SYS_ARGS:
|
|
|
+ #
|
|
|
+ #
|
|
|
+
|
|
|
+ path = SYS_ARGS['path']
|
|
|
+ f = open(path)
|
|
|
+ p = json.loads(f.read())
|
|
|
+ f.close()
|
|
|
+ Logger.init('data-collector')
|
|
|
+ SYS_ARGS = dict(SYS_ARGS,** p)
|
|
|
thread = Collector()
|
|
|
- thread.start()
|
|
|
+ thread.start()
|
|
|
+else:
|
|
|
+ print (h)
|