feat: Support multiple notification channels
- Update the Notification Settings dashboard to allow users to select multiple notification channels for alerts. - Add webhook to notification channels: Add webhook as a selectable option in the notification channel type dropdown. - Implement template type selection in the Add Template dialog. Based on the selected type.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
|
||||
import { pb } from '@/lib/pocketbase';
|
||||
import { monitoringIntervals } from '../monitoringIntervals';
|
||||
import { notificationService } from '@/services/notificationService';
|
||||
import { Service } from '@/types/service.types';
|
||||
import { startMonitoringService } from './startMonitoring';
|
||||
|
||||
@@ -16,7 +15,7 @@ export async function resumeMonitoring(serviceId: string): Promise<void> {
|
||||
// Fetch the current service to get its name for better logging
|
||||
const service = await pb.collection('services').getOne(serviceId);
|
||||
|
||||
// console.log(`Resuming service ${service.name} at ${now}`);
|
||||
// console.log(`Resuming service ${service.name} at ${now}`);
|
||||
|
||||
// First, clear any existing interval just to be safe
|
||||
const existingInterval = monitoringIntervals.get(serviceId);
|
||||
@@ -32,50 +31,14 @@ export async function resumeMonitoring(serviceId: string): Promise<void> {
|
||||
last_checked: now
|
||||
});
|
||||
|
||||
// Convert PocketBase record to Service type for notification
|
||||
const serviceForNotification: Service = {
|
||||
id: service.id,
|
||||
name: service.name,
|
||||
url: service.url || "",
|
||||
host: service.host || "", // Include host property
|
||||
type: service.service_type || service.type || "HTTP",
|
||||
status: "up",
|
||||
responseTime: service.response_time || 0,
|
||||
uptime: service.uptime || 0,
|
||||
lastChecked: now,
|
||||
interval: service.heartbeat_interval || 60,
|
||||
retries: service.max_retries || 3,
|
||||
notificationChannel: service.notification_id,
|
||||
alertTemplate: service.template_id,
|
||||
muteAlerts: service.mute_alerts || false,
|
||||
alerts: service.alerts || "unmuted",
|
||||
muteChangedAt: service.mute_changed_at,
|
||||
};
|
||||
|
||||
// Double check if alerts are muted before sending notification
|
||||
// Ensure we're using the correct field - alerts should be "muted" or "unmuted"
|
||||
const alertsMuted = service.alerts === "muted" || serviceForNotification.alerts === "muted";
|
||||
|
||||
if (!alertsMuted) {
|
||||
// console.log(`Alerts NOT muted for service ${service.name}, sending resume notification`);
|
||||
// Send notification that service has been resumed
|
||||
await notificationService.sendNotification({
|
||||
service: serviceForNotification,
|
||||
status: "up",
|
||||
timestamp: now
|
||||
});
|
||||
} else {
|
||||
// console.log(`Alerts muted for service ${service.name}, skipping resume notification`);
|
||||
}
|
||||
|
||||
// IMPORTANT: Wait a brief moment to ensure the status update is processed
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
|
||||
// Now start the service monitoring with a clean slate
|
||||
await startMonitoringService(serviceId);
|
||||
|
||||
console.log(`Service ${service.name} resumed and ready for monitoring`);
|
||||
// console.log(`Service ${service.name} resumed and ready for monitoring`);
|
||||
} catch (error) {
|
||||
// console.error("Error resuming service:", error);
|
||||
// console.error("Error resuming service:", error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user