canonical / ubuntu-pro-client

Ubuntu Pro Client for offerings from Canonical
https://canonical-ubuntu-pro-client.readthedocs-hosted.com/en/latest/
GNU General Public License v3.0
51 stars 69 forks source link

Feature: Add persistent attach/detach history file #3167

Open 106106 opened 3 weeks ago

106106 commented 3 weeks ago

Please describe the scenario where the new feature would be useful

A customer requested to know when a machine was onboarded to Ubuntu Pro for troubleshooting purposes. This would also be useful for support to easily determine the pro attachment history of a machine.

Describe the solution you'd like

Ideally a file like /var/lib/ubuntu-advantage/attachment.json

cat /var/lib/ubuntu-advantage/attachment.json
{"attached_at": "2024-06-13T23:14:30.054382+00:00"}

but persistent and append only that shows the attach/detach time of a machine. something like

cat /var/lib/ubuntu-advantage/attachment_history.json
{"attached_at": "2024-06-13T23:14:30.054382+00:00"}
{"detached_at": "2024-06-13T23:15:30.054382+00:00"}
{"attached_at": "2024-06-13T23:15:35.054382+00:00"}
etc.

Current behavior

The current behaviour is that /var/lib/ubuntu-advantage/attachment.json is removed after a pro detach. The history can be extracted from /var/log/ubuntu-advantage.log with sudo grep "Executed with sys.argv: \['/usr/bin/pro', 'attach'" /var/log/ubuntu-advantage.log but it's not ideal or friendly to troubleshooting/easily seeing the history of a machine.

Additional context

I'm happy to try to write the code/pull-request for this, if pointed in the right direction and this is deemed a worthwhile addition