def distribute_message(self,message): data = message.dict() data['name'] = message.__class__.__name__ data['type_id'] = message.Type.value data['type_comment'] = message.Type.comment data['timestamp'] = timestamp_current() data['datetime'] = current_datetime_string() data['device_id'] = self.device_id data['device_type'] = self.device_type if data.has_key('extra'): del data['extra'] if data.has_key('Type'): del data['Type'] print data #将设备消息发布出去 self.service.dataFanout('switch0',json.dumps(data)) # 发布到隶属于设备编号的通道上去 self.device_pub_channel.publish_or_produce(json.dumps(data)) # # 写入日志数据库 dbname = 'blue_earth_device_log' coll = self.mongo[dbname][self.device_id] coll.insert_one(data)
def onData(self, conn, data): self.logger.debug("app data retrieve in . " + data) json_text_list = self.accumulator.enqueue(data) # dump = self.hex_dump(bytes) # self.logger.debug("<< "+dump) # self.dump_hex_data(dump) for text in json_text_list: message = parseMessage(text) if message: self.queue.put([message, current_datetime_string()])
def onData(self,conn,data): self.logger.debug("<< Device Data Retrieve in . {} {}".format(self.device_id, self.device_type)) self.logger.debug(data) json_text_list = self.accumulator.enqueue(data) # dump = self.hex_dump(bytes) # self.logger.debug("<< "+dump) # self.dump_hex_data(dump) for text in json_text_list: message = parseMessage(text) if message: self.queue.put([message, current_datetime_string()])
def onData(self,bytes): """ raw data """ self.logger.debug("device data retrieve in . {} {}".format(self.device_id,self.device_type)) dump = self.hex_dump(bytes) self.logger.debug("<< "+dump) self.dump_hex_data(dump) # self.raw_file.write(bytes) # self.raw_file.flush() messages = self.accumulator.enqueue(bytes) for message in messages: # self.handle(message) self.queue.put([message,current_datetime_string()])
def checkTask(self, dest): from model import InnberBoxCheck, InnberBoxCheckSnapShot data = check_one_host(dest) if not data: return data['ip'], data['port'] = dest data['check_time_s'] = current_datetime_string() data['check_time'] = timestamp_current() check = InnberBoxCheck() check.assign(data) check.save() obj = InnberBoxCheckSnapShot.get_or_new(ip=dest[0]) obj.assign(data) obj.save()
def check_one_host(address): print 'enter time:', current_datetime_string() print 'check_one_host:', address sock = socket.socket() data = {} try: with gevent.Timeout(20) as timeout: sock.connect(address) sock.sendall('{"method":"system_query_stat"}') data = sock.recv(10000) data = parseCheckInfo(data) return data except: # traceback.print_exc() print 'Error: host({}) not reachable.'.format(str(address)) return {} finally: sock.close()
def ctp_strategy_run(): """加载运行策略""" start_time = current_datetime_string() mode = request.values.get('mode', 'test') strategy_id = request.values.get("strategy_id", '') st = model.StrategyParam.get(strategy_id=strategy_id) main = instance.serviceManager.get("main") locust_dir = main.getConfig().get('locust_home') path = os.path.join(locust_dir, 'scripts/st-load.sh') params = st.run_test_params if mode == 'real': params = st.run_real_params cmd = 'bash {} {} {} {}'.format(path, st.script, st.strategy_id, params) print 'System Exec:', cmd os.system(cmd) return CR(result=start_time).response