def parse_http_delete(args): destination = args.destination http_execute(const.HttpOperation.DELETE, destination, parse_http_request_parameters(args), parse_http_response_parameters())
def parse_http_post(args): destination = args.destination http_execute(HttpOperation.POST, destination, parse_http_request_parameters(args), parse_http_response_parameters())
def parse_http_put(args): destination = args.destination http_execute(const.HttpOperation.PUT, destination, parse_http_request_parameters(args), parse_http_response_parameters())
def queue_callback(_ch, _method, _properties, body): # 接收 logger.debug("Receive request [x]: {}".format(body)) command = json.loads(body) protocol = command["protocol"] destination = command["destination"] # request_parameters request_parameters = dict() if command.get("parameters"): request_parameters = command.get("parameters") # server_request_generate_time request_parameters["server_request_generate_time"] = command[ "generate_timestamp"] # terminal_request_receive_time request_parameters["terminal_request_receive_time"] = time.time() # set logger to request request_parameters["logger"] = ln # response_parameters response_parameters = dict() response_parameters["storage_type"] = const.StorageMode.RABBITMQ response_parameters["storage_queue"] = const.REQUEST_STORAGE_QUEUE_NAME response_parameters["storage_routing"] = const.REQUEST_STORAGE_ROUTING_KEY response_parameters["command_uuid"] = command["uuid"] response_parameters["command_terminal"] = command["terminal"] # set logger to response response_parameters["logger"] = ln # 分发, 根据command_protocol if protocol.lower() == Command.PING.value: logger.info("executing ping ......") ping_execute(destination, request_parameters, response_parameters) elif protocol.lower() == Command.TRACEROUTE.value: logger.info("executing traceroute ......") traceroute_execute(destination, request_parameters, response_parameters) elif protocol.lower() == Command.DNS.value: logger.info("executing dns ......") dns_execute(destination, request_parameters, response_parameters) elif protocol.lower() == Command.HTTP.value: operation = request_parameters.get("operation") if operation: if operation.lower() == HttpOperation.GET.value: http_operation = HttpOperation.GET elif operation.lower() == HttpOperation.POST.value: http_operation = HttpOperation.POST elif operation.lower() == HttpOperation.PUT.value: http_operation = HttpOperation.PUT elif operation.lower() == HttpOperation.DELETE.value: http_operation = HttpOperation.DELETE else: print( "ERROR, do not support operation {}, will use get as default" .format(protocol.lower())) logging.error( "ERROR, do not support operation {}, will use get as default" .format(protocol.lower())) logger.info("executing http {} ......".format( http_operation.value)) http_execute(http_operation, destination, request_parameters, response_parameters) else: logger.error("parameter operation is required for HTTP") else: logger.error("Natrix do not support {}".format(protocol))