netbox icon indicating copy to clipboard operation
netbox copied to clipboard

store who created and last modified netbox objects

Open ITJamie opened this issue 11 months ago • 3 comments

NetBox version

v3.7.3

Feature type

Data model extension

Proposed functionality

add fields to log who created an object and who last modified an object. expose these fields on API endpoints

Use case

knowing who created a device/interface/vm in netbox can be useful.

currently with changelog set to indefinate its technically possible to pull this information, but many orgs will not be keeping logs indefinitely. it is also not the netbox default so this data will be lost

Database changes

add two foreign key fields to the base models that reference the user object who created and who last updated an object.

External dependencies

n/a

ITJamie avatar Mar 01 '24 15:03 ITJamie

What should happen if the user who created or updated is deleted? Should that be allowed? If yes, what will happen to this data?

abhi1693 avatar Mar 05 '24 05:03 abhi1693

Same as what happens to the object change model right now i would guess. Though i do see the argument that maybe it should just be text fields and store just the username?

ITJamie avatar Mar 05 '24 08:03 ITJamie

The other option would be to adjust the cleanup script code to never prune object changelogs of "creation" events and also not to delete the most recent changelog event for an object

ITJamie avatar Mar 05 '24 09:03 ITJamie

Same as what happens to the object change model right now i would guess. Though i do see the argument that maybe it should just be text fields and store just the username?

Usernames are mutable, so a text field wouldn't cut it. We would need to use a more stable identifier such as users.netboxuser:42 internally. Those IDs don't appear to get reused.

jeffgdotorg avatar Mar 27 '24 21:03 jeffgdotorg

FWIW we have the same problem with the change log today: The ObjectChange model stores both the numeric user ID as well as the user name at the time the change was recorded. This ensures that some record of the associated user is preserved should the user be deleted sometime after the change was made.

An alternative would be to fully prevent the deletion of users. This might be feasible now that we've moved to a custom User model in v4.0, but might be messy.

jeremystretch avatar Apr 03 '24 14:04 jeremystretch

An argument could be made that users should only be "soft" deleteable and not actually removed from the db. that would keep the foreign-key references valid

ITJamie avatar May 18 '24 10:05 ITJamie

An argument could be made that users should only be "soft" deleteable and not actually removed from the db. that would keep the foreign-key references valid

if they aren't removed from the db, how would you handle a new user with the same username?

goteamkor avatar Aug 03 '24 00:08 goteamkor

Exactly the same way you'd handle the case if both were active, adding something to the username to disambiguate.

a084ed22 avatar Aug 05 '24 06:08 a084ed22