netbox-community / netbox

The premier source of truth powering network automation. Open source under Apache 2. Try NetBox Cloud free: https://netboxlabs.com/free-netbox-cloud/
http://netboxlabs.com/oss/netbox/
Apache License 2.0
15.91k stars 2.55k forks source link

store who created and last modified netbox objects #15323

Open ITJamie opened 7 months ago

ITJamie commented 7 months ago

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

abhi1693 commented 7 months ago

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

ITJamie commented 7 months ago

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 commented 7 months ago

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

jeffgdotorg commented 6 months ago

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.

jeremystretch commented 6 months ago

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.

ITJamie commented 4 months ago

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

goteamkor commented 2 months ago

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?

a084ed22 commented 1 month ago

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