diff --git a/src/rust/lqos_config/src/etc/migration.rs b/src/rust/lqos_config/src/etc/migration.rs index 25ccea3c..6b069015 100644 --- a/src/rust/lqos_config/src/etc/migration.rs +++ b/src/rust/lqos_config/src/etc/migration.rs @@ -8,6 +8,7 @@ use super::{ use thiserror::Error; use toml_edit::DocumentMut; use tracing::{debug, error, info}; +use crate::etc::v15::influxdb::InfluxDbConfig; #[derive(Debug, Error)] pub enum MigrationError { @@ -278,10 +279,14 @@ fn migrate_influx( python_config: &PythonMigration, new_config: &mut Config, ) -> Result<(), MigrationError> { - new_config.influxdb.enable_influxdb = python_config.influx_enabled; - new_config.influxdb.url = python_config.influx_dburl.clone(); - new_config.influxdb.bucket = python_config.influx_dbbucket.clone(); - new_config.influxdb.org = python_config.influx_dborg.clone(); - new_config.influxdb.token = python_config.influx_dbtoken.clone(); + if python_config.influx_enabled { + let mut cfg = InfluxDbConfig::default(); + cfg.enable_influxdb = python_config.influx_enabled; + cfg.url = python_config.influx_dburl.clone(); + cfg.bucket = python_config.influx_dbbucket.clone(); + cfg.org = python_config.influx_dborg.clone(); + cfg.token = python_config.influx_dbtoken.clone(); + new_config.influxdb = Some(cfg); + } Ok(()) } diff --git a/src/rust/lqos_config/src/etc/v15/mod.rs b/src/rust/lqos_config/src/etc/v15/mod.rs index a84906e1..14d23a58 100644 --- a/src/rust/lqos_config/src/etc/v15/mod.rs +++ b/src/rust/lqos_config/src/etc/v15/mod.rs @@ -13,7 +13,7 @@ mod spylnx_integration; mod uisp_integration; mod powercode_integration; mod sonar_integration; -mod influxdb; +pub mod influxdb; mod flows; pub use bridge::*; pub use long_term_stats::LongTermStats; diff --git a/src/rust/lqos_config/src/etc/v15/top_config.rs b/src/rust/lqos_config/src/etc/v15/top_config.rs index dfd4999e..54b24b33 100644 --- a/src/rust/lqos_config/src/etc/v15/top_config.rs +++ b/src/rust/lqos_config/src/etc/v15/top_config.rs @@ -70,7 +70,7 @@ pub struct Config { pub sonar_integration: super::sonar_integration::SonarIntegration, /// InfluxDB Configuration - pub influxdb: super::influxdb::InfluxDbConfig, + pub influxdb: Option, /// Option to disable the webserver for headless/CLI operation pub disable_webserver: Option, @@ -139,7 +139,7 @@ impl Default for Config { uisp_integration: super::uisp_integration::UispIntegration::default(), powercode_integration: super::powercode_integration::PowercodeIntegration::default(), sonar_integration: super::sonar_integration::SonarIntegration::default(), - influxdb: super::influxdb::InfluxDbConfig::default(), + influxdb: None, packet_capture_time: 10, queue_check_period_ms: 1000, flows: None, diff --git a/src/rust/lqos_python/src/lib.rs b/src/rust/lqos_python/src/lib.rs index c771d502..47c78fb4 100644 --- a/src/rust/lqos_python/src/lib.rs +++ b/src/rust/lqos_python/src/lib.rs @@ -642,34 +642,49 @@ fn sonar_active_status_ids() -> PyResult> { #[pyfunction] fn influx_db_enabled() -> PyResult { let config = lqos_config::load_config().unwrap(); - Ok(config.influxdb.enable_influxdb) + let Some(config) = config.influxdb.as_ref() else { + return Ok(false); + }; + Ok(config.enable_influxdb) } #[pyfunction] fn influx_db_bucket() -> PyResult { let config = lqos_config::load_config().unwrap(); - let bucket = config.influxdb.bucket.clone(); + let Some(config) = config.influxdb.as_ref() else { + return Ok(String::new()); + }; + let bucket = config.bucket.clone(); Ok(bucket) } #[pyfunction] fn influx_db_org() -> PyResult { let config = lqos_config::load_config().unwrap(); - let org = config.influxdb.org.clone(); + let Some(config) = config.influxdb.as_ref() else { + return Ok(String::new()); + }; + let org = config.org.clone(); Ok(org) } #[pyfunction] fn influx_db_token() -> PyResult { let config = lqos_config::load_config().unwrap(); - let token = config.influxdb.token.clone(); + let Some(config) = config.influxdb.as_ref() else { + return Ok(String::new()); + }; + let token = config.token.clone(); Ok(token) } #[pyfunction] fn influx_db_url() -> PyResult { let config = lqos_config::load_config().unwrap(); - let url = config.influxdb.url.clone(); + let Some(config) = config.influxdb.as_ref() else { + return Ok(String::new()); + }; + let url = config.url.clone(); Ok(url) }