Compare commits

..

3 Commits

Author SHA1 Message Date
prplV efb00dcf5e preproc setting up 2025-01-21 17:25:42 +03:00
prplV dd2973924a v2 structs 2025-01-21 17:24:33 +03:00
prplV d3fcfae15b new valid structs for sharing between services 2025-01-21 16:31:10 +03:00
7 changed files with 134 additions and 4 deletions

View File

@ -10,6 +10,6 @@
| Crate (submodule) | Progress |
|---|---|
|`api-grub` | ✅✅✅✅✅✅✅🔲🔲🔲 |
|`config-delivery` | ✅✅✅✅🔲🔲🔲🔲🔲🔲 |
|`config-delivery` | ✅✅✅✅✅✅🔲🔲🔲🔲 |
|`integrs-structs` | ✅✅✅✅✅✅🔲🔲🔲🔲 |
|`preproc` | 🔲🔲🔲🔲🔲🔲🔲🔲🔲🔲 |
|`preproc` | ✅✅✅🔲🔲🔲🔲🔲🔲🔲 |

View File

@ -1,4 +1,7 @@
use std::collections::HashMap;
use serde::{Serialize, Deserialize};
use serde_json::Value;
#[derive(Serialize, Deserialize, Debug)]
@ -22,3 +25,35 @@ impl Default for ApiConfig {
}
}
}
// v2
#[derive(Serialize, Deserialize, Debug)]
pub struct ApiConfigV2 {
id : u64,
#[serde(default)]
template : Vec<Template>,
ip_address : String,
login : Option<String>,
pass : Option<String>,
api_key : Option<String>,
period : u32, // if "0" -> inf
timeout : u32, // if "0" -> no-delay
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Template {
id : String,
name : String,
url : String,
#[serde(default)]
measure : Vec<String>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct ProcessedEndpoint {
id : String,
name : String,
url : String,
#[serde(default)]
metrics : HashMap<String, Value>
}

View File

@ -4,3 +4,11 @@ version = "0.1.0"
edition = "2021"
[dependencies]
anyhow = "1.0.95"
chrono = "0.4.39"
dotenv = "0.15.0"
env_logger = "0.11.6"
log = "0.4.25"
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.137"
tokio = { version = "1.43.0", features = ["full"] }

View File

@ -0,0 +1,21 @@
// mod for prpeproc config pulling and updating
#[cfg(test)]
mod config_unittests {
use tokio::test;
#[test]
async fn create_unix_socket_server() { assert!(true) }
#[test]
async fn verify_on_valid_config() { assert!(true) }
#[test]
async fn verify_on_invalid_config() { assert!(true) }
}

View File

@ -0,0 +1,50 @@
use chrono::Local;
use env_logger::Builder;
use log::LevelFilter;
use std::io::Write;
use anyhow::Result;
use log::info;
pub async fn setup_logger() -> Result<()> {
Builder::new()
.format(move |buf, record| {
writeln!(
buf,
"|{}| {} [{}] - {}",
"config-delivery",
Local::now().format("%d-%m-%Y %H:%M:%S"),
record.level(),
record.args(),
)
})
.filter(None, LevelFilter::Info)
.target(env_logger::Target::Stdout)
.init();
info!("Logger configured");
Ok(())
}
#[cfg(test)]
mod logger_unittests {
use tokio::test;
use super::*;
#[test]
async fn check_logger_builder() {
Builder::new()
.format(move |buf, record| {
writeln!(
buf,
"|{}| {} [{}] - {}",
"config-delivery",
Local::now().format("%d-%m-%Y %H:%M:%S"),
record.level(),
record.args(),
)
})
.filter(None, LevelFilter::Info)
.target(env_logger::Target::Stdout)
.init();
}
}

View File

@ -1,3 +1,18 @@
fn main() {
println!("Hello, world!");
mod config;
mod transform;
mod logger;
use logger::setup_logger;
use dotenv::dotenv;
use anyhow::Result;
use log::info;
#[tokio::main(flavor = "multi_thread")]
async fn main() -> Result<()>{
let _ = setup_logger().await?;
info!("Pulling env vars from .env file if exists ...");
dotenv().ok();
Ok(())
}

View File

@ -0,0 +1 @@
// mod for preproccessing and transfering to the CM metrics data