feat: 系统设置页支持修改告警保留天数
This commit is contained in:
parent
1c772fa28e
commit
0fbb2e85dc
@ -56,6 +56,13 @@ func (c *AlarmCollector) SetRetention(days int) {
|
||||
c.retentionDays = days
|
||||
}
|
||||
|
||||
func (c *AlarmCollector) GetRetention() int {
|
||||
if c == nil {
|
||||
return 30
|
||||
}
|
||||
return c.retentionDays
|
||||
}
|
||||
|
||||
func (c *AlarmCollector) cleanupLoop() {
|
||||
c.cleanupOldAlarms()
|
||||
ticker := time.NewTicker(24 * time.Hour)
|
||||
|
||||
@ -111,6 +111,8 @@ type PageData struct {
|
||||
UnacknowledgedAlarmCount int
|
||||
DetectionChannelCount int
|
||||
StaleCount int
|
||||
SystemAlarmRetention int
|
||||
SystemConcurrency int
|
||||
AlarmFilterDevices []string
|
||||
AlarmFilterRuleTypes []string
|
||||
SelectedAlarmDevice string
|
||||
@ -793,6 +795,7 @@ func (u *UI) Routes() (chi.Router, error) {
|
||||
r.Get("/assets/overlays/{name}/export", u.pageAssetOverlayExport)
|
||||
r.Get("/audit", u.pageAudit)
|
||||
r.Get("/system", u.pageSystem)
|
||||
r.Post("/system/config", u.actionSystemConfig)
|
||||
r.Get("/system/db-backup", u.pageSystemDBBackup)
|
||||
r.Get("/resources", u.pageResources)
|
||||
r.Post("/system/db-restore", u.actionSystemDBRestore)
|
||||
@ -4258,13 +4261,36 @@ func (u *UI) pageSystemDBBackup(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (u *UI) renderSystemPage(w http.ResponseWriter, r *http.Request, status int, message string, errText string) {
|
||||
w.WriteHeader(status)
|
||||
u.render(w, r, "system", PageData{
|
||||
Title: "系统状态",
|
||||
Devices: u.registry.GetDevices(),
|
||||
DBPath: u.dbPath,
|
||||
Message: message,
|
||||
Error: errText,
|
||||
})
|
||||
data := PageData{
|
||||
Title: "系统状态",
|
||||
Devices: u.registry.GetDevices(),
|
||||
DBPath: u.dbPath,
|
||||
Message: message,
|
||||
Error: errText,
|
||||
SystemAlarmRetention: 30,
|
||||
SystemConcurrency: 5,
|
||||
}
|
||||
if u.alarmCollector != nil {
|
||||
data.SystemAlarmRetention = u.alarmCollector.GetRetention()
|
||||
}
|
||||
u.render(w, r, "system", data)
|
||||
}
|
||||
|
||||
func (u *UI) actionSystemConfig(w http.ResponseWriter, r *http.Request) {
|
||||
_ = r.ParseForm()
|
||||
if days, err := strconv.Atoi(strings.TrimSpace(r.FormValue("alarm_retention_days"))); err == nil && days >= 0 {
|
||||
if u.alarmCollector != nil {
|
||||
u.alarmCollector.SetRetention(days)
|
||||
}
|
||||
msg := "告警保留已设为 " + strconv.Itoa(days) + " 天"
|
||||
if days == 0 {
|
||||
msg = "告警将永久保留"
|
||||
}
|
||||
msg += "(运行时生效,重启后需在配置文件 safesightd.json 中修改 alarm_retention_days 持久化)"
|
||||
u.renderSystemPage(w, r, http.StatusOK, msg, "")
|
||||
return
|
||||
}
|
||||
u.renderSystemPage(w, r, http.StatusBadRequest, "", "请输入有效的保留天数")
|
||||
}
|
||||
|
||||
func (u *UI) actionSystemDBRestore(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@ -36,6 +36,20 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="detail-grid">
|
||||
<div class="card">
|
||||
<h2 class="title-with-icon">{{icon "system"}}<span>系统配置</span></h2>
|
||||
<form method="post" action="/system/config">
|
||||
<div class="field-grid">
|
||||
<label><span>告警保留天数</span><input type="number" name="alarm_retention_days" value="{{.SystemAlarmRetention}}" min="0" /><div class="form-hint">0=永久保留</div></label>
|
||||
</div>
|
||||
<div class="actions" style="margin-top:12px">
|
||||
<button type="submit" class="secondary">保存配置</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
var svcEl = document.getElementById("svc-status");
|
||||
|
||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user