refactor: implement configurator
This commit is contained in:
28
src/configurator.rs
Normal file
28
src/configurator.rs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
use discord_client::DiscordNotifier;
|
||||||
|
use dotenvy::dotenv;
|
||||||
|
use system_monitor::SystemMonitor;
|
||||||
|
|
||||||
|
use crate::{actors, adapters, app};
|
||||||
|
|
||||||
|
pub fn get_service() -> app::service::Service {
|
||||||
|
dotenv().ok();
|
||||||
|
let notifier = DiscordNotifier::new(
|
||||||
|
std::env::var("DISCORD_WEBHOOK").expect("DISCORD_WEBHOOK environment variable not set"),
|
||||||
|
"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(),
|
||||||
|
);
|
||||||
|
let monitor =
|
||||||
|
SystemMonitor::new(system_monitor::resource_threshold::get_default_resource_thresholds());
|
||||||
|
|
||||||
|
let discord_adapter =
|
||||||
|
adapters::driven::for_sending_notification::discord_client::DiscordAdapter::new(notifier);
|
||||||
|
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(discord_adapter),
|
||||||
|
Box::new(system_monitor_adapter),
|
||||||
|
Box::new(formatter),
|
||||||
|
)
|
||||||
|
}
|
||||||
26
src/main.rs
26
src/main.rs
@@ -1,6 +1,3 @@
|
|||||||
use discord_client::DiscordNotifier;
|
|
||||||
use dotenvy::dotenv;
|
|
||||||
use system_monitor::SystemMonitor;
|
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
mod app {
|
mod app {
|
||||||
@@ -24,6 +21,8 @@ mod actors {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod configurator;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(name = "node-notifier")]
|
#[command(name = "node-notifier")]
|
||||||
#[command(about = "A system monitoring and notification tool")]
|
#[command(about = "A system monitoring and notification tool")]
|
||||||
@@ -42,27 +41,8 @@ enum Commands {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
dotenv().ok();
|
|
||||||
|
|
||||||
let notifier = DiscordNotifier::new(
|
let service = configurator::get_service();
|
||||||
std::env::var("DISCORD_WEBHOOK").expect("DISCORD_WEBHOOK environment variable not set"),
|
|
||||||
"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(),
|
|
||||||
);
|
|
||||||
let monitor =
|
|
||||||
SystemMonitor::new(system_monitor::resource_threshold::get_default_resource_thresholds());
|
|
||||||
|
|
||||||
let discord_adapter =
|
|
||||||
adapters::driven::for_sending_notification::discord_client::DiscordAdapter::new(notifier);
|
|
||||||
let system_monitor_adapter =
|
|
||||||
adapters::driven::for_monitoring_system::system_monitor::SystemMonitorAdapter::new(monitor);
|
|
||||||
let formatter = actors::driven::for_formatting_message::alert_formatter::AlertFormatter;
|
|
||||||
|
|
||||||
let service = app::service::new(
|
|
||||||
Box::new(discord_adapter),
|
|
||||||
Box::new(system_monitor_adapter),
|
|
||||||
Box::new(formatter),
|
|
||||||
);
|
|
||||||
|
|
||||||
match cli.command {
|
match cli.command {
|
||||||
Commands::Run => {
|
Commands::Run => {
|
||||||
|
|||||||
Reference in New Issue
Block a user