work on alerting logic

This commit is contained in:
mbecker20
2023-08-13 01:54:14 -04:00
parent 7aa048a512
commit f1639126df
11 changed files with 380 additions and 292 deletions

View File

@@ -1,15 +1,49 @@
use derive_variants::EnumVariants;
use mungos::{
derive::{MungosIndexed, StringObjectId},
mongodb::bson::{doc, serde_helpers::hex_string_as_object_id},
};
use serde::{Deserialize, Serialize};
use typeshare::typeshare;
use crate::{MongoId, I64};
use super::{
deployment::DockerContainerState,
server::stats::{StatsState, SystemProcess},
update::ResourceTarget,
};
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, EnumVariants)]
#[variant_derive(Serialize, Deserialize, Debug, Clone, Copy)]
#[derive(Serialize, Deserialize, Debug, Clone, Default, MungosIndexed, StringObjectId)]
#[doc_index(doc! { "target.type": 1 })]
#[sparse_doc_index(doc! { "target.id": 1 })]
pub struct AlertRecord {
#[serde(
default,
rename = "_id",
skip_serializing_if = "String::is_empty",
with = "hex_string_as_object_id"
)]
pub id: MongoId,
#[index]
pub start_ts: I64,
#[index]
pub resolved: bool,
#[index]
pub alert_type: AlertVariant,
pub target: ResourceTarget,
pub alert: Alert,
pub resolved_ts: Option<I64>,
}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, EnumVariants, MungosIndexed)]
#[variant_derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[serde(tag = "type", content = "data")]
pub enum Alert {
ServerUnreachable {
@@ -58,4 +92,18 @@ pub enum Alert {
from: DockerContainerState,
to: DockerContainerState,
},
None {},
}
impl Default for Alert {
fn default() -> Self {
Alert::None {}
}
}
#[allow(clippy::derivable_impls)]
impl Default for AlertVariant {
fn default() -> Self {
AlertVariant::None
}
}