Register Agent
Description
The register_agent
function sends a POST request to register an agent with a web service, providing details like device name, agent type, version, and process ID. It returns the response code and response string after making the request.
Function Signature:
def register_agent(ws_config: WebServiceConfig, device_name: str, agent_type: str, agent_version: str, agent_index: int, process_id: int) -> tuple[int, str]:
Parameters
- ws_config (WebServiceConfig): Configuration for the web service connection.
- device_name (str): The name of the device being registered.
- agent_type (str): The type of the agent.
- agent_version (str): The version of the agent.
- agent_index (int): The index of the agent.
- process_id (int): The process ID of the agent.
Returns
- tuple[int, str]: The response code and the response string from the web service. If an error occurs,
-1
and an error message are returned.
Example Usage
ws_config = WebServiceConfig(base_url="https://api.actionstreamer.com")
device_name = "Device123"
agent_type = "TypeA"
agent_version = "1.0"
agent_index = 1
process_id = 1234
response_code, response_string = register_agent(ws_config, device_name, agent_type, agent_version, agent_index, process_id)
Behavior
- The function prepares a JSON payload with details about the agent.
- It sends a POST request to the web service using the
send_signed_request
function. - The response from the web service is returned, or an error message is printed if an exception occurs.
Error Handling
- General Exception: Any errors during the request (e.g., connection issues or invalid response) will be caught, and an error message will be printed.
- Exception Information: If an error occurs, the function prints the filename and line number for easier debugging.