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

This commit is contained in:
Herbert Wolverson 2025-01-02 09:24:43 -06:00
parent 758035d864
commit c0a43bc771
4 changed files with 33 additions and 13 deletions

View File

@ -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(())
}

View File

@ -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;

View File

@ -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>,
@ -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,

View File

@ -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)
}