v2 completed, getting + preproc
parent
70b7d41f87
commit
72c59dbce9
|
|
@ -1,6 +1,6 @@
|
|||
// module to handle unix-socket connection + pulling info from api
|
||||
use anyhow::{Error, Result};
|
||||
use integr_structs::api::ApiConfigV2;
|
||||
use integr_structs::api::{ApiConfigV2, ProcessedEndpoint};
|
||||
use log::{error, info};
|
||||
use tokio::sync::mpsc::Receiver;
|
||||
use tokio::time::{sleep, Duration};
|
||||
|
|
@ -68,6 +68,10 @@ impl<'a> ApiPoll<'a> {
|
|||
return;
|
||||
}
|
||||
if let Ok(text) = resp.text().await {
|
||||
//
|
||||
let a = ProcessedEndpoint::from_target_response(&text, &point);
|
||||
println!("{}", a.unwrap());
|
||||
//
|
||||
let mut buffer = buffer.lock().await;
|
||||
buffer.push(text);
|
||||
} else {
|
||||
|
|
@ -149,7 +153,7 @@ mod net_unittests {
|
|||
#[test]
|
||||
async fn check_api_poll_is_default() {
|
||||
let mut conf1 = ApiConfigV2::default();
|
||||
let mut poll = ApiPoll::new(&mut conf1).await;
|
||||
let poll = ApiPoll::new(&mut conf1).await;
|
||||
assert!(poll.is_default().await)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,5 +4,6 @@ version = "0.1.0"
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.95"
|
||||
serde = { version = "1.0.217", features = ["derive"] }
|
||||
serde_json = "1.0.135"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde_json::Value;
|
||||
use serde_json::{ to_string_pretty, Value };
|
||||
use anyhow::Result;
|
||||
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
|
|
@ -90,7 +90,7 @@ impl ApiConfigV2 {
|
|||
}
|
||||
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Template {
|
||||
pub id : String,
|
||||
pub name : String,
|
||||
|
|
@ -117,6 +117,31 @@ pub struct ProcessedEndpoint {
|
|||
id : String,
|
||||
name : String,
|
||||
url : String,
|
||||
method : String,
|
||||
#[serde(default)]
|
||||
metrics : HashMap<String, Value>
|
||||
metrics : HashMap<String, Value>,
|
||||
}
|
||||
|
||||
impl ProcessedEndpoint {
|
||||
pub fn new(id: &str, name: &str, url: &str, method: &str, metrics: HashMap<String, Value>) -> Self {
|
||||
ProcessedEndpoint {
|
||||
id : id.to_owned(),
|
||||
name : name.to_owned(),
|
||||
url : url.to_owned(),
|
||||
method : method.to_owned(),
|
||||
metrics : metrics,
|
||||
}
|
||||
}
|
||||
pub fn from_target_response(response: &str, keys: &Template) -> Result<String> {
|
||||
let mut hm: HashMap<String, Value> = HashMap::new();
|
||||
let mut response: Value = serde_json::from_str(response)?;
|
||||
|
||||
let _ = keys.measure.iter()
|
||||
.map(|key| (key, response[key].take()))
|
||||
.for_each(|(key, value)| {
|
||||
hm.insert(key.clone(), value);
|
||||
});
|
||||
let val = ProcessedEndpoint::new(&keys.id, &keys.name, &keys.url, &keys.method,hm);
|
||||
Ok(to_string_pretty(&val)?)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue