feat: implement StdoutNotificationActor for get command
This commit is contained in:
16
src/actors/driven/for_sending_notification/print.rs
Normal file
16
src/actors/driven/for_sending_notification/print.rs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
use crate::app::ports::driven::ForSendingNotification;
|
||||||
|
|
||||||
|
pub struct StdoutNotificationActor;
|
||||||
|
|
||||||
|
impl StdoutNotificationActor {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
StdoutNotificationActor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ForSendingNotification for StdoutNotificationActor {
|
||||||
|
fn send_notification(&self, message: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
println!("Sending notification: {message}");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,20 +4,21 @@ use system_monitor::SystemMonitor;
|
|||||||
|
|
||||||
use crate::{actors, adapters, app};
|
use crate::{actors, adapters, app};
|
||||||
|
|
||||||
pub fn get_service() -> app::service::Service {
|
pub fn get_run_service() -> app::service::Service {
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
let notifier = DiscordNotifier::new(
|
let notifier = DiscordNotifier::new(
|
||||||
std::env::var("DISCORD_WEBHOOK").expect("DISCORD_WEBHOOK environment variable not set"),
|
std::env::var("DISCORD_WEBHOOK").expect("DISCORD_WEBHOOK environment variable not set"),
|
||||||
"System Monitor".to_string(),
|
"System Monitor".to_string(),
|
||||||
"https://cdn.shopify.com/s/files/1/0262/1423/6212/files/Lord_of_the_Rings_eye_of_Sauron_-_Ghtic.com_-_Blog.png?v=1579680018".to_string(),
|
"https://cdn.shopify.com/s/files/1/0262/1423/6212/files/Lord_of_the_Rings_eye_of_Sauron_-_Ghtic.com_-_Blog.png?v=1579680018".to_string(),
|
||||||
);
|
);
|
||||||
let monitor =
|
|
||||||
SystemMonitor::new(system_monitor::resource_threshold::get_default_resource_thresholds());
|
|
||||||
|
|
||||||
let discord_adapter =
|
let discord_adapter =
|
||||||
adapters::driven::for_sending_notification::discord_client::DiscordAdapter::new(notifier);
|
adapters::driven::for_sending_notification::discord_client::DiscordAdapter::new(notifier);
|
||||||
|
|
||||||
|
let monitor =
|
||||||
|
SystemMonitor::new(system_monitor::resource_threshold::get_default_resource_thresholds());
|
||||||
let system_monitor_adapter =
|
let system_monitor_adapter =
|
||||||
adapters::driven::for_monitoring_system::system_monitor::SystemMonitorAdapter::new(monitor);
|
adapters::driven::for_monitoring_system::system_monitor::SystemMonitorAdapter::new(monitor);
|
||||||
|
|
||||||
let formatter = actors::driven::for_formatting_message::alert_formatter::AlertFormatter;
|
let formatter = actors::driven::for_formatting_message::alert_formatter::AlertFormatter;
|
||||||
|
|
||||||
app::service::new(
|
app::service::new(
|
||||||
@@ -26,3 +27,20 @@ pub fn get_service() -> app::service::Service {
|
|||||||
Box::new(formatter),
|
Box::new(formatter),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_get_service() -> app::service::Service {
|
||||||
|
let notifier = actors::driven::for_sending_notification::print::StdoutNotificationActor::new();
|
||||||
|
|
||||||
|
let monitor =
|
||||||
|
SystemMonitor::new(system_monitor::resource_threshold::get_default_resource_thresholds());
|
||||||
|
let system_monitor_adapter =
|
||||||
|
adapters::driven::for_monitoring_system::system_monitor::SystemMonitorAdapter::new(monitor);
|
||||||
|
|
||||||
|
let formatter = actors::driven::for_formatting_message::alert_formatter::AlertFormatter;
|
||||||
|
|
||||||
|
app::service::new(
|
||||||
|
Box::new(notifier),
|
||||||
|
Box::new(system_monitor_adapter),
|
||||||
|
Box::new(formatter),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ mod actors {
|
|||||||
pub mod for_formatting_message {
|
pub mod for_formatting_message {
|
||||||
pub mod alert_formatter;
|
pub mod alert_formatter;
|
||||||
}
|
}
|
||||||
|
pub mod for_sending_notification {
|
||||||
|
pub mod print;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,15 +45,16 @@ enum Commands {
|
|||||||
fn main() {
|
fn main() {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
let service = configurator::get_service();
|
|
||||||
|
|
||||||
match cli.command {
|
match cli.command {
|
||||||
Commands::Run => {
|
Commands::Run => {
|
||||||
|
let service = configurator::get_run_service();
|
||||||
if let Err(e) = service.alert_on_threshold_violation() {
|
if let Err(e) = service.alert_on_threshold_violation() {
|
||||||
eprintln!("Error during threshold violation check: {e}");
|
eprintln!("Error during threshold violation check: {e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Commands::Get => {
|
Commands::Get => {
|
||||||
|
let service = configurator::get_get_service();
|
||||||
if let Err(e) = service.send_all_metrics_notification() {
|
if let Err(e) = service.send_all_metrics_notification() {
|
||||||
eprintln!("Error sending final notification: {e}");
|
eprintln!("Error sending final notification: {e}");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user