Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE #624 - the Influx config section is now optional. #625

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/rust/lqos_config/src/etc/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(())
}
2 changes: 1 addition & 1 deletion src/rust/lqos_config/src/etc/v15/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/rust/lqos_config/src/etc/v15/top_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub struct Config {
pub sonar_integration: super::sonar_integration::SonarIntegration,

/// InfluxDB Configuration
pub influxdb: super::influxdb::InfluxDbConfig,
pub influxdb: Option<super::influxdb::InfluxDbConfig>,

/// Option to disable the webserver for headless/CLI operation
pub disable_webserver: Option<bool>,
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 20 additions & 5 deletions src/rust/lqos_python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,34 +642,49 @@ fn sonar_active_status_ids() -> PyResult<Vec<String>> {
#[pyfunction]
fn influx_db_enabled() -> PyResult<bool> {
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<String> {
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<String> {
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<String> {
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<String> {
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)
}

Expand Down
Loading