Last Used field on API tokens #6567

Closed
opened 2025-12-29 19:42:28 +01:00 by adam · 4 comments
Owner

Originally created by @PieterL75 on GitHub (Jun 15, 2022).

Originally assigned to: @jeremystretch, @PieterL75 on GitHub.

NetBox version

v3.2.3

Feature type

Change to existing functionality

Proposed functionality

Add a 'Last used' property to the API token

Use case

I want to know if a token is actively being used.

Database changes

Add 'Last used' field (datetime) to 'users_token'

External dependencies

No response

Originally created by @PieterL75 on GitHub (Jun 15, 2022). Originally assigned to: @jeremystretch, @PieterL75 on GitHub. ### NetBox version v3.2.3 ### Feature type Change to existing functionality ### Proposed functionality Add a 'Last used' property to the API token ### Use case I want to know if a token is actively being used. ### Database changes Add 'Last used' field (datetime) to 'users_token' ### External dependencies _No response_
adam added the status: acceptedtype: feature labels 2025-12-29 19:42:28 +01:00
adam closed this issue 2025-12-29 19:42:28 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jun 15, 2022):

This is an interesting idea. My only concern is the introduction of an additional database query, but I wonder if it can be combined somehow with the existing auth query. 🤔

@jeremystretch commented on GitHub (Jun 15, 2022): This is an interesting idea. My only concern is the introduction of an additional database query, but I wonder if it can be combined somehow with the existing auth query. :thinking:
Author
Owner

@PieterL75 commented on GitHub (Jun 17, 2022):

@jeremystretch I have PR ready.
It adds the new field to the model, and updates the last_used when the TokenAuthentication.authenticate_credentials is called.

It does introduce a write for each API call., so it only update once a minute..

@PieterL75 commented on GitHub (Jun 17, 2022): @jeremystretch I have PR ready. It adds the new field to the model, and updates the last_used when the TokenAuthentication.authenticate_credentials is called. It does introduce a write for each API call., so it only update once a minute..
Author
Owner

@sdktr commented on GitHub (Jun 18, 2022):

Does it stil work when netbox is run in maintenance/readonly mode?

@sdktr commented on GitHub (Jun 18, 2022): Does it stil work when netbox is run in maintenance/readonly mode?
Author
Owner

@PieterL75 commented on GitHub (Jun 19, 2022):

@sdktr Any request with an API key will update the last_used field, independent of the accesslevel of the API token or state of Netbox

But when reading the docs https://docs.netbox.dev/en/stable/configuration/dynamic-settings/#maintenance_mode and this comment https://github.com/netbox-community/netbox/discussions/6219 , I think we should not update the last_used field when in maintenance mode.

Thank you for pointing that out, I'll update the PR

@PieterL75 commented on GitHub (Jun 19, 2022): @sdktr Any request with an API key will update the last_used field, independent of the accesslevel of the API token or state of Netbox But when reading the docs https://docs.netbox.dev/en/stable/configuration/dynamic-settings/#maintenance_mode and this comment https://github.com/netbox-community/netbox/discussions/6219 , I think we should not update the last_used field when in maintenance mode. Thank you for pointing that out, I'll update the PR
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6567