From 67c3265286448a5e7450d76a8298b297fb99cb19 Mon Sep 17 00:00:00 2001 From: Sylvain Tremblay Date: Fri, 13 Mar 2026 10:31:17 -0400 Subject: [PATCH] fix: small details were preventing to re-save frontends,backends and healthchecks in opnsense UI --- harmony/src/infra/opnsense/load_balancer.rs | 29 ++++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/harmony/src/infra/opnsense/load_balancer.rs b/harmony/src/infra/opnsense/load_balancer.rs index 4d3dd99..8e496a9 100644 --- a/harmony/src/infra/opnsense/load_balancer.rs +++ b/harmony/src/infra/opnsense/load_balancer.rs @@ -267,10 +267,16 @@ pub(crate) fn harmony_load_balancer_service_to_haproxy_xml( SSL::Default => "".into(), SSL::Other(other) => other.as_str().into(), }; + let path_without_query = path.split_once('?').map_or(path.as_str(), |(p, _)| p); + let (port, port_name) = match port { + Some(port) => (Some(port.to_string()), port.to_string()), + None => (None, "serverport".to_string()), + }; + let haproxy_check = HAProxyHealthCheck { - name: format!("HTTP_{http_method}_{path}"), + name: format!("HTTP_{http_method}_{path_without_query}_{port_name}"), uuid: Uuid::new_v4().to_string(), - http_method: http_method.to_string().into(), + http_method: http_method.to_string().to_lowercase().into(), health_check_type: "http".to_string(), http_uri: path.clone().into(), interval: "2s".to_string(), @@ -314,7 +320,10 @@ pub(crate) fn harmony_load_balancer_service_to_haproxy_xml( let mut backend = HAProxyBackend { uuid: Uuid::new_v4().to_string(), enabled: 1, - name: format!("backend_{}", service.listening_port), + name: format!( + "backend_{}", + service.listening_port.to_string().replace(':', "_") + ), algorithm: "roundrobin".to_string(), random_draws: Some(2), stickiness_expire: "30m".to_string(), @@ -346,10 +355,22 @@ pub(crate) fn harmony_load_balancer_service_to_haproxy_xml( let frontend = Frontend { uuid: uuid::Uuid::new_v4().to_string(), enabled: 1, - name: format!("frontend_{}", service.listening_port), + name: format!( + "frontend_{}", + service.listening_port.to_string().replace(':', "_") + ), bind: service.listening_port.to_string(), mode: "tcp".to_string(), // TODO do not depend on health check here default_backend: Some(backend.uuid.clone()), + stickiness_expire: "30m".to_string().into(), + stickiness_size: "50k".to_string().into(), + stickiness_conn_rate_period: "10s".to_string().into(), + stickiness_sess_rate_period: "10s".to_string().into(), + stickiness_http_req_rate_period: "10s".to_string().into(), + stickiness_http_err_rate_period: "10s".to_string().into(), + stickiness_bytes_in_rate_period: "1m".to_string().into(), + stickiness_bytes_out_rate_period: "1m".to_string().into(), + ssl_hsts_max_age: 15768000, ..Default::default() }; info!("HAPRoxy frontend and backend mode currently hardcoded to tcp"); -- 2.39.5