[Bug]: Push Monitors not found
- Lingua principale
- Go
- Stelle
- 1.2k
- Fork
- 69
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
**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 │
} │
}
```
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Il problema si trova in `apps/server/internal/modules/monitor/monitor.service.go` nelle funzioni `Create` e `UpdateFull`. Inizia esaminando come vengono creati e aggiornati i monitor push, concentrandoti sul campo `push_token` e sul JSON `config.pushToken`. La correzione comporta l'estrazione del token dal JSON di configurazione e il popolamento della colonna `push_token`. Verifica la modifica creando un monitor push tramite l'API e controllando il database per assicurarti che il token venga memorizzato correttamente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- go, sqlite
- Ambito
- backend, databases
- Tipo di issue
- Bug
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 70/100