Fix monitor ID type mismatch causing all Uptime Kuma statuses to read unknown (#38)
heartbeatList/importantHeartbeatList emit monitor IDs as strings (server iterates object keys), while monitorList and the live heartbeat event use numbers. The lastHeartbeat map was keyed by the numeric monitor.id, so string-keyed lookups from heartbeatList/importantHeartbeatList never hit. Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
parent
b4943b1155
commit
9a1d2803a2
1 changed files with 7 additions and 4 deletions
|
|
@ -86,17 +86,20 @@ export const uptimeKuma: IntegrationAdapter = {
|
||||||
s.on('monitorList', (list: Record<string, UptimeKumaMonitor>) => {
|
s.on('monitorList', (list: Record<string, UptimeKumaMonitor>) => {
|
||||||
for (const m of Object.values(list)) monitors.set(m.id, m)
|
for (const m of Object.values(list)) monitors.set(m.id, m)
|
||||||
})
|
})
|
||||||
s.on('importantHeartbeatList', (monitorId: number, beats: Heartbeat[]) => {
|
s.on('importantHeartbeatList', (monitorId: number | string, beats: Heartbeat[]) => {
|
||||||
const latest = beats[beats.length - 1]
|
const latest = beats[beats.length - 1]
|
||||||
if (latest) lastHeartbeat.set(monitorId, latest)
|
if (latest) lastHeartbeat.set(Number(monitorId), latest)
|
||||||
})
|
})
|
||||||
// importantHeartbeatList only contains status-change events, so a monitor
|
// importantHeartbeatList only contains status-change events, so a monitor
|
||||||
// that's been continuously up since it was added has no entries there.
|
// that's been continuously up since it was added has no entries there.
|
||||||
// heartbeatList carries the regular (non-"important") beat history and is
|
// heartbeatList carries the regular (non-"important") beat history and is
|
||||||
// sent for every monitor, so it's needed to populate those cases too.
|
// sent for every monitor, so it's needed to populate those cases too.
|
||||||
s.on('heartbeatList', (monitorId: number, beats: Heartbeat[]) => {
|
// Uptime Kuma's server emits both with the monitor ID as a string (it
|
||||||
|
// iterates monitor object keys), unlike monitorList/heartbeat which use
|
||||||
|
// numeric IDs — coerce so map lookups by numeric monitor.id still hit.
|
||||||
|
s.on('heartbeatList', (monitorId: number | string, beats: Heartbeat[]) => {
|
||||||
const latest = beats[beats.length - 1]
|
const latest = beats[beats.length - 1]
|
||||||
if (latest) lastHeartbeat.set(monitorId, latest)
|
if (latest) lastHeartbeat.set(Number(monitorId), latest)
|
||||||
})
|
})
|
||||||
s.on('heartbeat', (beat: Heartbeat & { monitorID: number }) => {
|
s.on('heartbeat', (beat: Heartbeat & { monitorID: number }) => {
|
||||||
lastHeartbeat.set(beat.monitorID, beat)
|
lastHeartbeat.set(beat.monitorID, beat)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue