diff --git a/WatcherAgent/src/api.rs b/WatcherAgent/src/api.rs index b19bc46..a34dc9a 100644 --- a/WatcherAgent/src/api.rs +++ b/WatcherAgent/src/api.rs @@ -152,6 +152,41 @@ async fn get_server_id_by_ip( } } +/// Broadcasts Docker container information to the monitoring server for service discovery. +/// +/// This function sends the current Docker container configuration to the server +/// to register available containers and enable service monitoring. It will +/// continuously retry until successful, making it suitable for initial +/// registration scenarios. +/// +/// # Arguments +/// +/// * `base_url` - The base URL of the monitoring server API (e.g., "https://monitoring.example.com") +/// * `server_id` - The ID of the server to associate the containers with +/// * `container_dto` - Mutable reference to Docker container information for broadcast +/// +/// # Returns +/// +/// * `Ok(())` - When container information is successfully broadcasted to the server +/// * `Err(Box)` - If an unrecoverable error occurs (though the function typically retries on transient failures) +/// +/// # Behavior +/// +/// This function operates in a retry loop with the following characteristics: +/// +/// - **Retry Logic**: Attempts broadcast every 10 seconds until successful +/// - **Mutation**: Modifies the `container_dto` to set the `server_id` before sending +/// - **TLS**: Accepts invalid TLS certificates for development environments +/// - **Logging**: Provides detailed console output about broadcast attempts and results +/// +/// # Errors +/// +/// This function may return an error in the following cases: +/// +/// * **HTTP Client Creation**: Failed to create HTTP client with TLS configuration +/// * **Network Issues**: Persistent connection failures to the backend server +/// * **Server Errors**: Backend returns non-success HTTP status codes repeatedly +/// * **JSON Serialization**: Cannot serialize container data (should be rare with proper DTOs) pub async fn broadcast_docker_containers( base_url: &str, server_id: u16,