Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Centralize pushover webhook field normalization

rcourtman062721f020f6
diff --git a/docs/release-control/v6/internal/subsystems/alerts.md b/docs/release-control/v6/internal/subsystems/alerts.md
index bdc197f467..f6bde60fd9 100644
--- a/docs/release-control/v6/internal/subsystems/alerts.md
+++ b/docs/release-control/v6/internal/subsystems/alerts.md
@@ -64,6 +64,11 @@ but canonical service-field ownership such as Pushover `token` / `user`
normalization belongs to `internal/notifications/` and persistence boundaries,
not to alert-surface runtime delivery code.
+The alert webhook editor now mirrors that canonical Pushover field rule through
+`frontend-modern/src/utils/alertWebhookPresentation.ts`, so the UI shares the
+same alias and preset mapping instead of carrying its own local webhook-field
+normalization fork.
+
Frontend alert surfaces and backend alert-support files now require explicit
registry path-policy coverage, so new alert-owned runtime files must be mapped
to a concrete proof route instead of silently inheriting subsystem-default
diff --git a/frontend-modern/src/components/Alerts/WebhookConfig.test.tsx b/frontend-modern/src/components/Alerts/WebhookConfig.test.tsx
index 9cd63f730e..f85bcf67e2 100644
--- a/frontend-modern/src/components/Alerts/WebhookConfig.test.tsx
+++ b/frontend-modern/src/components/Alerts/WebhookConfig.test.tsx
@@ -1142,6 +1142,30 @@ describe('WebhookConfig', () => {
expect(tokenInput).toBeTruthy();
});
+ it('shows shared pushover custom fields when creating a webhook', async () => {
+ render(() => (
+ <WebhookConfig
+ webhooks={[]}
+ onAdd={onAddMock}
+ onUpdate={onUpdateMock}
+ onDelete={onDeleteMock}
+ onTest={onTestMock}
+ />
+ ));
+
+ fireEvent.click(screen.getByText('+ Add Webhook'));
+
+ await waitFor(() => {
+ expect(screen.getByPlaceholderText('Generic Webhook')).toBeInTheDocument();
+ });
+
+ fireEvent.click(screen.getByText(/Generic →/));
+ fireEvent.click(screen.getByText('Pushover').closest('button')!);
+
+ expect(screen.getByText('Application Token')).toBeInTheDocument();
+ expect(screen.getByText('User Key')).toBeInTheDocument();
+ });
+
// --- Edge case: webhook with no id for delete/test ---
it('does not call onDelete when webhook has no id', () => {
diff --git a/frontend-modern/src/components/Alerts/WebhookConfig.tsx b/frontend-modern/src/components/Alerts/WebhookConfig.tsx
index e7953af86d..61b04a250c 100644
--- a/frontend-modern/src/components/Alerts/WebhookConfig.tsx
+++ b/frontend-modern/src/components/Alerts/WebhookConfig.tsx
@@ -29,6 +29,7 @@ import {
ALERT_WEBHOOK_URL_HELP_TEMPLATE_VARIABLE,
getAlertWebhookMentionHelp,
getAlertWebhookMentionPlaceholder,
+ getAlertWebhookCustomFieldPresets,
getAlertWebhookNamePlaceholder,
getAlertWebhookServiceLabel,
getAlertWebhookServices,
@@ -39,6 +40,7 @@ import {
getAlertWebhookToggleAllLabel,
getAlertWebhookToggleLabel,
getAlertWebhookUrlPlaceholder,
+ normalizeAlertWebhookCustomFields,
} from '@/utils/alertWebhookPresentation';
import {
formField,
@@ -69,56 +71,12 @@ interface WebhookConfigProps {
type HeaderInput = { id: string; key: string; value: string };
-type CustomFieldPreset = {
- key: string;
- label: string;
- placeholder?: string;
- required?: boolean;
-};
-
type CustomFieldInput = HeaderInput & {
label?: string;
placeholder?: string;
required?: boolean;
};
-const customFieldPresets: Record<string, CustomFieldPreset[]> = {
- pushover: [
- {
- key: 'token',
- label: 'Application Token',
- placeholder: 'Your Pushover application token',
- required: true,
- },
- {
- key: 'user',
- label: 'User Key',
- placeholder: 'Primary user key or group key',
- required: true,
- },
- ],
-};
-
-const normalizeWebhookCustomFields = (
- service: string,
- fields: Record<string, string> = {},
-): Record<string, string> => {
- if (service !== 'pushover') {
- return { ...fields };
- }
-
- const normalized = { ...fields };
- if (!normalized.token?.trim() && normalized.app_token?.trim()) {
- normalized.token = normalized.app_token;
- }
- if (!normalized.user?.trim() && normalized.user_token?.trim()) {
- normalized.user = normalized.user_token;
- }
- delete normalized.app_token;
- delete normalized.user_token;
- return normalized;
-};
-
const buildMapFromInputs = (
inputs: Array<{ key: string; value: string }>,
): Record<string, string> => {
@@ -135,8 +93,8 @@ const createCustomFieldInputs = (
service: string,
existing: Record<string, string> = {},
): CustomFieldInput[] => {
- const presets = customFieldPresets[service];
- const normalizedExisting = normalizeWebhookCustomFields(service, existing);
+ const presets = getAlertWebhookCustomFieldPresets(service);
+ const normalizedExisting = normalizeAlertWebhookCustomFields(service, existing);
const timestamp = Date.now();
if (!presets) {
@@ -212,10 +170,10 @@ export function WebhookConfig(props: WebhookConfigProps) {
};
const ensurePresetCustomFields = (service: string) => {
- if (!customFieldPresets[service]) {
+ if (!getAlertWebhookCustomFieldPresets(service)) {
return;
}
- const existing = normalizeWebhookCustomFields(service, formData().customFields || {});
+ const existing = normalizeAlertWebhookCustomFields(service, formData().customFields || {});
const inputs = createCustomFieldInputs(service, existing);
setCustomFieldInputs(inputs);
};
@@ -241,7 +199,7 @@ export function WebhookConfig(props: WebhookConfigProps) {
headers[input.key] = input.value;
}
});
- const customFields = normalizeWebhookCustomFields(
+ const customFields = normalizeAlertWebhookCustomFields(
data.service,
buildMapFromInputs(customFieldInputs()),
);
@@ -318,7 +276,7 @@ export function WebhookConfig(props: WebhookConfigProps) {
...webhook,
service: webhook.service || 'generic',
payloadTemplate: webhook.template || '',
- customFields: normalizeWebhookCustomFields(
+ customFields: normalizeAlertWebhookCustomFields(
webhook.service || 'generic',
webhook.customFields || {},
),
@@ -335,8 +293,11 @@ export function WebhookConfig(props: WebhookConfigProps) {
);
const service = webhook.service || 'generic';
- const existingCustomFields = normalizeWebhookCustomFields(service, webhook.customFields || {});
- if (customFieldPresets[service] || Object.keys(existingCustomFields).length > 0) {
+ const existingCustomFields = normalizeAlertWebhookCustomFields(
+ service,
+ webhook.customFields || {},
+ );
+ if (getAlertWebhookCustomFieldPresets(service) || Object.keys(existingCustomFields).length > 0) {
setCustomFieldInputs(createCustomFieldInputs(service, existingCustomFields));
} else {
setCustomFieldInputs([]);
diff --git a/frontend-modern/src/utils/__tests__/alertWebhookPresentation.test.ts b/frontend-modern/src/utils/__tests__/alertWebhookPresentation.test.ts
index 92a4b3d853..6d0138eb1b 100644
--- a/frontend-modern/src/utils/__tests__/alertWebhookPresentation.test.ts
+++ b/frontend-modern/src/utils/__tests__/alertWebhookPresentation.test.ts
@@ -2,8 +2,10 @@ import { describe, expect, it } from 'vitest';
import {
ALERT_WEBHOOK_TEST_FAILURE,
ALERT_WEBHOOK_TEST_SUCCESS,
+ getAlertWebhookCustomFieldPresets,
getAlertWebhookTestFailure,
getAlertWebhookTestSuccess,
+ normalizeAlertWebhookCustomFields,
} from '@/utils/alertWebhookPresentation';
describe('alertWebhookPresentation', () => {
@@ -13,4 +15,43 @@ describe('alertWebhookPresentation', () => {
expect(getAlertWebhookTestSuccess()).toBe('Test webhook sent successfully!');
expect(getAlertWebhookTestFailure()).toBe('Failed to send test webhook');
});
+
+ it('exposes pushover custom-field presets and canonicalizes legacy aliases', () => {
+ expect(getAlertWebhookCustomFieldPresets('pushover')).toEqual([
+ {
+ key: 'token',
+ label: 'Application Token',
+ placeholder: 'Your Pushover application token',
+ required: true,
+ },
+ {
+ key: 'user',
+ label: 'User Key',
+ placeholder: 'Primary user key or group key',
+ required: true,
+ },
+ ]);
+
+ expect(
+ normalizeAlertWebhookCustomFields('pushover', {
+ app_token: 'legacy-token',
+ user_token: 'legacy-user',
+ priority: '2',
+ }),
+ ).toEqual({
+ token: 'legacy-token',
+ user: 'legacy-user',
+ priority: '2',
+ });
+
+ expect(
+ normalizeAlertWebhookCustomFields('discord', {
+ app_token: 'legacy-token',
+ user_token: 'legacy-user',
+ }),
+ ).toEqual({
+ app_token: 'legacy-token',
+ user_token: 'legacy-user',
+ });
+ });
});
diff --git a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
index 8a8caeb59d..9fc892ed6c 100644
--- a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
+++ b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
@@ -2977,6 +2977,8 @@ describe('frontend resource type boundaries', () => {
it('keeps alert webhook service vocabulary and action copy in a shared presentation utility', () => {
expect(webhookConfigSource).toContain('getAlertWebhookServices');
expect(webhookConfigSource).toContain('getAlertWebhookServiceLabel');
+ expect(webhookConfigSource).toContain('getAlertWebhookCustomFieldPresets');
+ expect(webhookConfigSource).toContain('normalizeAlertWebhookCustomFields');
expect(webhookConfigSource).toContain('getAlertWebhookSummaryLabel');
expect(webhookConfigSource).toContain('getAlertWebhookToggleAllLabel');
expect(webhookConfigSource).toContain('getAlertWebhookToggleLabel');
@@ -2991,6 +2993,10 @@ describe('frontend resource type boundaries', () => {
expect(webhookConfigSource).not.toContain('My Webhook');
expect(webhookConfigSource).not.toContain('https://example.com/webhook');
expect(webhookConfigSource).not.toContain('Optional — tag users or groups');
+ expect(webhookConfigSource).not.toContain('Your Pushover application token');
+ expect(webhookConfigSource).not.toContain('Primary user key or group key');
+ expect(webhookConfigSource).not.toContain('app_token');
+ expect(webhookConfigSource).not.toContain('user_token');
expect(webhookConfigSource).not.toContain('Enable All');
expect(webhookConfigSource).not.toContain('Disable All');
expect(webhookConfigSource).not.toContain('Enable this webhook');
@@ -3001,6 +3007,12 @@ describe('frontend resource type boundaries', () => {
expect(alertWebhookPresentationSource).toContain(
'export function getAlertWebhookServices',
);
+ expect(alertWebhookPresentationSource).toContain(
+ 'export function getAlertWebhookCustomFieldPresets',
+ );
+ expect(alertWebhookPresentationSource).toContain(
+ 'export function normalizeAlertWebhookCustomFields',
+ );
expect(alertWebhookPresentationSource).toContain(
'export function getAlertWebhookTestLabel',
);
diff --git a/frontend-modern/src/utils/alertWebhookPresentation.ts b/frontend-modern/src/utils/alertWebhookPresentation.ts
index 7209e9a8d5..fc37bafcab 100644
--- a/frontend-modern/src/utils/alertWebhookPresentation.ts
+++ b/frontend-modern/src/utils/alertWebhookPresentation.ts
@@ -21,6 +21,13 @@ type AlertWebhookServicePresentation = {
mentionHelp?: string;
};
+type AlertWebhookCustomFieldPreset = {
+ key: string;
+ label: string;
+ placeholder?: string;
+ required?: boolean;
+};
+
const ALERT_WEBHOOK_SERVICE_PRESENTATION: Record<
AlertWebhookService,
AlertWebhookServicePresentation
@@ -81,6 +88,25 @@ const ALERT_WEBHOOK_SERVICE_PRESENTATION: Record<
},
};
+const ALERT_WEBHOOK_CUSTOM_FIELD_PRESETS: Partial<
+ Record<string, readonly AlertWebhookCustomFieldPreset[]>
+> = {
+ pushover: [
+ {
+ key: 'token',
+ label: 'Application Token',
+ placeholder: 'Your Pushover application token',
+ required: true,
+ },
+ {
+ key: 'user',
+ label: 'User Key',
+ placeholder: 'Primary user key or group key',
+ required: true,
+ },
+ ],
+};
+
export const ALERT_WEBHOOK_SETUP_INSTRUCTIONS_TITLE = 'Setup Instructions';
export const ALERT_WEBHOOK_NAME_PLACEHOLDER = 'My Webhook';
export const ALERT_WEBHOOK_URL_PLACEHOLDER = 'https://example.com/webhook';
@@ -156,6 +182,30 @@ export function getAlertWebhookServiceDescription(service: string) {
);
}
+export function getAlertWebhookCustomFieldPresets(service: string) {
+ return ALERT_WEBHOOK_CUSTOM_FIELD_PRESETS[service.trim().toLowerCase()];
+}
+
+export function normalizeAlertWebhookCustomFields(
+ service: string,
+ fields: Record<string, string> = {},
+) {
+ if (service.trim().toLowerCase() !== 'pushover') {
+ return { ...fields };
+ }
+
+ const normalized = { ...fields };
+ if (!normalized.token?.trim() && normalized.app_token?.trim()) {
+ normalized.token = normalized.app_token;
+ }
+ if (!normalized.user?.trim() && normalized.user_token?.trim()) {
+ normalized.user = normalized.user_token;
+ }
+ delete normalized.app_token;
+ delete normalized.user_token;
+ return normalized;
+}
+
export function getAlertWebhookSetupInstructionsTitle() {
return ALERT_WEBHOOK_SETUP_INSTRUCTIONS_TITLE;
}