Remove legacy notification code and fix all warnings

This commit is contained in:
2025-10-21 19:48:55 +02:00
parent f4b5bb814d
commit 338c4457a5
3 changed files with 36 additions and 249 deletions

View File

@@ -3,7 +3,6 @@ use std::collections::HashMap;
use std::time::Instant;
use tracing::{debug, info, error};
use serde::{Deserialize, Serialize};
use crate::notifications::StatusChange;
use chrono::Utc;
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -32,7 +31,6 @@ pub struct StatusChangeSummary {
pub initial_status: Status,
pub final_status: Status,
pub change_count: usize,
pub significant_change: bool, // true if needs notification
}
#[derive(Debug, Clone)]
@@ -191,7 +189,7 @@ impl HostStatusManager {
info!("Sending aggregated notification for {} service changes", aggregated.service_summaries.len());
// Send aggregated notification
if let Err(e) = self.send_aggregated_notification(&aggregated, notification_manager).await {
if let Err(e) = self.send_aggregated_email(&aggregated, notification_manager).await {
error!("Failed to send aggregated notification: {}", e);
}
} else {
@@ -220,7 +218,6 @@ impl HostStatusManager {
initial_status: *initial_status,
final_status: *final_status,
change_count: *change_count,
significant_change,
});
}
@@ -251,22 +248,11 @@ impl HostStatusManager {
}
}
/// Send aggregated notification email
async fn send_aggregated_notification(
async fn send_aggregated_email(
&self,
aggregated: &AggregatedStatusChanges,
notification_manager: &mut crate::notifications::NotificationManager,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// Create a summary status change for the notification system
let summary_change = StatusChange {
metric_name: "host_status_summary".to_string(),
old_status: aggregated.host_status_initial,
new_status: aggregated.host_status_final,
timestamp: Utc::now(),
details: Some(self.format_aggregated_details(aggregated)),
};
// Create a descriptive summary based on change types
let mut summary_parts = Vec::new();
let critical_count = aggregated.service_summaries.iter().filter(|s| s.final_status == Status::Critical).count();
let warning_count = aggregated.service_summaries.iter().filter(|s| s.final_status == Status::Warning).count();
@@ -288,17 +274,10 @@ impl HostStatusManager {
summary_parts.join(", ")
};
// Create a dummy metric for the notification
let summary_metric = Metric {
name: "host_status_summary".to_string(),
value: cm_dashboard_shared::MetricValue::String(summary_text),
status: aggregated.host_status_final,
timestamp: Utc::now().timestamp() as u64,
description: Some("Aggregated status summary".to_string()),
unit: None,
};
let subject = format!("Status Alert: {}", summary_text);
let body = self.format_aggregated_details(aggregated);
notification_manager.send_status_change_notification(summary_change, &summary_metric).await.map_err(|e| e.into())
notification_manager.send_direct_email(&subject, &body).await.map_err(|e| e.into())
}
/// Format details for aggregated notification