Skip to content

Commit

Permalink
add entities / message for test alerter
Browse files Browse the repository at this point in the history
  • Loading branch information
mbecker20 committed Jan 12, 2025
1 parent 56f9e88 commit 3fb36f1
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bin/core/src/alert/discord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ pub async fn send_alert(
) -> anyhow::Result<()> {
let level = fmt_level(alert.level);
let content = match &alert.data {
AlertData::Test { id, name } => {
let link = resource_link(ResourceTargetVariant::Alerter, id);
format!(
"{level} | If you see this message, then Alerter **{name}** is **working**\n{link}"
)
}
AlertData::ServerUnreachable {
id,
name,
Expand Down
16 changes: 16 additions & 0 deletions bin/core/src/alert/slack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ pub async fn send_alert(
) -> anyhow::Result<()> {
let level = fmt_level(alert.level);
let (text, blocks): (_, Option<_>) = match &alert.data {
AlertData::Test { id, name } => {
let text = format!(
"{level} | If you see this message, then Alerter *{name}* is *working*"
);
let blocks = vec![
Block::header(level),
Block::section(format!(
"If you see this message, then Alerter *{name}* is *working*"
)),
Block::section(resource_link(
ResourceTargetVariant::Alerter,
id,
)),
];
(text, blocks.into())
}
AlertData::ServerUnreachable {
id,
name,
Expand Down
29 changes: 29 additions & 0 deletions client/core/rs/src/api/execute/alerter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use clap::Parser;
use derive_empty_traits::EmptyTraits;
use resolver_api::Resolve;
use serde::{Deserialize, Serialize};
use typeshare::typeshare;

use crate::entities::update::Update;

use super::KomodoExecuteRequest;

/// Tests an Alerters ability to reach the configured endpoint. Response: [Update]
#[typeshare]
#[derive(
Serialize,
Deserialize,
Debug,
Clone,
PartialEq,
Resolve,
EmptyTraits,
Parser,
)]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(serror::Error)]
pub struct TestAlerter {
/// Name or id
pub alerter: String,
}
1 change: 1 addition & 0 deletions client/core/rs/src/api/execute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use strum::{Display, EnumString};
use typeshare::typeshare;

mod action;
mod alerter;
mod build;
mod deployment;
mod procedure;
Expand Down
9 changes: 9 additions & 0 deletions client/core/rs/src/entities/alert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ pub enum AlertData {
/// A null alert
None {},

/// The user triggered a test of the
/// Alerter configuration.
Test {
/// The id of the alerter
id: String,
/// The name of the alerter
name: String,
},

/// A server could not be reached.
ServerUnreachable {
/// The id of the server
Expand Down
1 change: 1 addition & 0 deletions client/core/rs/src/entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@ pub enum Operation {
UpdateAlerter,
RenameAlerter,
DeleteAlerter,
TestAlerter,

// server template
CreateServerTemplate,
Expand Down

1 comment on commit 3fb36f1

@FoxxMD
Copy link
Contributor

@FoxxMD FoxxMD commented on 3fb36f1 Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Please sign in to comment.