Hello,
How can i get information about user last login date via Script Runner?
Cheers,
Maciej O.
Hi Maciej,
have you tried to use LoginManager and the method getLoginInfo(String userName).getLastLoginTime()? It returns date as millisecond in long.
I hope I've helped you,
Best Regards,
P.S.
Pozdrowienia z Wrocławia
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.login.LoginManager
import java.text.SimpleDateFormat;
import java.util.Date;
def loginManager = ComponentAccessor.getComponentOfType(LoginManager.class)
def users=ComponentAccessor.getUserUtil().getUsers()
StringBuilder builder=new StringBuilder()
builder.append("<table border = 1><tr><td><b>User Name</b></td><td><b>Full Name</b></td><td><b>eMail Address</b></td><td><b>Last Login</b></td><td><b>Status</b></td></tr>")
users.each{
Long lastLoginTime = loginManager.getLoginInfo(it.username).getLastLoginTime()
String activeStatus=it.active
if(activeStatus=="false")
builder.append("<tr><td>"+it.username+"</td><td>"+it.displayName+"</td><td>"+it.emailAddress+"</td><td>Inactive User</td><td>"+it.active+"</td></tr>")
else if(lastLoginTime==null)
builder.append("<tr><td>"+it.username+"</td><td>"+it.displayName+"</td><td>"+it.emailAddress+"</td><td>Logon not found</td><td>"+it.active+"</td></tr>")
else{
Date date=new Date(lastLoginTime);
SimpleDateFormat df2 = new SimpleDateFormat("dd/MM/yy hh:mm");
String dateText = df2.format(date);
builder.append("<tr><td>"+it.username+"</td><td>"+it.displayName+"</td><td>"+it.emailAddress+"</td><td>"+dateText+"</td><td>"+it.active+"</td></tr>")
}
}
builder.append("</table>")
return builder
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Krupasindhu Nayak can anyone please help me with the script for getting the list of users in Confluence, Name, Email Address, and active and in active users list and created , last updated date in a single script? is that possible to get all these details in a single script? please help me in this thank you in advance..
The Exact scenario in confluence is needed
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried to use it and my script looks like that
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.user.util.UserUtil import com.atlassian.crowd.embedded.api.CrowdService import com.atlassian.crowd.embedded.core.util.StaticCrowdServiceFactory import com.atlassian.crowd.embedded.api.User import com.atlassian.jira.user.ApplicationUser import com.atlassian.jira.security.login.LoginManager import com.atlassian.jira.security.login.LoginInfo import com.atlassian.jira.user.util.UserManager import java.sql.Timestamp import com.atlassian.jira.bc.security.login.LoginService UserUtil userUtil = ComponentAccessor.getUserUtil() CrowdService crowdService = StaticCrowdServiceFactory.getCrowdService() result = "<table style=\"width:100%\"><tr><th>name</th><th>display name</th><th>email</th><th>directory</th><th>last login</th></tr>" userUtil.getUsers().findAll{user -> user.isActive()}.each{ user -> Long lastLoginTime = getLoginInfo(user.name).getLastLoginTime() result += "<tr><th>" + user.name + "</th>" + "<th>" + user.displayName + "</th>" + "<th>" + user.emailAddress + "</th>" + "<th>" + user.getDirectoryId() + "</th>" result += "<th>" + lastLogin + "</th></tr>" } result += "</table>" result
Can you tell me where is mistake? <error is in
Long lastLoginTime = getLoginInfo(user.name).getLastLoginTime()
Thanks in Advance
Maciej O.
PS: Wrocław jest piękny!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to use LoginManager. Define it before "each" loop:
def loginManager = ComponentAccessor.getComponentOfType(LoginManager.class)
and use it inside foreach in this way:
Long lastLoginTime = loginManager.getLoginInfo(user.name).getLastLoginTime()
you need to convert this long number to format of date.
Best Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks , one more question:
What exactly gives me loginManager.getLoginInfo(user.name).getLastLoginTime()
I get numbers like "1456303984535" is it miliseconds since last login?
Cheers,
Maciej O.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It seems that it could be done only from database: https://confluence.atlassian.com/jirakb/retrieve-last-login-dates-for-users-from-the-database-363364638.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.