diff --git a/agent/internal/httpapi/alarms.go b/agent/internal/httpapi/alarms.go index 8d772f5..c18a4d0 100644 --- a/agent/internal/httpapi/alarms.go +++ b/agent/internal/httpapi/alarms.go @@ -50,25 +50,22 @@ func (s *Server) handleAlarmReport(w http.ResponseWriter, r *http.Request) { maxBytes := int64(1 << 20) // 1MB max r.Body = http.MaxBytesReader(w, r.Body, maxBytes) - var alarm alarmRecord + var alarm map[string]any if err := json.NewDecoder(r.Body).Decode(&alarm); err != nil { errorJSON(w, http.StatusBadRequest, "invalid json: "+err.Error()) return } - if strings.TrimSpace(alarm.Channel) == "" { - errorJSON(w, http.StatusBadRequest, "channel is required") - return + + // Normalize: extract channel and rule_name from whatever format media-server sends + id, _ := alarm["id"].(string) + if id == "" { + id = fmt.Sprintf("alarm_%s_%s", time.Now().Format("20060102_150405"), randomHex(6)) } - if strings.TrimSpace(alarm.RuleName) == "" { - errorJSON(w, http.StatusBadRequest, "rule_name is required") - return - } - if alarm.ID == "" { - alarm.ID = fmt.Sprintf("alarm_%s_%s", time.Now().Format("20060102_150405"), randomHex(6)) - } - if alarm.Timestamp == "" { - alarm.Timestamp = time.Now().Format(time.RFC3339) + if _, ok := alarm["timestamp"]; !ok { + alarm["timestamp"] = time.Now().Format(time.RFC3339) } + alarm["id"] = id + alarm["received_at"] = time.Now().Format(time.RFC3339) path := s.alarmsPath() dir := filepath.Dir(path) @@ -95,8 +92,8 @@ func (s *Server) handleAlarmReport(w http.ResponseWriter, r *http.Request) { return } - s.recordAudit(r, "alarm.report", true, alarm.ID) - writeJSON(w, http.StatusOK, map[string]any{"ok": true, "id": alarm.ID}) + s.recordAudit(r, "alarm.report", true, id) + writeJSON(w, http.StatusOK, map[string]any{"ok": true, "id": id}) } // handleAlarmsRecent returns recent alarm records. diff --git a/agent/rk3588-agent_linux_arm64 b/agent/rk3588-agent_linux_arm64 index 8cae8c7..cc89f0c 100755 Binary files a/agent/rk3588-agent_linux_arm64 and b/agent/rk3588-agent_linux_arm64 differ