From 2d1b87af389163680c1db20a32f409ae61c0b94a Mon Sep 17 00:00:00 2001
From: yumusb <43062104+yumusb@users.noreply.github.com>
Date: Wed, 10 Dec 2025 15:38:52 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E5=91=8A?=
=?UTF-8?q?=E8=AD=A6=E4=B8=AD=20=E5=A2=9E=E5=8A=A0=E6=A0=BC=E5=BC=8F?=
=?UTF-8?q?=E5=8C=96=E5=90=8E=E7=9A=84=E6=97=B6=E9=97=B4=E5=AD=97=E6=AE=B5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
internal/service/notifier.go | 14 ++-
.../pages/Settings/NotificationChannels.tsx | 115 +++++++++---------
2 files changed, 71 insertions(+), 58 deletions(-)
diff --git a/internal/service/notifier.go b/internal/service/notifier.go
index fb16be4..e2b5bc0 100644
--- a/internal/service/notifier.go
+++ b/internal/service/notifier.go
@@ -84,7 +84,7 @@ func (n *Notifier) buildMessage(agent *models.Agent, record *models.AlertRecord)
record.Message,
record.Threshold,
record.ActualValue,
- time.Unix(record.FiredAt/1000, 0).Format("2006-01-02 15:04:05"),
+ time.Unix(record.FiredAt/1000, 0).Local().Format("2006-01-02 15:04:05"),
)
} else if record.Status == "resolved" {
// 告警恢复消息
@@ -103,7 +103,7 @@ func (n *Notifier) buildMessage(agent *models.Agent, record *models.AlertRecord)
agent.IP,
record.AlertType,
record.ActualValue,
- time.Unix(record.ResolvedAt/1000, 0).Format("2006-01-02 15:04:05"),
+ time.Unix(record.ResolvedAt/1000, 0).Local().Format("2006-01-02 15:04:05"),
)
}
@@ -321,8 +321,18 @@ func (n *Notifier) sendCustomWebhook(ctx context.Context, config map[string]inte
v = fmt.Sprintf("%.2f", record.ActualValue)
case "alert.firedAt":
v = fmt.Sprintf("%d", record.FiredAt)
+ case "alert.firedAtFormatted":
+ // 格式化的触发时间 (使用系统时区,Docker 中设置为 Asia/Shanghai)
+ v = time.Unix(record.FiredAt/1000, 0).Local().Format("2006-01-02 15:04:05")
case "alert.resolvedAt":
v = fmt.Sprintf("%d", record.ResolvedAt)
+ case "alert.resolvedAtFormatted":
+ // 格式化的恢复时间 (使用系统时区,Docker 中设置为 Asia/Shanghai)
+ if record.ResolvedAt > 0 {
+ v = time.Unix(record.ResolvedAt/1000, 0).Local().Format("2006-01-02 15:04:05")
+ } else {
+ v = ""
+ }
default:
return w.Write([]byte("{{" + tag + "}}"))
}
diff --git a/web/src/pages/Settings/NotificationChannels.tsx b/web/src/pages/Settings/NotificationChannels.tsx
index 9d92591..fd4e70c 100644
--- a/web/src/pages/Settings/NotificationChannels.tsx
+++ b/web/src/pages/Settings/NotificationChannels.tsx
@@ -1,22 +1,22 @@
-import {useEffect} from 'react';
-import {App, Button, Card, Collapse, Form, Input, Select, Space, Spin, Switch} from 'antd';
-import {TestTube} from 'lucide-react';
-import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query';
+import { useEffect } from 'react';
+import { App, Button, Card, Collapse, Form, Input, Select, Space, Spin, Switch } from 'antd';
+import { TestTube } from 'lucide-react';
+import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import {
getNotificationChannels,
type NotificationChannel,
saveNotificationChannels,
testNotificationChannel,
} from '@/api/property.ts';
-import {getErrorMessage} from '@/lib/utils';
+import { getErrorMessage } from '@/lib/utils';
const NotificationChannels = () => {
const [form] = Form.useForm();
- const {message: messageApi} = App.useApp();
+ const { message: messageApi } = App.useApp();
const queryClient = useQueryClient();
// 获取通知渠道列表
- const {data: channels = [], isLoading} = useQuery({
+ const { data: channels = [], isLoading } = useQuery({
queryKey: ['notificationChannels'],
queryFn: getNotificationChannels,
});
@@ -26,7 +26,7 @@ const NotificationChannels = () => {
mutationFn: saveNotificationChannels,
onSuccess: () => {
messageApi.success('保存成功');
- queryClient.invalidateQueries({queryKey: ['notificationChannels']});
+ queryClient.invalidateQueries({ queryKey: ['notificationChannels'] });
},
onError: (error: unknown) => {
messageApi.error(getErrorMessage(error, '保存失败'));
@@ -181,8 +181,8 @@ const NotificationChannels = () => {
钉钉通知
}
@@ -192,7 +192,7 @@ const NotificationChannels = () => {