store who created and last modified netbox objects #9314

Open
opened 2025-12-29 20:48:18 +01:00 by adam · 8 comments
Owner

Originally created by @ITJamie on GitHub (Mar 1, 2024).

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

Originally created by @ITJamie on GitHub (Mar 1, 2024). ### 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
adam added the type: featurecomplexity: mediumnetboxstatus: backlog labels 2025-12-29 20:48:18 +01:00
Author
Owner

@abhi1693 commented on GitHub (Mar 5, 2024):

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 commented on GitHub (Mar 5, 2024): What should happen if the user who created or updated is deleted? Should that be allowed? If yes, what will happen to this data?
Author
Owner

@ITJamie commented on GitHub (Mar 5, 2024):

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 on GitHub (Mar 5, 2024): 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?
Author
Owner

@ITJamie commented on GitHub (Mar 5, 2024):

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 commented on GitHub (Mar 5, 2024): 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
Author
Owner

@jeffgdotorg commented on GitHub (Mar 27, 2024):

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 commented on GitHub (Mar 27, 2024): > 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.
Author
Owner

@jeremystretch commented on GitHub (Apr 3, 2024):

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 commented on GitHub (Apr 3, 2024): 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.
Author
Owner

@ITJamie commented on GitHub (May 18, 2024):

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 commented on GitHub (May 18, 2024): 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
Author
Owner

@ghost commented on GitHub (Aug 3, 2024):

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?

@ghost commented on GitHub (Aug 3, 2024): > 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?
Author
Owner

@a084ed22 commented on GitHub (Aug 5, 2024):

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

@a084ed22 commented on GitHub (Aug 5, 2024): Exactly the same way you'd handle the case if both were active, adding something to the username to disambiguate.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9314