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