Using the Health Check API

I am writing a tool that interrogates systems supported by our team and uploading the data to New Relic for up-time reporting, metrics (if available), and alerting.

The documentation is limited on how to call ‘api/system/health’.

  • How to format the API call
    http://sonar.blah.com/api/system/health?<some_login>=<token_here>
  • Can I use a token or is there a username/password that needs to be created
  • What is the expected output/format of the json response {"health":"GREEN","causes":[]}
    More specifically what could go into the array after "causes":[]

Any help would certainly be appreciated, I’ve been searching every resource I could but haven’t had much luck.

1 Like

Hello !

Accordingly to the doc https://docs.sonarqube.org/latest/extend/web-api/, you can call the api this way :

curl -u THIS_IS_MY_TOKEN: https://sonarqube.com/api/system/health

You can find an example of the output format in the embedded api documentation, or our live example here

About the message you can find in the causes, there is no official list : this is just plaintext, mean to be human readable. you can find example of Strings by browsing the source code here.

Some examples :

  • Compute Engine is not operational
  • Elasticsearch status is RED
  • SonarQube webserver is not up
  • Can't connect to DB

Thank you so much @pierreguillot

Unfortunately for me when I try the query, the API is responding with a 403 Forbidden. I’m using Postman, and I’ve imported the curl command.

The response is {"errors":[{"msg":"Insufficient privileges"}]}

Can you help me understand if there is configuration that is needed before I can use my token? If I visit those URL’s while logged in, I see valid responses.

How do I convert this curl into a REST call? Is there a param to put after /api/system/health?

I found the answer on stack overflow:

In addition to the answer
1. Open POSTMAN
2. Click on "import" tab on the upper left side.
3. Select the Raw Text option and paste your cURL command.
4. Hit import and you will have the command in your Postman builder!
5. If -u admin:admin are not imported, just go to the Authorization 
  tab, select Basic Auth -> enter the user name eg admin and password eg admin.
This will automatically generate Authorization header based on Base64 encoder

Insufficient privileges means that your token has been recognised, but the user that own this token has no system admin permission.

The api endpoint documentation specify : Require 'Administer System' permission or authentication with passcode

Pierreguillot,

This is a continuation of the tread and the web_api.

I use “curl -u login:password http://sonarurl/api/system/health” and it works flawlessly

but when use the token for user “login” token3 it does not and only give an empty lime

“curl -u token3: http://sonarurl/api/system/health

If I put in nonsense it still gives me an empty line?

Is there anyway to see if curl is passing the token to SonarQube like it is the user:password?

To recap user:password works fine but the TOKEN: does not with curl api/system/health

Thank you