Skip to content
Snippets Groups Projects
Commit e97926d8 authored by jkerdreu's avatar jkerdreu
Browse files

Linting..


git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@3068 b32b6428-25c9-4566-ad07-03861ab6144f
parent 615a00a6
No related branches found
No related tags found
No related merge requests found
from xaal.lib import Device,tools,config
import sys
import time
import platform
import urllib3
import logging
from xaal.lib import Device, tools
PACKAGE_NAME = "xaal.warp10"
logger = logging.getLogger(PACKAGE_NAME)
# period between two push
PUSH_RATE = 30
PUSH_RATE = 30
DATA_BUF = ''
class WARP10Logger:
def __init__(self,engine):
def __init__(self, engine):
self.eng = engine
# change xAAL call flow
self.eng.subscribe(self.parse_msg)
......@@ -27,58 +27,56 @@ class WARP10Logger:
dev.address = tools.get_uuid(self.cfg['addr'])
dev.vendor_id = "IHSEV"
dev.product_id = "WARP10 Logger"
dev.info = "%s@%s" % (PACKAGE_NAME,platform.node())
dev.info = "%s@%s" % (PACKAGE_NAME, platform.node())
self.eng.add_device(dev)
self.http = urllib3.PoolManager()
self.eng.add_timer(self.push,PUSH_RATE)
self.eng.add_timer(self.push, PUSH_RATE)
def push(self):
global DATA_BUF
if len(DATA_BUF)==0:
return
#print(DATA_BUF)
# print(DATA_BUF)
try:
#logger.debug(DATA_BUF)
rsp = self.http.request('POST', self.cfg['url'],headers={'X-Warp10-Token':self.cfg['token']},body=DATA_BUF,retries=2)
# logger.debug(DATA_BUF)
rsp = self.http.request('POST', self.cfg['url'], headers={'X-Warp10-Token': self.cfg['token']}, body=DATA_BUF, retries=2)
except Exception:
# no need to log since, urllib3 already log errors
return
if rsp.status != 200:
logger.error('%s: %s' % (rsp.status,rsp.reason))
logger.error('%s: %s' % (rsp.status, rsp.reason))
# warp10 will rise an internal error if data contain contain a wrong pload
# I decided to drop this data, because we will loop until death here
if rsp.status == 500:
DATA_BUF=''
DATA_BUF = ''
return
DATA_BUF = ''
def parse_msg(self,msg):
def parse_msg(self, msg):
global DATA_BUF
# only deal w/ notification (not alive)
if not msg.is_notify():
return
if msg.is_alive():
return
buf = ''
base = self.cfg['topic'] + '.' + msg.dev_type
now = round(time.time() * 1000000)
tags = '{devid=%s}' % str(msg.source)
tags = '{devid=%s}' % str(msg.source)
# log attributes change
if msg.is_attributes_change():
for k in msg.body:
name = '%s.%s' % (base,k)
name = '%s.%s' % (base, k)
value = msg.body[k]
if value != None and (type(value) not in [list,str]):
buf = buf +"%s// %s%s %s\n" % (now,name,tags,value)
if value != None and (type(value) not in [list, str]):
buf = buf + "%s// %s%s %s\n" % (now, name, tags, value)
# log notification with no body (click...)
else:
name = '%s.%s' % (base,msg.action)
buf = buf +"%s// %s%s %s\n" % (now,name,tags,True)
buf = buf +"%s// %s%s %s\n" % (now+1,name,tags,False)
name = '%s.%s' % (base, msg.action)
buf = buf + "%s// %s%s %s\n" % (now, name, tags, True)
buf = buf + "%s// %s%s %s\n" % (now+1, name, tags, False)
DATA_BUF = DATA_BUF + buf
def setup(engine):
WARP10Logger(engine)
return True
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment