Scriptrunner - How to get a specific user's login history

Michael
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 14, 2024

I'm looking for / hoping that there is a way within the ScriptRunner console where I can get the total login history for a user.

We currently have one user that is stating they log in every day and we want to verify this, but we can't "check" this since Jira by default only shows their latest login date.

Is there a way to get more historic logins / login attempts for a user from Scriptrunner console / Jira?

Thanks,

Mike

2 answers

1 accepted

2 votes
Answer accepted
Ignacio Aredez GenAI Expert
Banned
February 14, 2024

To get a specific user's login history in Jira using ScriptRunner, you'll need to analyze Jira's application logs, specifically focusing on authentication events logged by Jira. This method requires access to the server's file system where Jira is hosted, as Jira doesn't provide a built-in feature to retrieve detailed login histories directly from its UI or database.

Here's a simplified approach:

Locate Log Files: Determine where Jira's log files are stored on your server. Login events are typically recorded in atlassian-jira-security.log within the Jira home directory's log folder.

Write a Groovy Script: Use ScriptRunner's console to execute a Groovy script that scans the log file(s) for login events related to the specific user. The script would look something like this:

groovy
// Path to the log file
String logFilePath = "/path/to/jira/home/log/atlassian-jira-security.log"
// Username to search for
String username = "user@example.com"

// Script to read the file and filter for login events by the user
new File(logFilePath).eachLine { line ->
if (line.contains("login") && line.contains(username)) {
println line
}
}


This script is a basic example and might need adjustments based on the exact format of your log files and the specific details you're looking for.

Considerations: Remember that log files can be large, and log rotation might affect where and how long login data is stored. Ensure you comply with any applicable privacy and data handling policies.

Michael
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 14, 2024

Thanks @Ignacio Aredez GenAI Expert

With that consideration in mind - we will no longer look into this.

thanks again,

MIke

0 votes
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 14, 2024

As mentioned by @Ignacio Aredez GenAI Expert jira doesn't natively store login activity. Only the last login.

But you could use a scriptrunner listener to catch the login event and create your own logging for that separate from the native jira logs.

Suggest an answer

Log in or Sign up to answer