mirror of
https://github.com/pcvolkmer/checkbar.git
synced 2025-04-19 19:16:50 +00:00
Extract response check
This commit is contained in:
parent
80f42de06a
commit
e2f4e8463b
@ -1,6 +1,8 @@
|
||||
use reqwest::Response;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::checker::{CheckResult, CheckState};
|
||||
use crate::config::CheckConfig;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct ActuatorResponse {
|
||||
@ -17,29 +19,22 @@ impl Checker<'_> {
|
||||
}
|
||||
|
||||
pub async fn check(&self) -> CheckResult {
|
||||
let state = match reqwest::get(self.check_config.url.as_str()).await {
|
||||
Ok(r) => {
|
||||
if r.status().is_success() {
|
||||
match r.json::<ActuatorResponse>().await {
|
||||
Ok(ar) => {
|
||||
if ar.status == "UP" {
|
||||
CheckState::Up
|
||||
} else {
|
||||
CheckState::Warn
|
||||
}
|
||||
}
|
||||
_ => CheckState::Warn,
|
||||
}
|
||||
} else {
|
||||
CheckState::Warn
|
||||
}
|
||||
}
|
||||
Err(_) => CheckState::Down,
|
||||
};
|
||||
|
||||
CheckResult {
|
||||
name: self.check_config.name.to_string(),
|
||||
state,
|
||||
state: match reqwest::get(self.check_config.url.as_str()).await {
|
||||
Ok(r) => Self::check_response(r).await,
|
||||
Err(_) => CheckState::Down,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
async fn check_response(response: Response) -> CheckState {
|
||||
if response.status().is_success() {
|
||||
return match response.json::<ActuatorResponse>().await {
|
||||
Ok(ar) if ar.status == "UP" => CheckState::Up,
|
||||
_ => CheckState::Warn,
|
||||
};
|
||||
}
|
||||
CheckState::Warn
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
use reqwest::Response;
|
||||
|
||||
use crate::checker::{CheckResult, CheckState};
|
||||
use crate::config::CheckConfig;
|
||||
|
||||
@ -11,20 +13,20 @@ impl Checker<'_> {
|
||||
}
|
||||
|
||||
pub async fn check(&self) -> CheckResult {
|
||||
let state = match reqwest::get(self.check_config.url.as_str()).await {
|
||||
Ok(r) => {
|
||||
if r.status().is_success() {
|
||||
CheckResult {
|
||||
name: self.check_config.name.to_string(),
|
||||
state: match reqwest::get(self.check_config.url.as_str()).await {
|
||||
Ok(r) => Self::check_response(r).await,
|
||||
Err(_) => CheckState::Down,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
async fn check_response(response: Response) -> CheckState {
|
||||
if response.status().is_success() {
|
||||
CheckState::Up
|
||||
} else {
|
||||
CheckState::Warn
|
||||
}
|
||||
}
|
||||
Err(_) => CheckState::Down,
|
||||
};
|
||||
|
||||
CheckResult {
|
||||
name: self.check_config.name.to_string(),
|
||||
state,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user