Get Octopus Deploy inactive users

Greetings.

Our team would like to have a way to identify which users are not using Octopus Deploy in a determined period of time, I have read that I can have the events of the users in Octopus via API, but the query doesn’t have a way to filter by the user and search one by one wouldn’t be a viable option. are there other ways to do that without making a brute search?

Thank you in advanced.

Hey @andres.carcamo,

Nice to hear from you again, that is a great question!

Unfortunately Octopus doesn’t capture user login events, and so it looks like you are correct that it will require manually searching the /events endpoint for each user’s last event to determine when they were last active.

I’ll look into getting an example script put together for it to hopefully save you some effort, I’ll let you know as soon as it’s ready!

Best Regards,

1 Like

Hi @andres.carcamo,

Sorry for the delay with this, I was looking into ways to make it a bit faster but it looks like we are about to make some significant changes to the /events endpoint to improve performance!

To improve performance, archived audit logs older than 90 days will only be available as downloadable files. These audit log files can be accessed through the overflow menu (three dots) on this page or through the API. Learn more about this change and share your feedback.

The following script should output each unique username and the time their most recent event took place. Essentially if a username isn’t included in the output then they didn’t perform any actions in that space for that timeframe:

$ErrorActionPreference = "Stop";

# Define working variables
$octopusURL = "https://<octopus-url>.octopus.app"
$octopusAPIKey = "API-XXXXXX"
$header = @{ "X-Octopus-ApiKey" = $octopusAPIKey }

$spaceName = "Default"

# Time format mm/dd/yyyy hh:mm:ss
$fromDate = "9/1/2022 00:00:00"
$toDate = "9/14/2022 00:00:00"

# Get space
$space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName}

# Get list of events to check that don't include usernames like system or octoadmin 
$eventList = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/events?from=$([datetime] $fromDate)&to=$([datetime] $toDate)&take=2147483647" -Headers $header).Items | Where-Object {([datetime]$_.Occurred -ge [datetime]$fromDate) -and ($_.Username -notlike "system") -and ($_.Username -notlike "octoadmin")}

# Output unique usernames and their last event time
$eventNames = @()
foreach ($event in $eventList) {
    if(!$eventNames.contains($event.Username)){
    write-host "$($event.Username) - $([datetime] $event.Occurred)" 
    $eventNames += $event.Username   
    }
}

Hopefully that helps set you in the right direction to check users who aren’t active, but feel free to let me know if you have any questions at all!

Best Regards,