def post(self): """ POST方法 :return: """ # 参数验证 args = self.post_parser.parse_args() mac_addr = args.get('mac_addr') # mac_addr参数 access_token = args.get('access_token') # token参数 cpu_percent = args.get('cpu_percent') # cpu_percent参数 cpu_count = args.get('cpu_count') # cpu_count参数 cpu_freq_current = args.get('cpu_freq_current') # cpu_freq_current参数 total_memory = args.get('total_memory') # total_memory参数 available_memory = args.get('available_memory') # available_memory参数 sensors_battery_percent = args.get( 'sensors_battery_percent') # sensors_battery_percent参数 boot_time = args.get('boot_time') # boot_time参数 create_time = args.get('create_time') # create_time参数 flag = Certify.certify_agent(mac_addr, access_token) if flag == 1: row = AgentResourceLogs(mac_addr, cpu_percent, cpu_count, cpu_freq_current, total_memory, available_memory, sensors_battery_percent, boot_time, create_time) db.session.add(row) # 新增设备资源信息记录 db.session.commit() return { 'status': '1', 'state': 'success', 'message': 'Record added' } else: msg = 'Access denied' abort.abort_with_msg(403, flag, 'error', msg)
def post(self): """ POST方法 :return: """ # 参数验证 args = self.post_parser.parse_args() mac_addr = args.get('mac_addr') access_token = args.get('access_token') create_time = args.get('create_time') flag = Certify.certify_agent(mac_addr, access_token) if flag == 1: rt = db.session.query(AgentHeartbeatLogs).filter_by(mac_addr=mac_addr).first() if rt: rt.create_time = create_time # 修改最后心跳时间 db.session.commit() else: row = AgentHeartbeatLogs(mac_addr, create_time) db.session.add(row) # 新增心跳记录 db.session.commit() return {'status': '1', 'state': 'success', 'message': 'Server online'} else: msg = 'Access denied' abort.abort_with_msg(403, flag, 'error', msg)
def post(self): """ POST方法 :return: """ args = self.post_parser.parse_args() client_id = args.get('client_id') client_secret = args.get('client_secret') mac_addr = args.get('mac_addr') message = args.get('message') create_time = args.get('create_time') flag = Certify.certify_client(client_id, client_secret) if flag == 1: boxed_msg = { 'mac_addr': mac_addr, 'message': message, 'create_time': create_time } status = ws_rpc_client.run(index=mac_addr, msg=str(boxed_msg)) if status: return {'status': '1', 'state': 'success', 'message': 'Message pushed successfully'} else: return {'status': '-1', 'state': 'error', 'message': 'Message pushed failed'} else: # Client验证未通过 msg = 'Access denied' abort.abort_with_msg(403, flag, 'error', msg)
def get(self): """ POST方法 :return: """ # 参数验证 args = self.get_parser.parse_args() client_id = args.get('client_id') client_secret = args.get('client_secret') mac_addr = args.get('mac_addr') page = args.get('page') flag = Certify.certify_client(client_id, client_secret) if flag == 1: if mac_addr: rt = db.session.query(AgentResourceLogs).filter_by( mac_addr=mac_addr).order_by( AgentResourceLogs.create_time.desc()).limit( self._PAGE_SIZE).offset( (page - 1) * self._PAGE_SIZE).all() else: rt = db.session.query(AgentResourceLogs).order_by( AgentResourceLogs.create_time.desc()).limit( self._PAGE_SIZE).offset( (page - 1) * self._PAGE_SIZE).all() return {'status': '1', 'state': 'success', 'message': rt} else: msg = 'Access denied' abort.abort_with_msg(403, flag, 'error', msg)
def delete(self): """ DELETE方法 :return: """ args = self.del_parser.parse_args() client_id = args.get('client_id') client_secret = args.get('client_secret') mac_addr = args.get('mac_addr') flag = Certify.certify_client(client_id, client_secret) if flag == 1: # Client验证通过 rt = db.session.query(AgentRegisterLogs).filter( AgentRegisterLogs.mac_addr == mac_addr).first() if rt: # Agent已在白名单 db.session.delete(rt) db.session.commit() return { 'status': '1', 'state': 'success', 'message': 'Agent deleted' } else: # Agent未在白名单 msg = 'Delete denied' abort.abort_with_msg(403, -2, 'error', msg) else: # Client验证未通过 msg = 'Access denied' abort.abort_with_msg(403, flag, 'error', msg)
def put(self): """ PUT方法 :return: """ args = self.put_parser.parse_args() # 解析参数 client_id = args.get('client_id') client_secret = args.get('client_secret') mac_addr = args.get('mac_addr') status = args.get('status') flag = Certify.certify_client(client_id, client_secret) if flag == 1: rt = db.session.query(AgentRegisterLogs).filter( AgentRegisterLogs.mac_addr == mac_addr).first() if rt: # Agent已在白名单 rt.status = status db.session.commit() return { 'status': '1', 'state': 'success', 'message': 'Agent updated' } else: # Agent未在白名单 msg = 'Access denied' abort.abort_with_msg(403, flag, 'error', msg) else: msg = 'Access denied' abort.abort_with_msg(403, flag, 'error', msg)
def post(self): """ POST方法 :return: """ args = self.post_parser.parse_args() # 解析参数 client_id = args.get('client_id') client_secret = args.get('client_secret') mac_addr = args.get('mac_addr') status = args.get('status') flag = Certify.certify_client(client_id, client_secret) # Client验证 if flag == 1: rt = db.session.query(AgentRegisterLogs).filter( AgentRegisterLogs.mac_addr == mac_addr).first() if rt is None: # Agent未在白名单 row = AgentRegisterLogs(mac_addr, None, status) db.session.add(row) db.session.commit() return { 'status': '1', 'state': 'success', 'message': 'Agent added' } else: # Agent已在白名单 msg = 'Agent already exists' abort.abort_with_msg(403, -2, 'error', msg) else: msg = 'Access denied' abort.abort_with_msg(403, flag, 'error', msg)
def get(self): args = self.get_parser.parse_args() # 解析参数 client_id = args.get('client_id') client_secret = args.get('client_secret') page = args.get('page') # 页数索引 flag = Certify.certify_client(client_id, client_secret) # Client验证 if flag == 1: rt = db.session.query(AgentRegisterLogs).limit( self._PAGE_SIZE).offset((page - 1) * self._PAGE_SIZE) return {'status': '1', 'state': 'success', 'message': rt} else: msg = 'Access denied' abort.abort_with_msg(403, flag, 'error', msg)
def get(self): """ GET方法 :return: """ # 参数验证 args = self.get_parser.parse_args() mac_addr = args.get('mac_addr') rt = db.session.query(AgentRegisterLogs).filter( AgentRegisterLogs.mac_addr == mac_addr).first() if rt and rt.status == 1: rt.access_token = Certify.generate_token(mac_addr) db.session.commit() return {'status': 1, 'state': 'success', 'message': rt} else: msg = 'Access denied' abort.abort_with_msg(403, -1, 'error', msg)