fixed net
parent
847fd1595d
commit
60c31e1a5f
|
|
@ -93,17 +93,22 @@ impl<'a> ApiPoll<'a> {
|
||||||
// exporter: Arc<Exporter>
|
// exporter: Arc<Exporter>
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
// processing metrics
|
// processing metrics
|
||||||
let mut req = Client::new()
|
// let mut req = Client::new()
|
||||||
.get(&metrics.url);
|
// // .user_agent("api_grub/integration_module")
|
||||||
|
// .get(&metrics.url);
|
||||||
|
let client = Client::builder()
|
||||||
|
.user_agent("api_grub/integration_module");
|
||||||
|
let mut req = client.build().unwrap().get(&metrics.url);
|
||||||
|
|
||||||
let login = creds.endpoint.login.clone();
|
let login = creds.endpoint.login.clone();
|
||||||
let password = creds.endpoint.password.clone();
|
let password = creds.endpoint.password.clone();
|
||||||
let api_key = creds.endpoint.api_key.clone();
|
let api_key = creds.endpoint.api_key.clone();
|
||||||
if !login.is_empty() && !password.is_empty() {
|
// if !login.is_empty() && !password.is_empty() {
|
||||||
dbg!("kjgbkasgksjd");
|
// dbg!("kjgbkasgksjd");
|
||||||
req = req.basic_auth(login, Some(password));
|
// req = req.basic_auth(login, Some(password));
|
||||||
}
|
// }
|
||||||
if !api_key.is_empty() {
|
if !api_key.is_empty() {
|
||||||
req = req.bearer_auth(&api_key);
|
// req = req.bearer_auth(&api_key);
|
||||||
// req = req.header("authorization", "bearer ");
|
// req = req.header("authorization", "bearer ");
|
||||||
|
|
||||||
req = req.header("accept", "application/json");
|
req = req.header("accept", "application/json");
|
||||||
|
|
@ -111,7 +116,7 @@ impl<'a> ApiPoll<'a> {
|
||||||
|
|
||||||
// req = req.query(&["Bearer", "6fe8b0db-62b4-4065-9c1e-441ec4228341.9acec20bd17d7178f332896f8c006452877a22b8627d089105ed39c5baef9711"])
|
// req = req.query(&["Bearer", "6fe8b0db-62b4-4065-9c1e-441ec4228341.9acec20bd17d7178f332896f8c006452877a22b8627d089105ed39c5baef9711"])
|
||||||
}
|
}
|
||||||
dbg!(&req);
|
// dbg!(&req);
|
||||||
// let (client, res) = req.build_split();
|
// let (client, res) = req.build_split();
|
||||||
// let res = res.unwrap();
|
// let res = res.unwrap();
|
||||||
// res.url_mut().is_special()
|
// res.url_mut().is_special()
|
||||||
|
|
@ -124,19 +129,23 @@ impl<'a> ApiPoll<'a> {
|
||||||
|
|
||||||
match req.send().await {
|
match req.send().await {
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
dbg!(&resp);
|
// dbg!(&resp.text().await);
|
||||||
if let Ok(response) = resp.text().await {
|
if let Ok(response) = resp.text().await {
|
||||||
match serde_json::from_str::<Value>(&response) {
|
match serde_json::to_value(&response) {
|
||||||
Err(er) => {error!("Bad JSON in response. Error: {}", er);},
|
Err(er) => {
|
||||||
|
error!("Bad JSON in response. Error: {}", er);
|
||||||
|
},
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let endpoint_name = &metrics.name;
|
let endpoint_name = &metrics.name;
|
||||||
let preproc = JsonParser::parse(&metrics.measure, &response);
|
let preproc = JsonParser::parse(&metrics.measure, &response);
|
||||||
let metrics: String = serde_json::from_value(preproc.clone())
|
// dbg!(serde_json::to_string_pretty(&preproc));
|
||||||
.unwrap_or({
|
|
||||||
|
let metrics = serde_json::to_string_pretty(&preproc)
|
||||||
|
.unwrap_or_else(|_| {
|
||||||
error!("Cannot parse grabbed metrics data to String");
|
error!("Cannot parse grabbed metrics data to String");
|
||||||
String::from(r#""value" : null"#)
|
String::from(r#""value" : null"#)
|
||||||
});
|
});
|
||||||
dbg!(&metrics);
|
// dbg!(&metrics);
|
||||||
match Exporter::export_metrics(&metrics).await {
|
match Exporter::export_metrics(&metrics).await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
info!("Successfully imported metrics data to Prometheus");
|
info!("Successfully imported metrics data to Prometheus");
|
||||||
|
|
|
||||||
|
|
@ -258,4 +258,5 @@ pub mod v3 {
|
||||||
endpoint_name: String,
|
endpoint_name: String,
|
||||||
metrics: Value,
|
metrics: Value,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue