Skip to content

Commit

Permalink
Handle new CheckResult
Browse files Browse the repository at this point in the history
  • Loading branch information
Threated committed Oct 10, 2023
1 parent 4719cf7 commit 83dbe05
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/bridgehead_health.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use beam_lib::{TaskRequest, FailureStrategy, MsgId, AppId, TaskResult};
use clap::Args;
use bridgehead_monitoring_lib::Check;
use bridgehead_monitoring_lib::{Check, CheckResult};
use anyhow::{Result, bail};
use reqwest::{Url, header, StatusCode};
use serde_json::Value;
Expand Down Expand Up @@ -68,10 +68,20 @@ pub async fn check_bridgehead(
if res.status() != StatusCode::OK {
bail!("Failed to retrive task: Got status {}", res.status());
}
let results = res.json::<Vec<TaskResult<Vec<String>>>>().await?.pop();
match results {
Some(task) => checks.into_iter().zip(task.body).for_each(|(check, result)| println!("{check}: {result}")),
None => bail!("Got no results from task"),
let results = res.json::<Vec<TaskResult<Vec<CheckResult>>>>().await?.pop();
let Some(task) = results else {
bail!("Got no results from task")
};
Ok(IcingaCode::Ok)
let mut worst_case = IcingaCode::Ok;
checks
.into_iter()
.zip(task.body)
.map(|(check, result)| match result {
CheckResult::Ok(res) => (check, res),
CheckResult::Err(e) | CheckResult::Unexpected(e) => {
worst_case = IcingaCode::Warning;
(check, e)
}
}).for_each(|(check, res)| println!("{check}: {res}"));
Ok(worst_case)
}

0 comments on commit 83dbe05

Please sign in to comment.