Add placeholders to Service Uptime templates
- Adds support for new placeholders in the Service Uptime Monitoring alert templates. The following placeholders are now available:
-- ${ip_host}: The IP address or hostname of the service.
-- ${service_type}: The type of the service (e.g., HTTP, PING, TCP, DNS).
-- ${port}: The port the service is running on.
-- ${domain}: The domain name of the service.
-- ${region_agent}: The regional agent monitoring the service.
This commit is contained in:
@@ -32,12 +32,9 @@ export function processTemplate(
|
||||
|
||||
// Skip replacement if template is empty
|
||||
if (!templateText) {
|
||||
// console.log("Empty template for status:", status);
|
||||
return generateDefaultMessage(service.name, status, responseTime);
|
||||
}
|
||||
|
||||
// console.log("Using template text:", templateText);
|
||||
|
||||
|
||||
// Replace placeholders with actual values
|
||||
let message = templateText
|
||||
.replace(/\${service_name}/g, service.name || 'Unknown Service')
|
||||
@@ -50,16 +47,20 @@ export function processTemplate(
|
||||
message = message.replace(/\${response_time}/g, 'N/A');
|
||||
}
|
||||
|
||||
// Replace any other placeholders
|
||||
// Replace service-specific placeholders
|
||||
message = message
|
||||
.replace(/\${threshold}/g, service.threshold || 'N/A')
|
||||
.replace(/\${url}/g, service.url || 'N/A')
|
||||
.replace(/\${host}/g, service.host || 'N/A')
|
||||
.replace(/\${service_type}/g, service.type?.toUpperCase() || 'N/A')
|
||||
.replace(/\${port}/g, service.port ? service.port.toString() : 'N/A')
|
||||
.replace(/\${domain}/g, service.domain || 'N/A')
|
||||
.replace(/\${region_name}/g, service.region_name || 'Default')
|
||||
.replace(/\${agent_id}/g, service.agent_id ? service.agent_id.toString() : '1')
|
||||
.replace(/\${uptime}/g, service.uptime ? `${service.uptime}%` : 'N/A')
|
||||
.replace(/\${time}/g, new Date().toLocaleString());
|
||||
|
||||
// console.log("Processed template message:", message);
|
||||
;
|
||||
return message;
|
||||
} catch (error) {
|
||||
// console.error("Error processing template:", error);
|
||||
return generateDefaultMessage(service.name, status, responseTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import { pb } from "@/lib/pocketbase";
|
||||
import {
|
||||
serverNotificationTemplateService,
|
||||
@@ -122,7 +121,8 @@ export const templateTypeConfigs = {
|
||||
description: 'Templates for service uptime monitoring alerts',
|
||||
placeholders: [
|
||||
'${service_name}', '${status}', '${response_time}', '${url}',
|
||||
'${uptime}', '${downtime}', '${time}'
|
||||
'${host}', '${service_type}', '${port}', '${domain}',
|
||||
'${region_name}', '${agent_id}', '${uptime}', '${time}'
|
||||
]
|
||||
},
|
||||
ssl: {
|
||||
|
||||
Reference in New Issue
Block a user