43 lines
1.2 KiB
Rust
43 lines
1.2 KiB
Rust
use crate::app::ports::driven::{
|
|
ForFormattingMessage, ForMonitoringSystem, ForSendingNotification,
|
|
};
|
|
|
|
pub struct Service {
|
|
notifier: Box<dyn ForSendingNotification>,
|
|
monitor: Box<dyn ForMonitoringSystem>,
|
|
formatter: Box<dyn ForFormattingMessage>,
|
|
}
|
|
|
|
pub fn new(
|
|
notifier: Box<dyn ForSendingNotification>,
|
|
monitor: Box<dyn ForMonitoringSystem>,
|
|
formatter: Box<dyn ForFormattingMessage>,
|
|
) -> Service {
|
|
Service {
|
|
notifier,
|
|
monitor,
|
|
formatter,
|
|
}
|
|
}
|
|
|
|
impl Service {
|
|
pub fn alert_on_threshold_violation(&self) {
|
|
// Check for threshold violations and send alerts
|
|
let violations = self.monitor.check_thresholds();
|
|
for violation in violations {
|
|
let message = self.formatter.format_violation(violation);
|
|
self.notifier
|
|
.send_notification(&message)
|
|
.expect("Failed to send notification");
|
|
}
|
|
}
|
|
|
|
pub fn send_all_metrics_notification(&self) {
|
|
// Send a final notification with all system information
|
|
let summary = self.formatter.format_summary(&self.monitor.get_metrics());
|
|
self.notifier
|
|
.send_notification(&summary)
|
|
.expect("Failed to send final notification");
|
|
}
|
|
}
|