1pub use async_trait::async_trait;
2
3#[async_trait]
5pub trait Checker: Send + Sync {
6 async fn check(&self) -> CheckResponse;
8}
9
10#[derive(Debug)]
12pub struct CheckResponse {
13 health: Health,
14 output: String,
15 action: Option<String>,
16 impact: Option<String>,
17}
18
19impl CheckResponse {
20 pub fn healthy(output: &str) -> Self {
22 CheckResponse {
23 health: Health::Healthy,
24 output: output.to_owned(),
25 action: None,
26 impact: None,
27 }
28 }
29
30 pub fn degraded(output: &str, action: &str) -> Self {
32 CheckResponse {
33 health: Health::Degraded,
34 output: output.to_owned(),
35 action: Some(action.to_owned()),
36 impact: None,
37 }
38 }
39
40 pub fn unhealthy(output: &str, action: &str, impact: &str) -> Self {
42 CheckResponse {
43 health: Health::Unhealthy,
44 output: output.to_owned(),
45 action: Some(action.to_owned()),
46 impact: Some(impact.to_owned()),
47 }
48 }
49
50 pub fn health(&self) -> Health {
52 self.health
53 }
54
55 pub fn output(&self) -> &str {
57 &self.output
58 }
59
60 pub fn action(&self) -> Option<&str> {
62 self.action.as_ref().map(String::as_ref)
63 }
64
65 pub fn impact(&self) -> Option<&str> {
67 self.impact.as_ref().map(String::as_ref)
68 }
69}
70
71#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
73pub enum Health {
74 Healthy,
75 Degraded,
76 Unhealthy,
77}
78
79impl Into<&'static str> for Health {
80 fn into(self) -> &'static str {
81 match self {
82 Health::Healthy => "healthy",
83 Health::Degraded => "degraded",
84 Health::Unhealthy => "unhealthy",
85 }
86 }
87}