Skip to content

Systemd logs always empty on systems with a battery (json/v2 cannot unmarshal Battery) #2746

Closed

Description

@andreasmuellerka

Version: hub and agent 0.21.1 (also present on main as of 27af11c)

Problem

On systems that report a battery (laptops), the systemd service sheet always shows "No logs found." Logs work on systems without a battery. The agent advertises jl: true and running journalctl as the agent works; the hub never sends the request to the agent (the request to /api/beszel/systemd/logs returns 200 with {"logs":""} in ~2 ms, vs. ~24 ms on a system without battery).

Cause

getSystemdLogs in internal/hub/api.go reads the system info with

if err := systemRecord.UnmarshalJSONField("info", &info); err != nil || !info.SystemdLogs {
    return e.JSON(http.StatusOK, map[string]string{"logs": ""})
}

PocketBase's Record.UnmarshalJSONField uses encoding/json/v2. system.Battery is [2]uint8 and only implements MarshalJSON (numeric array). json/v2 expects a base64 string for [N]byte by default, so unmarshalling "bat":[59,5] fails:

json: unable to unmarshal JSON array into Go system.Battery within "/bat"

The error is swallowed and treated as "no journal access".

Reproduce

Unmarshal {"bat":[59,5],"jl":true} into system.Info with encoding/json/v2 → error, SystemdLogs stays false. Without bat it works.

Suggested fix

Add an UnmarshalJSON to Battery that accepts a numeric array (mirroring MarshalJSON), and/or log the unmarshal error in getSystemdLogs instead of silently returning empty logs. The existing test TestStatsBatteryNumericArrayUnmarshal only covers json v1.

Activity

  1. aditya-rai-5 commented on Nov 1, 2026

    @aditya-rai-5
    Contributor

    i will working on this and raise a PR shortly

  2. andreasmuellerka commented on Nov 5, 2026

    @andreasmuellerka
    Author

    Thank you both, @aditya-rai-5 for the quick fix and @henrygd for the quick review and merge! Logs from my laptops were the one thing missing, and it's great to see this solved so fast. I really love Beszel: it's lightweight, a pleasure to use, and has become a tool I rely on every day. Thanks for all the work you put into it!

  3. locked and limited conversation to collaborators on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions