Add the beginnings of the Sonar integration into the config system. Add defaults for every Python field to reduce the chances of getting a partial config.

This commit is contained in:
Herbert Wolverson
2024-01-27 09:30:54 -06:00
parent a24c51065f
commit ed5cbbc29c
6 changed files with 132 additions and 45 deletions

View File

@@ -86,6 +86,8 @@ fn do_migration_14_to_15(
migrate_integration_common(python_config, &mut new_config)?;
migrate_spylnx(python_config, &mut new_config)?;
migrate_uisp(python_config, &mut new_config)?;
migrate_powercode(python_config, &mut new_config)?;
migrate_sonar(python_config, &mut new_config)?;
migrate_queues( python_config, &mut new_config)?;
new_config.validate().unwrap(); // Left as an upwrap because this should *never* happen
@@ -228,6 +230,27 @@ fn migrate_spylnx(
Ok(())
}
fn migrate_powercode(
python_config: &PythonMigration,
new_config: &mut Config,
) -> Result<(), MigrationError> {
new_config.powercode_integration.enable_powercode = python_config.automatic_import_powercode;
new_config.powercode_integration.powercode_api_url = python_config.powercode_api_url.clone();
new_config.powercode_integration.powercode_api_key = python_config.powercode_api_key.clone();
Ok(())
}
fn migrate_sonar(
python_config: &PythonMigration,
new_config: &mut Config,
) -> Result<(), MigrationError> {
new_config.sonar_integration.enable_sonar = python_config.automatic_import_sonar;
new_config.sonar_integration.sonar_api_url = python_config.sonar_api_url.clone();
new_config.sonar_integration.sonar_api_key = python_config.sonar_api_key.clone();
new_config.sonar_integration.snmp_community = python_config.snmp_community.clone();
Ok(())
}
fn migrate_uisp(
python_config: &PythonMigration,
new_config: &mut Config,

View File

@@ -93,59 +93,90 @@ pub struct PythonMigration {
pub api_password: String,
pub api_host_ip: String,
pub api_host_port: u32,
pub automatic_import_powercode: bool,
pub powercode_api_key: String,
pub powercode_api_url: String,
pub automatic_import_sonar: bool,
pub sonar_api_url: String,
pub sonar_api_key: String,
pub snmp_community: String,
// TODO: It isn't clear what types `sonar_api_key,sonar_airmax_ap_model_ids,sonar_active_status_ids,sonar_ltu_ap_model_ids`
// are supposed to be.
// TODO: httpRestIntegrationConfig
}
impl PythonMigration {
fn parse(cfg: &mut Self, py: &Python) -> Result<(), PythonMigrationError> {
cfg.sqm = from_python(&py, "sqm")?;
cfg.monitor_only_mode = from_python(&py, "monitorOnlyMode")?;
cfg.sqm = from_python(&py, "sqm").unwrap_or("cake diffserv4".to_string());
cfg.monitor_only_mode = from_python(&py, "monitorOnlyMode").unwrap_or(false);
cfg.upstream_bandwidth_capacity_download_mbps =
from_python(&py, "upstreamBandwidthCapacityDownloadMbps")?;
from_python(&py, "upstreamBandwidthCapacityDownloadMbps").unwrap_or(1000);
cfg.upstream_bandwidth_capacity_upload_mbps =
from_python(&py, "upstreamBandwidthCapacityUploadMbps")?;
cfg.generated_pn_download_mbps = from_python(&py, "generatedPNDownloadMbps")?;
cfg.generated_pn_upload_mbps = from_python(&py, "generatedPNUploadMbps")?;
cfg.interface_a = from_python(&py, "interfaceA")?;
cfg.interface_b = from_python(&py, "interfaceB")?;
from_python(&py, "upstreamBandwidthCapacityUploadMbps").unwrap_or(1000);
cfg.generated_pn_download_mbps = from_python(&py, "generatedPNDownloadMbps").unwrap_or(1000);
cfg.generated_pn_upload_mbps = from_python(&py, "generatedPNUploadMbps").unwrap_or(1000);
cfg.interface_a = from_python(&py, "interfaceA").unwrap_or("eth1".to_string());
cfg.interface_b = from_python(&py, "interfaceB").unwrap_or("eth2".to_string());
cfg.queue_refresh_interval_mins = from_python(&py, "queueRefreshIntervalMins").unwrap_or(15);
cfg.on_a_stick = from_python(&py, "OnAStick")?;
cfg.stick_vlan_a = from_python(&py, "StickVlanA")?;
cfg.stick_vlan_b = from_python(&py, "StickVlanB")?;
cfg.enable_actual_shell_commands = from_python(&py, "enableActualShellCommands")?;
cfg.run_shell_commands_as_sudo = from_python(&py, "runShellCommandsAsSudo")?;
cfg.queues_available_override = from_python(&py, "queuesAvailableOverride")?;
cfg.use_bin_packing_to_balance_cpu = from_python(&py, "useBinPackingToBalanceCPU")?;
cfg.influx_db_enabled = from_python(&py, "influxDBEnabled")?;
cfg.influx_db_url = from_python(&py, "influxDBurl")?;
cfg.infux_db_bucket = from_python(&py, "influxDBBucket")?;
cfg.influx_db_org = from_python(&py, "influxDBOrg")?;
cfg.influx_db_token = from_python(&py, "influxDBtoken")?;
cfg.circuit_name_use_address = from_python(&py, "circuitNameUseAddress")?;
cfg.overwrite_network_json_always = from_python(&py, "overwriteNetworkJSONalways")?;
cfg.ignore_subnets = from_python(&py, "ignoreSubnets")?;
cfg.allowed_subnets = from_python(&py, "allowedSubnets")?;
cfg.automatic_import_splynx = from_python(&py, "automaticImportSplynx")?;
cfg.splynx_api_key = from_python(&py, "splynx_api_key")?;
cfg.spylnx_api_secret = from_python(&py, "splynx_api_secret")?;
cfg.spylnx_api_url = from_python(&py, "splynx_api_url")?;
cfg.automatic_import_uisp = from_python(&py, "automaticImportUISP")?;
cfg.uisp_auth_token = from_python(&py, "uispAuthToken")?;
cfg.uisp_base_url = from_python(&py, "UISPbaseURL")?;
cfg.uisp_site = from_python(&py, "uispSite")?;
cfg.uisp_strategy = from_python(&py, "uispStrategy")?;
cfg.uisp_suspended_strategy = from_python(&py, "uispSuspendedStrategy")?;
cfg.airmax_capacity = from_python(&py, "airMax_capacity")?;
cfg.ltu_capacity = from_python(&py, "ltu_capacity")?;
cfg.exclude_sites = from_python(&py, "excludeSites")?;
cfg.find_ipv6_using_mikrotik = from_python(&py, "findIPv6usingMikrotik")?;
cfg.bandwidth_overhead_factor = from_python(&py, "bandwidthOverheadFactor")?;
cfg.committed_bandwidth_multiplier = from_python(&py, "committedBandwidthMultiplier")?;
cfg.exception_cpes = from_python(&py, "exceptionCPEs")?;
cfg.api_username = from_python(&py, "apiUsername")?;
cfg.api_password = from_python(&py, "apiPassword")?;
cfg.api_host_ip = from_python(&py, "apiHostIP")?;
cfg.api_host_port = from_python(&py, "apiHostPost")?;
cfg.on_a_stick = from_python(&py, "OnAStick").unwrap_or(false);
cfg.stick_vlan_a = from_python(&py, "StickVlanA").unwrap_or(0);
cfg.stick_vlan_b = from_python(&py, "StickVlanB").unwrap_or(0);
cfg.enable_actual_shell_commands = from_python(&py, "enableActualShellCommands").unwrap_or(true);
cfg.run_shell_commands_as_sudo = from_python(&py, "runShellCommandsAsSudo").unwrap_or(false);
cfg.queues_available_override = from_python(&py, "queuesAvailableOverride").unwrap_or(0);
cfg.use_bin_packing_to_balance_cpu = from_python(&py, "useBinPackingToBalanceCPU").unwrap_or(false);
// Influx
cfg.influx_db_enabled = from_python(&py, "influxDBEnabled").unwrap_or(false);
cfg.influx_db_url = from_python(&py, "influxDBurl").unwrap_or("http://localhost:8086".to_string());
cfg.infux_db_bucket = from_python(&py, "influxDBBucket").unwrap_or("libreqos".to_string());
cfg.influx_db_org = from_python(&py, "influxDBOrg").unwrap_or("Your ISP Name Here".to_string());
cfg.influx_db_token = from_python(&py, "influxDBtoken").unwrap_or("".to_string());
// Common
cfg.circuit_name_use_address = from_python(&py, "circuitNameUseAddress").unwrap_or(true);
cfg.overwrite_network_json_always = from_python(&py, "overwriteNetworkJSONalways").unwrap_or(false);
cfg.ignore_subnets = from_python(&py, "ignoreSubnets").unwrap_or(vec!["192.168.0.0/16".to_string()]);
cfg.allowed_subnets = from_python(&py, "allowedSubnets").unwrap_or(vec!["100.64.0.0/10".to_string()]);
cfg.exclude_sites = from_python(&py, "excludeSites").unwrap_or(vec![]);
cfg.find_ipv6_using_mikrotik = from_python(&py, "findIPv6usingMikrotik").unwrap_or(false);
// Spylnx
cfg.automatic_import_splynx = from_python(&py, "automaticImportSplynx").unwrap_or(false);
cfg.splynx_api_key = from_python(&py, "splynx_api_key").unwrap_or("Your API Key Here".to_string());
cfg.spylnx_api_secret = from_python(&py, "splynx_api_secret").unwrap_or("Your API Secret Here".to_string());
cfg.spylnx_api_url = from_python(&py, "splynx_api_url").unwrap_or("https://your.splynx.url/api/v1".to_string());
// UISP
cfg.automatic_import_uisp = from_python(&py, "automaticImportUISP").unwrap_or(false);
cfg.uisp_auth_token = from_python(&py, "uispAuthToken").unwrap_or("Your API Token Here".to_string());
cfg.uisp_base_url = from_python(&py, "UISPbaseURL").unwrap_or("https://your.uisp.url".to_string());
cfg.uisp_site = from_python(&py, "uispSite").unwrap_or("Your parent site name here".to_string());
cfg.uisp_strategy = from_python(&py, "uispStrategy").unwrap_or("full".to_string());
cfg.uisp_suspended_strategy = from_python(&py, "uispSuspendedStrategy").unwrap_or("none".to_string());
cfg.airmax_capacity = from_python(&py, "airMax_capacity").unwrap_or(0.65);
cfg.ltu_capacity = from_python(&py, "ltu_capacity").unwrap_or(0.9);
cfg.bandwidth_overhead_factor = from_python(&py, "bandwidthOverheadFactor").unwrap_or(1.0);
cfg.committed_bandwidth_multiplier = from_python(&py, "committedBandwidthMultiplier").unwrap_or(0.98);
cfg.exception_cpes = from_python(&py, "exceptionCPEs").unwrap_or(HashMap::new());
// API
cfg.api_username = from_python(&py, "apiUsername").unwrap_or("testUser".to_string());
cfg.api_password = from_python(&py, "apiPassword").unwrap_or("testPassword".to_string());
cfg.api_host_ip = from_python(&py, "apiHostIP").unwrap_or("127.0.0.1".to_string());
cfg.api_host_port = from_python(&py, "apiHostPost").unwrap_or(5000);
// Powercode
cfg.automatic_import_powercode = from_python(&py, "automaticImportPowercode").unwrap_or(false);
cfg.powercode_api_key = from_python(&py,"powercode_api_key").unwrap_or("".to_string());
cfg.powercode_api_url = from_python(&py,"powercode_api_url").unwrap_or("".to_string());
// Sonar
cfg.automatic_import_sonar = from_python(&py, "automaticImportSonar").unwrap_or(false);
cfg.sonar_api_key = from_python(&py, "sonar_api_key").unwrap_or("".to_string());
cfg.sonar_api_url = from_python(&py, "sonar_api_url").unwrap_or("".to_string());
cfg.snmp_community = from_python(&py, "snmp_community").unwrap_or("public".to_string());
Ok(())
}

View File

@@ -84,3 +84,9 @@ use_ptmp_as_parent = false
enable_powercode = false
powercode_api_key = ""
powercode_api_url = ""
[sonar_integration]
enable_sonar = false
sonar_api_key = ""
sonar_api_url = ""
snmp_community = "public"

View File

@@ -12,6 +12,7 @@ mod ip_ranges;
mod spylnx_integration;
mod uisp_integration;
mod powercode_integration;
mod sonar_integration;
pub use bridge::*;
pub use long_term_stats::LongTermStats;
pub use tuning::Tunables;

View File

@@ -0,0 +1,22 @@
use serde::{Serialize, Deserialize};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SonarIntegration {
pub enable_sonar: bool,
pub sonar_api_url: String,
pub sonar_api_key: String,
pub snmp_community: String,
// TODO: It isn't clear what types `sonar_api_key,sonar_airmax_ap_model_ids,sonar_active_status_ids,sonar_ltu_ap_model_ids`
// are supposed to be.
}
impl Default for SonarIntegration {
fn default() -> Self {
SonarIntegration {
enable_sonar: false,
sonar_api_url: "".to_string(),
sonar_api_key: "".to_string(),
snmp_community: "public".to_string(),
}
}
}

View File

@@ -62,6 +62,9 @@ pub struct Config {
/// Powercode Integration
pub powercode_integration: super::powercode_integration::PowercodeIntegration,
/// Sonar Integration
pub sonar_integration: super::sonar_integration::SonarIntegration,
}
impl Config {
@@ -123,6 +126,7 @@ impl Default for Config {
spylnx_integration: super::spylnx_integration::SplynxIntegration::default(),
uisp_integration: super::uisp_integration::UispIntegration::default(),
powercode_integration: super::powercode_integration::PowercodeIntegration::default(),
sonar_integration: super::sonar_integration::SonarIntegration::default(),
packet_capture_time: 10,
queue_check_period_ms: 1000,
}