Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Sql query to get the list of Jira and Jira Service Desk Active users last login details

Surender November 23, 2018

Hi All,

Is there any Sql query to get the list of Jira Software as well as Jira Service Desk Active users last login details.

I have found the below article as part of my search. but this article is NOT giving the last login of the "Jira and Jira Service Desk Active users last login'


https://confluence.atlassian.com/jirakb/how-to-get-a-list-of-active-users-counting-towards-the-jira-application-license-278695452.html\\ 
https://confluence.atlassian.com/jirakb/retrieve-last-login-dates-for-users-from-the-database-363364638.html

I tried to make a query by using these two articles but that didn't worked for me.


Please advise.

Thanks,
Surender

1 answer

1 vote
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 26, 2018

I think you can combine these two queries, but there are some considerations when doing so.   Each of these articles is seeking something slightly different so the SQL select statements are specifically geared for the results in question.  That said, I think I have found a way for you to see the last login time of specific users in a licensing role.  For Service Desk Agents:

SELECT d.directory_name AS "Directory", u.user_name AS "Username",
    to_timestamp(CAST(attribute_value AS BIGINT)/1000) AS "Last Login", lrg.license_role_name
FROM cwd_user u
JOIN (
    SELECT DISTINCT child_name
    FROM cwd_membership cm
    JOIN licenserolesgroup gp ON cm.parent_name = gp.GROUP_ID
    ) AS cm ON cm.child_name = u.user_name
JOIN (
    SELECT *
    FROM cwd_user_attributes ca
    WHERE attribute_name = 'login.lastLoginMillis'
    ) AS a ON a.user_id = u.id
JOIN cwd_directory d ON u.directory_id = d.id
JOIN cwd_membership m
         ON u.id = m.child_id
            AND u.directory_id = m.directory_id
       JOIN licenserolesgroup lrg
         ON Lower(m.parent_name) = Lower(lrg.group_id)
WHERE  d.active = '1'
       AND u.active = '1'
    AND license_role_name = 'jira-servicedesk'
ORDER BY "Last Login" DESC;

 

And for Jira Software users:

SELECT d.directory_name AS "Directory", u.user_name AS "Username",
    to_timestamp(CAST(attribute_value AS BIGINT)/1000) AS "Last Login", lrg.license_role_name
FROM cwd_user u
JOIN (
    SELECT DISTINCT child_name
    FROM cwd_membership cm
    JOIN licenserolesgroup gp ON cm.parent_name = gp.GROUP_ID
    ) AS cm ON cm.child_name = u.user_name
JOIN (
    SELECT *
    FROM cwd_user_attributes ca
    WHERE attribute_name = 'login.lastLoginMillis'
    ) AS a ON a.user_id = u.id
JOIN cwd_directory d ON u.directory_id = d.id
JOIN cwd_membership m
         ON u.id = m.child_id
            AND u.directory_id = m.directory_id
       JOIN licenserolesgroup lrg
         ON Lower(m.parent_name) = Lower(lrg.group_id)
WHERE  d.active = '1'
       AND u.active = '1'
    AND license_role_name = 'jira-software'
ORDER BY "Last Login" DESC;

Neither of these queries should return inactive users

Surender November 27, 2018

Hi Andrew,

 

Thanks for the response. 

The query seems to be working but it is not listing ALL the users login details.

Here is the output for the Jira Service Desk users last logins based on the query given above.

 

"Active Directory server" "865980" "2018-09-21 16:59:15+00" "jira-servicedesk"
"Active Directory server" "132885" "2018-08-22 18:27:16+00" "jira-servicedesk"
"Jira Internal Directory" "Local.Admin.User" "2018-08-02 20:35:37+00" "jira-servicedesk"
"Jira Internal Directory" "uditjakhotia" "2018-04-23 21:01:56+00" "jira-servicedesk"
"Jira Internal Directory" "nkothapalli" "2018-04-13 18:08:57+00" "jira-servicedesk"

 

Thanks,

Surender

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 27, 2018

Are you looking for the login times of users in the Jira Service Desk customer role?  If so, those users are not actually expected to be returned by either of the queries I have listed above.  The reason for that is that users in this role are actually unlicensed users in Jira.  They don't consume a license seat, hence Service Desk allows you to have an unlimited number of customers in that role.

