[management] Record peer connection and disconnection events
Describe your changes
Admins have no history of when a peer connected to Management or where it connected from. Peer status and last seen only show the current state, which is the gap raised in the community request for basic security visibility in every deployment.
Management now records peer.connect and peer.disconnect activity events. They are written only after the existing session checks accept the change, so a duplicate connect or a disconnect from an older stream adds no entry. Both are system events and follow the existing activity log setting and permissions.
A connect event carries the source IP seen on the sync stream, which is recorded whether or not geolocation is enabled. Country and city are added only when the peer's stored location was resolved for that same address, so a location from an earlier connection is never attached. The meta keys (location_connection_ip, location_country_code, location_city_name) match the existing peer-added events, so the dashboard renders both the same way. Disconnect events carry no address.
"Connected" here means connected to Management. It says nothing about peer-to-peer tunnels or traffic.
Known limitations, open for discussion in the ticket:
- History is best effort. A Management crash can leave a session without a disconnect event.
- A delayed disconnect can be recorded after a newer reconnect, so the history can be out of order. The peer's current status is unaffected.
- Every accepted reconnect produces an event, which adds activity log volume. Retention follows the existing activity log settings.
Dashboard counterpart: https://github.com/netbirdio/dashboard/pull/896
Issue ticket number and link
Closes https://github.com/netbirdio/netbird/issues/8616
Stack
Checklist
- Is it a bug fix
- Is a typo/documentation fix
- Is a feature enhancement
- It is a refactor
- Created tests that fail without the change (if possible)
- I ran and tested this change locally — I did not rely on CI to find out whether it works
- This PR has a single purpose (not a fix + refactor + feature in one)
- This change is a trivial fix, OR it links an issue the NetBird team agreed on beforehand. Changes to the public API, gRPC protocols, functionality behavior, CLI / service flags, or new features always need that agreement first. See CONTRIBUTING.md.
By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.
Documentation
Select exactly one:
- I added/updated documentation for this change
- Documentation is not needed for this change (explain why)
Docs PR URL (required if "docs added" is checked)
Paste the PR link from https://github.com/netbirdio/docs here: