Skip to content

Commit 1b964b6

Browse files
committed
Update.
1 parent a608edd commit 1b964b6

File tree

9 files changed

+72
-145
lines changed

9 files changed

+72
-145
lines changed

cmd/dashboard/controller/member_api.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,22 @@ func (ma *memberAPI) addOrEditCron(c *gin.Context) {
941941
cr.ServersRaw = "[]"
942942
err = nil
943943
}
944+
945+
// 验证和修复cron表达式
946+
if cr.TaskType == model.CronTypeCronTask && cr.Scheduler != "" {
947+
// 检查是否包含不支持的 ? 符号
948+
if strings.Contains(cr.Scheduler, "?") {
949+
log.Printf("检测到不支持的cron表达式格式: %s,尝试修复", cr.Scheduler)
950+
// 将 ? 替换为 *
951+
cr.Scheduler = strings.ReplaceAll(cr.Scheduler, "?", "*")
952+
log.Printf("修复后的cron表达式: %s", cr.Scheduler)
953+
}
954+
955+
// 验证表达式是否有效
956+
if _, testErr := singleton.Cron.AddFunc(cr.Scheduler, func() {}); testErr != nil {
957+
err = fmt.Errorf("无效的cron表达式 '%s': %v", cr.Scheduler, testErr)
958+
}
959+
}
944960
}
945961

946962
// 计划任务类型不得使用触发服务器执行方式

resource/l10n/zh-CN.toml

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ other = "服务"
3535
other = "任务"
3636

3737
[Notification]
38-
other = "告警"
38+
other = "事件通知"
3939

4040
[Settings]
4141
other = "设置"
@@ -193,7 +193,7 @@ other = "请求类型"
193193
other = "验证SSL"
194194

195195
[AddNotificationRule]
196-
other = "添加报警规则"
196+
other = "添加事件通知规则"
197197

198198
[Rules]
199199
other = "规则"
@@ -303,8 +303,7 @@ other = "注册"
303303
[DontHaveAnAccount]
304304
other = "没有账号?"
305305

306-
[SSLCertificate]
307-
other = "HTTP(S)/SSL证书"
306+
308307

309308
[TCPPort]
310309
other = "TCP 端口"
@@ -322,10 +321,10 @@ other = "删除通知方式"
322321
other = "确认删除此通知方式?"
323322

324323
[DeleteNotificationRule]
325-
other = "删除报警规则"
324+
other = "删除事件通知规则"
326325

327326
[ConfirmToDeleteThisNotificationRule]
328-
other = "确认删除此报警规则"
327+
other = "确认删除此事件通知规则"
329328

330329
[ForceUpdate]
331330
other = "强制更新"
@@ -616,7 +615,7 @@ other = "添加"
616615
other = "修改"
617616

618617
[AlarmRule]
619-
other = "告警规则"
618+
other = "事件规则"
620619

621620
[NotificationMethod]
622621
other = "通知方式"
@@ -839,10 +838,10 @@ other = "自定义DDNS使用的公共DNS服务器(逗号分隔)"
839838
other = "套餐"
840839

841840
[TrafficAlert]
842-
other = "流量告警"
841+
other = "流量事件"
843842

844843
[SetupTrafficAlert]
845-
other = "设置流量告警"
844+
other = "设置流量事件"
846845

847846
[MonthlyTrafficLimit]
848847
other = "月流量限制"
@@ -851,28 +850,28 @@ other = "月流量限制"
851850
other = "通知组"
852851

853852
[AlertThresholds]
854-
other = "告警阈值"
853+
other = "事件阈值"
855854

856855
[Alert50Percent]
857-
other = "50% 流量告警"
856+
other = "50% 流量事件"
858857

859858
[Alert90Percent]
860-
other = "90% 流量告警"
859+
other = "90% 流量事件"
861860

862861
[Alert100Percent]
863-
other = "100% 流量告警"
862+
other = "100% 流量事件"
864863

865864
[CreateAlert]
866-
other = "创建告警"
865+
other = "创建事件"
867866

868867
[TrafficAlertInfo]
869-
other = "流量告警说明"
868+
other = "流量事件说明"
870869

871870
[TrafficAlertInfo1]
872871
other = "流量统计周期为自然月(每月1号重置)"
873872

874873
[TrafficAlertInfo2]
875-
other = "可同时启用多个阈值告警"
874+
other = "可同时启用多个阈值事件"
876875

877876
[TrafficAlertInfo3]
878-
other = "告警将发送到指定的通知组"
877+
other = "事件通知将发送到指定的通知组"

resource/static/main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
let LANG = {
22
Add: "添加",
33
Edit: "修改",
4-
AlarmRule: "报警规则",
4+
AlarmRule: "事件规则",
55
Notification: "通知方式",
66
Server: "服务器",
77
Monitor: "监控",
@@ -1818,10 +1818,10 @@ function updateTaskNameMapping() {
18181818
// 转换表格中的JSON数据为可读名称
18191819
function convertTableJsonToNames() {
18201820

1821-
// 只在监控配置页面和Cron任务页面运行,跳过报警规则页面
1821+
// 只在监控配置页面和Cron任务页面运行,跳过事件规则页面
18221822
if (window.location.pathname.includes('/notification')) {
18231823

1824-
return; // 跳过报警规则页面,保持原始显示
1824+
return; // 跳过事件规则页面,保持原始显示
18251825
}
18261826

18271827
// 转换监控配置表格中的服务器ID

resource/template/dashboard-default/notification.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,20 @@
100100
<script>
101101
$('.checkbox').checkbox();
102102

103-
// 为编辑报警规则按钮添加事件监听器
103+
// 为编辑事件规则按钮添加事件监听器
104104
$(document).on('click', '.edit-alert-rule-btn', function() {
105105
const btn = $(this);
106106
const ruleId = btn.data('id');
107107

108108
if (!ruleId) {
109-
console.error('告警规则ID不存在');
109+
console.error('事件规则ID不存在');
110110
return;
111111
}
112112

113113
// 显示加载状态
114114
btn.addClass('loading');
115115

116-
// 通过AJAX获取告警规则详细数据
116+
// 通过AJAX获取事件规则详细数据
117117
$.ajax({
118118
url: '/api/alert-rule/' + ruleId,
119119
type: 'GET',
@@ -122,16 +122,16 @@
122122
.done(function(response) {
123123
if (response && response.code === 200 && response.result) {
124124
const rule = response.result;
125-
console.log('获取到告警规则数据:', rule);
125+
console.log('获取到事件规则数据:', rule);
126126
addOrEditAlertRule(rule);
127127
} else {
128-
console.error('获取告警规则数据失败:', response);
129-
alert('获取告警规则数据失败: ' + (response.message || '未知错误'));
128+
console.error('获取事件规则数据失败:', response);
129+
alert('获取事件规则数据失败: ' + (response.message || '未知错误'));
130130
}
131131
})
132132
.fail(function(xhr, status, error) {
133-
console.error('获取告警规则数据网络错误:', error);
134-
alert('获取告警规则数据失败: ' + error);
133+
console.error('获取事件规则数据网络错误:', error);
134+
alert('获取事件规则数据失败: ' + error);
135135
})
136136
.always(function() {
137137
btn.removeClass('loading');

service/rpc/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ func checkAndResetCycleTraffic(clientID uint64) {
921921
singleton.ServerLock.RLock()
922922
defer singleton.ServerLock.RUnlock()
923923

924-
// 遍历所有启用的报警规则
924+
// 遍历所有启用的事件规则
925925
for _, alert := range singleton.Alerts {
926926
if !alert.Enabled() {
927927
continue
@@ -1056,7 +1056,7 @@ func checkAndResetCycleTraffic(clientID uint64) {
10561056
// 计算上个周期累计流量
10571057
totalOldTraffic := oldInTransfer + oldOutTransfer
10581058

1059-
resetMessage := fmt.Sprintf("流量重置通知\n服务器 %s [%s] 的周期流量已重置\n上个周期累计流量: %s (入站=%s, 出站=%s)\n新周期: %s 到 %s\n报警规则: %s",
1059+
resetMessage := fmt.Sprintf("流量重置通知\n服务器 %s [%s] 的周期流量已重置\n上个周期累计流量: %s (入站=%s, 出站=%s)\n新周期: %s 到 %s\n事件规则: %s",
10601060
server.Name,
10611061
singleton.IPDesensitize(server.Host.IP),
10621062
formatTraffic(totalOldTraffic),

service/singleton/alertsentinel.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ type NotificationHistory struct {
2424
Until time.Time
2525
}
2626

27-
// 报警规则
27+
// 事件规则
2828
var (
2929
AlertsLock sync.RWMutex
3030
Alerts []*model.AlertRule
31-
alertsStore map[uint64]map[uint64][][]interface{} // [alert_id][server_id] -> 对应报警规则的检查结果
32-
alertsPrevState map[uint64]map[uint64]uint // [alert_id][server_id] -> 对应报警规则的上一次报警状态
33-
AlertsCycleTransferStatsStore map[uint64]*model.CycleTransferStats // [alert_id] -> 对应报警规则的周期流量统计
31+
alertsStore map[uint64]map[uint64][][]interface{} // [alert_id][server_id] -> 对应事件规则的检查结果
32+
alertsPrevState map[uint64]map[uint64]uint // [alert_id][server_id] -> 对应事件规则的上一次事件状态
33+
AlertsCycleTransferStatsStore map[uint64]*model.CycleTransferStats // [alert_id] -> 对应事件规则的周期流量统计
3434
)
3535

36-
// addCycleTransferStatsInfo 向AlertsCycleTransferStatsStore中添加周期流量报警统计信息
36+
// addCycleTransferStatsInfo 向AlertsCycleTransferStatsStore中添加周期流量事件统计信息
3737
func addCycleTransferStatsInfo(alert *model.AlertRule) {
3838
if !alert.Enabled() {
3939
return
@@ -66,7 +66,7 @@ const (
6666
maxHistoryPerServer = 10 // 每个server最多存储10条历史记录
6767
)
6868

69-
// AlertSentinelStart 报警器启动
69+
// AlertSentinelStart 事件监控器启动
7070
func AlertSentinelStart() {
7171
alertsStore = make(map[uint64]map[uint64][][]interface{})
7272
alertsPrevState = make(map[uint64]map[uint64]uint)
@@ -85,29 +85,29 @@ func AlertSentinelStart() {
8585

8686
// 根据数据库类型选择不同的加载方式
8787
if Conf.DatabaseType == "badger" {
88-
// 使用BadgerDB加载报警规则
88+
// 使用BadgerDB加载事件规则
8989
if db.DB != nil {
9090
// BadgerDB模式,使用AlertRuleOps查询AlertRule
9191
alertOps := db.NewAlertRuleOps(db.DB)
9292
alerts, err := alertOps.GetAllAlertRules()
9393
if err != nil {
94-
log.Printf("从BadgerDB加载报警规则失败: %v", err)
94+
log.Printf("从BadgerDB加载事件规则失败: %v", err)
9595
AlertsLock.Unlock()
9696
return
9797
}
9898
Alerts = alerts
9999
} else {
100-
log.Println("BadgerDB未初始化,跳过加载报警规则")
100+
log.Println("BadgerDB未初始化,跳过加载事件规则")
101101
AlertsLock.Unlock()
102102
return
103103
}
104104
} else {
105-
// 使用SQLite加载报警规则
105+
// 使用SQLite加载事件规则
106106
err := executeWithRetry(func() error {
107107
return DB.Find(&Alerts).Error
108108
})
109109
if err != nil {
110-
log.Printf("从SQLite加载报警规则失败: %v", err)
110+
log.Printf("从SQLite加载事件规则失败: %v", err)
111111
AlertsLock.Unlock()
112112
return // 不要panic,而是返回并稍后重试
113113
}
@@ -174,24 +174,24 @@ func AlertSentinelStart() {
174174

175175
if lastPrint.Before(startedAt.Add(-1 * time.Hour)) {
176176
if Conf.Debug {
177-
log.Println("NG>> 报警规则检测每小时", checkCount, "次", startedAt, time.Now())
177+
log.Println("NG>> 事件规则检测每小时", checkCount, "次", startedAt, time.Now())
178178
}
179179
checkCount = 0
180180
lastPrint = startedAt
181181
}
182182

183-
// 优化检查间隔:根据报警规则数量动态调整
183+
// 优化检查间隔:根据事件规则数量动态调整
184184
var checkInterval time.Duration
185185
AlertsLock.RLock()
186186
alertCount := len(Alerts) // 使用Alerts而不是alertsStore,更准确
187187
AlertsLock.RUnlock()
188188

189189
if alertCount == 0 {
190-
checkInterval = 30 * time.Second // 没有报警规则时30秒检查一次
190+
checkInterval = 30 * time.Second // 没有事件规则时30秒检查一次
191191
} else if alertCount < 10 {
192-
checkInterval = 10 * time.Second // 少量报警规则时10秒检查一次
192+
checkInterval = 10 * time.Second // 少量事件规则时10秒检查一次
193193
} else {
194-
checkInterval = 5 * time.Second // 大量报警规则时5秒检查一次
194+
checkInterval = 5 * time.Second // 大量事件规则时5秒检查一次
195195
}
196196

197197
// 计算剩余时间并睡眠,避免忙等待

service/singleton/notification.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,7 @@ func (_NotificationMuteLabel) ServiceStateChanged(serviceId uint64) *string {
248248
return &label
249249
}
250250

251-
func (_NotificationMuteLabel) ServiceSSL(serviceId uint64, extraInfo string) *string {
252-
label := fmt.Sprintf("bf::sssl-%d-%s", serviceId, extraInfo)
253-
return &label
254-
}
251+
255252

256253
func (_NotificationMuteLabel) DDNSChanged(serverId uint64, domain string) *string {
257254
label := fmt.Sprintf("bf::ddns-%d-%s", serverId, domain)

0 commit comments

Comments
 (0)