The results you see there are users in the Service Desk Agent role.  These are users that consume a license seat for service desk.

Does this explain the results you see?  Or are you expecting to see something different?

Surender November 27, 2018

Hi Andrew,

I understand the licensing functionality. 

I am looking to get the last login details of the service desk agents (Licensed users) not the customers (Unlicensed users).

Currently we have around 200 Service desk agents. but as per the above query i am getting only 5 users last login details.

It would be helpful for me if i get a last login of the users,

- Who were never logged/used the service desk 

- Who were not logged in for morethan 30 days.

 

I am looking the above functionality to the Jira Software too.

 

We are using "Jira Service Desk" and "Jira Software" as our application access names/categories. 

 

Hope it clarifies.

 

Thanks,

Surender

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 3, 2018

I'm not sure why you would only be seeing 5 results if you have 200 that fit this application access role.  The SQL looks to be correct as far as I can see it.

The only thing I can think of is that if these other users have never logged into this Jira site, they would not have any value for their last login time.  Hence they would not be returned by this specific query.  Additionally, if their user account is disabled in Jira, or the user directory is disabled, again they would not be returned by this query.

Perhaps the SQL syntax could be different on database types other than postgresql.  Are you using postgresql?  Or Mysql? MS Sql? Oracle?

Surender December 4, 2018

Hi Andrew,

We are using PostgreSQL only.

Don't understand whats missing here.

I checked manually this morning and out of 200 users 181 users are logged in and their last login is not morethan 180 days.

We are using AD directory and all of those users accounts are Active. (I checked all those users in AD).

Please help me with the query that brings all the Active users who are using Jira Software/Jira Service Desk licenses. (This also works for me as alternative to my original ask)

 

Thanks,

Surender

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 6, 2018

Going back to the license count KB, there is a warning about

This SQL query may not return accurate results if you are using nested groups in LDAP or Crowd, or if you have users with duplicated usernames across multiple directories.

So I guess the first thing to understand is are you getting accurate results from that KB when just looking for the users counting towards the licenses (not looking at last login date yet)?   

Do you have multiple user directories in use in Jira?   Perhaps some of these user accounts are being excluded from the query because another user directory is disabled, but has the same usernames as an active directory.

krishnakanth_av May 14, 2019

HI @Andy Heinzer ,

Can you help us the SQL query- 

we need to find out the the list of active users who are true users-

1) Users who are never logged in or not logged into jira service desk from last 12 months, these users might have logged in Jira software.

2) Users who are never logged in or not logged into jira software from last 12 months, these users might have logged in Jira service desk.

we are trying to do the user clean-up due to license issue.

Thanks & Regards

Krishna

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 15, 2019

Hi Krishna,

In reviewing my previous answer on this thread, I think I might have missed something.  It is possible that you have users that have both the service desk agent role and a Jira Software license role as well.  When these users login to Jira, SQL is recording the login time of that event.  That login event doesn't tell us which product they are actually utilizing (Service Desk or Software). 

So you could have users are active in one but not the other.  I can't find a good way to find that information via SQL accurately.  I think I have misunderstood the original question's request here.

I can't see how we will be able to query what I think you are looking for here from SQL. 

krishnakanth_av May 15, 2019

Thanks @Andy Heinzer ,

Is there any way that I can get sql query - users who are not logged in to the Jira or never logged in for the last 12 months ?

If i can have this sql script, we try to schedule it and do the clean for every year.

 

Thanks & Regards

Krishna

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 17, 2019

Hi Krishna,

You can certainly use the KB Retrieve last login dates for users from the database to try to find this.   I am afraid that I do not have a more succinct way to sort out the past one year from this query.  It is ordering the values by last login at least, but since the query is using the cast parameter is makes it a bit more difficult to search this back to a variable period of say one year so that you can run the same query and only find inactive users that way.

It would probably be best to run this query just to find the usernames of these users.   I don't suggest that you make changes to the database directly as a means to remove these users.

Andy

Suggest an answer

Log in or Sign up to answer