Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle new CheckResult #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading