How to find active users in Sonarqube

Hello,

I am using sonarqube 9.0.1.46107 version running in a container.

I need to retrieve the list of active users in sonarqube for last 3 months to understand the usage.

Is there any API available to retrieve this information?

Please share the details.

Welcome :slight_smile:

use the web api api/users/search , see docs https://yoursonarhosturl/web_api/api/users

Get a list of active users.
The following fields are only returned when user has Administer System permission or for logged-in in user :

  • ‘email’
  • ‘externalIdentity’
  • ‘externalProvider’
  • ‘groups’
  • ‘lastConnectionDate’
  • ‘tokensCount’

Field ‘lastConnectionDate’ is only updated every hour, so it may not be accurate, for instance when a user authenticates many times in less than one hour.

Gilbert

1 Like

Hi @Rebse

Thank you for quick help.

I will try the suggested api.

I’m currently on LTS version 8.9.3 and have troubles getting lastConnectionDate out via API. I do a general search over all users (/api/users/search?ps=500) and I get all fields as described in the docs for each user - except lastConnectionDate.

According the docs this field should be available since 7.7, but why it is not shown via API? The user I’m using has administrator rights.
Regards, Thomas

Hi Thomas,

just tested on SQ 8.9.1 Enterprise with pagesize 500 as user with admin rights and got all fields, i.e.

users": [
  {
      "login": "xxx",
      "name": "xxx, xxx - xxx",
      "active": true,
      "email": "xxx.xxx@foobar.com",
      "groups": [
          "sonar-users"
      ],
      "tokensCount": 0,
      "local": false,
      "externalIdentity": "xxx",
      "externalProvider": "sonarqube",
      "avatar": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "lastConnectionDate": "2020-10-13T09:08:45+0200"
  },

Gilbert

As User admin or user with administration rights?

My output (one user):

{'active': True,
 'avatar': 'xxxx',
 'email': 'xxx@xxx.at',
 'externalIdentity': 'xxx',
 'externalProvider': 'sonarqube',
 'groups': ['sonar-users'],
 'local': False,
 'login': 'xxx',
 'name': 'xxx',
 'tokensCount': 0}

No idea why …

Regards, Thomas

Sorry meant as user with admin rights.

Well, than I really don’t get the point why I do not see lastConnectionDate in the output. Tried different users with admin rights, no change. Is there some kind of switch to use a different version in the API or is the API just as is and comes with settings from the current SQ version?

Regards, Thomas

Does your user has ‘Administer System’ permissions ?
I’m not sure what is meant by

Get a list of active users.
The following fields are only returned when user has Administer System permission or for logged-in in user

in the web api docs for api/users/search

Hi there,

I found the mistake - me. :slight_smile: I assumed that even for users which haven’t logged in yet a lastConnectionDate is set anyway, which is not the case.

Well, sometimes I’m really, really stupid.

Regards, Thomas

1 Like