mirror of
https://github.com/moghtech/komodo.git
synced 2026-05-03 12:03:21 -05:00
work on alerting logic
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user