[Bug]: Push Monitors not found
- Vorherrschende Sprache
- Go
- Sterne
- 1.2k
- Forks
- 69
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
**Describe the bug**
Push monitors are not found when sending heartbeats. The API returns `{"message":"Monitor not found for pushToken","data":null}` even though the monitor exists and the correct token is
used.
The root cause is that `push_token` column is stored as empty string, while the token is only stored inside `config.pushToken`. The push handler's `FindOneByPushToken` queries `WHERE
push_token = ?` which finds nothing.
API response shows the mismatch:
```json
{
"config": "{\"pushToken\":\"aQlBH7ty9EBpnAFcT1oXQjsVQqJe3M9T\"}",
"push_token": "" // Empty!
}
```
**Database**
- sqlite
**To Reproduce**
1. Create a push monitor via the API with push_token field set
2. Observe that push_token column is empty, token only exists in config.pushToken
3. Call GET /api/v1/push/{token}?status=up&msg=OK&ping=
4. Receive "Monitor not found for pushToken" error
**Expected behavior**
The push_token field should be populated from either:
- The top-level push_token field in the request, OR
- Extracted from config.pushToken if not provided at top level
**Screenshots**
N/A
**Desktop (please complete the following information):**
- OS: macOS
- Browser: N/A (API calls via curl/CI)
- Version: Latest
**Smartphone (please complete the following information):**
N/A
**Additional context**
The fix should be in `apps/server/internal/modules/monitor/monitor.service.go` in the `Create` and `UpdateFull` functions to extract `pushToken` from config and populate the `push_token` field when
creating/updating push monitors.
```go
// In Create() - after setting createModel fields: │
if createModel.Type == "push" && createModel.PushToken == "" { │
// Extract from config if not provided at top level │
var pushConfig struct { │
PushToken string `json:"pushToken"` │
} │
if err := json.Unmarshal([]byte(createModel.Config), &pushConfig); err == nil && pushConfig.PushToken != "" { │
createModel.PushToken = pushConfig.PushToken │
} │
}
```
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Das Issue liegt in `apps/server/internal/modules/monitor/monitor.service.go` in den Funktionen `Create` und `UpdateFull`. Beginnen Sie damit zu untersuchen, wie Push-Monitore erstellt und aktualisiert werden, mit Fokus auf das Feld `push_token` und das JSON `config.pushToken`. Die Lösung umfasst das Extrahieren des Tokens aus dem JSON-Konfigurationsobjekt und das Befüllen der Spalte `push_token`. Überprüfen Sie die Änderung, indem Sie einen Push-Monitor über die API erstellen und in der Datenbank prüfen, ob das Token korrekt gespeichert ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- go, sqlite
- Bereich
- backend, databases
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 70/100