feat: Add Server Threshold Tab

- Add a new tab for "Server Threshold" to the Alert Templates dashboard, to allow users to manage server threshold configurations.
This commit is contained in:
Tola Leng
2025-08-09 20:06:40 +07:00
parent 34dccb763d
commit 92e5f3f074
5 changed files with 235 additions and 37 deletions
+28 -5
View File
@@ -1,3 +1,4 @@
import { pb } from "@/lib/pocketbase";
import {
serverNotificationTemplateService,
@@ -14,15 +15,20 @@ import {
SslNotificationTemplate,
CreateUpdateSslNotificationTemplateData
} from "./sslNotificationTemplateService";
import {
serverThresholdService,
ServerThreshold,
CreateUpdateServerThresholdData
} from "./serverThresholdService";
export type TemplateType = 'server' | 'service' | 'ssl';
export type TemplateType = 'server' | 'service' | 'ssl' | 'server_threshold';
export type AnyTemplate = ServerNotificationTemplate | ServiceNotificationTemplate | SslNotificationTemplate;
export type AnyTemplateData = CreateUpdateServerNotificationTemplateData | CreateUpdateServiceNotificationTemplateData | CreateUpdateSslNotificationTemplateData;
export type AnyTemplate = ServerNotificationTemplate | ServiceNotificationTemplate | SslNotificationTemplate | ServerThreshold;
export type AnyTemplateData = CreateUpdateServerNotificationTemplateData | CreateUpdateServiceNotificationTemplateData | CreateUpdateSslNotificationTemplateData | CreateUpdateServerThresholdData;
// Export individual template types
export type { ServerNotificationTemplate, ServiceNotificationTemplate, SslNotificationTemplate };
export type { CreateUpdateServerNotificationTemplateData, CreateUpdateServiceNotificationTemplateData, CreateUpdateSslNotificationTemplateData };
export type { ServerNotificationTemplate, ServiceNotificationTemplate, SslNotificationTemplate, ServerThreshold };
export type { CreateUpdateServerNotificationTemplateData, CreateUpdateServiceNotificationTemplateData, CreateUpdateSslNotificationTemplateData, CreateUpdateServerThresholdData };
export const templateService = {
async getTemplates(type: TemplateType): Promise<AnyTemplate[]> {
@@ -33,6 +39,8 @@ export const templateService = {
return serviceNotificationTemplateService.getTemplates();
case 'ssl':
return sslNotificationTemplateService.getTemplates();
case 'server_threshold':
return serverThresholdService.getServerThresholds();
default:
throw new Error(`Unknown template type: ${type}`);
}
@@ -46,6 +54,8 @@ export const templateService = {
return serviceNotificationTemplateService.getTemplate(id);
case 'ssl':
return sslNotificationTemplateService.getTemplate(id);
case 'server_threshold':
return serverThresholdService.getServerThreshold(id);
default:
throw new Error(`Unknown template type: ${type}`);
}
@@ -59,6 +69,8 @@ export const templateService = {
return serviceNotificationTemplateService.createTemplate(data as CreateUpdateServiceNotificationTemplateData);
case 'ssl':
return sslNotificationTemplateService.createTemplate(data as CreateUpdateSslNotificationTemplateData);
case 'server_threshold':
return serverThresholdService.createServerThreshold(data as CreateUpdateServerThresholdData);
default:
throw new Error(`Unknown template type: ${type}`);
}
@@ -72,6 +84,8 @@ export const templateService = {
return serviceNotificationTemplateService.updateTemplate(id, data as Partial<CreateUpdateServiceNotificationTemplateData>);
case 'ssl':
return sslNotificationTemplateService.updateTemplate(id, data as Partial<CreateUpdateSslNotificationTemplateData>);
case 'server_threshold':
return serverThresholdService.updateServerThreshold(id, data as Partial<CreateUpdateServerThresholdData>);
default:
throw new Error(`Unknown template type: ${type}`);
}
@@ -85,6 +99,8 @@ export const templateService = {
return serviceNotificationTemplateService.deleteTemplate(id);
case 'ssl':
return sslNotificationTemplateService.deleteTemplate(id);
case 'server_threshold':
return serverThresholdService.deleteServerThreshold(id);
default:
throw new Error(`Unknown template type: ${type}`);
}
@@ -116,5 +132,12 @@ export const templateTypeConfigs = {
'${domain}', '${certificate_name}', '${expiry_date}', '${days_left}',
'${issuer}', '${serial_number}', '${time}'
]
},
server_threshold: {
label: 'Server Threshold',
description: 'Templates for server resource threshold configurations',
placeholders: [
'${name}', '${cpu_threshold}', '${ram_threshold}', '${disk_threshold}', '${network_threshold}'
]
}
};