SonarQube REST APIs : Read Metrics - sonarqube

I am using SonarQube version 6.7.1
I am trying to get JSON Response for our projects sonarQube statistics
Just want simple details like
Bug count, vulnerability count , % code duplication , code coverage
Tried URL http://sonar-server:9000/api/metrics&json=true but got error Unknown url, can someone point out correct URL
End Aim is to store Above counts for each run in time series DB .. any suggestions how to do it ?
May be i am not reading / understanding documentation clearly , possibly a pointer to tutorial or example or some other pointers will help me,

Try to use sonarqube.server.com:9000/api/metrics/domains, I am able to get json response from this.
APIs that you can use are listed at:
sonarqube.server.com:9000/web_api/api/metrics/domains/search
but just remove "web_api" while calling, to get json response.

Related

A rest service using spring 2 and jersey, unable to get response for some consumers

We have an application that uses asyncresponse and writes the data into a stream.
I upgraded to spring2 from 1.5.
And not sure if it could be releated but now with postman I get this error "Unexpected end of file".
Even in a java client , I get error "java.IO.EOFException: Unexpected end of zlib input stream".
But I get expected result in a curl command.
Now I suspect, this could be something either with user-agent or somewhere in spring2 or jersey , I need to set some properties to get rid of this.
There is no security , I excluded SecurityAutoConfiguration.java, in case somewhere it checks some user-agent.
Because of error I see in java client, I tried with server.compression.enabled=false (which is default anyway), but no luck.
I suppose I need to edit the question.
It seems there is some issue using StreamingOutput using spring2x. This is not streaming which I assumes results in all of above stated issues.
Any help is appreciated.

how to get bug count from every file of the project in sonarqube

if anybody knows please give me sql query or idea, I am not able to find common thing for getting bug count from projects_measures and projects table.
You can use this curl request:
curl <SONARQUBE_URL>/api/issues/search?ps=1&projectKey=<PROJECT_KEY>&facets=types
by using facets=types you will get the number of issues by type (bugs, code smells and vulnerabilities).

How to get more than 500 issues from SonarQube api

I'm using the SonarQube API in a java tool to process issues and add comments to them/change the issue status (e.g. wont fix)
The api/issues/search function has a page size limitation of 500 max. I have more than 500 issues and need to read this. I thought of performing mulitpule queries, but the issue keys are not numberical so I can not just increment and perform a query on the next 500.
Is there any way I can handle more than 500 issues from the API? I thought a workaround would be to get the list of issue keys from the api and query in batches, but this doesnt seem possible.
Short answer : no, it's not possible to get more than 500 issues in a single web service call.
Long answer : you should try to use a hook (either by using a plugin or by using a web hook) that is triggered on each project analysis => You'll then be able to browse all project's issues using pagination : api/issues/search?componentKeys=PROJECT_KEY&ps=500&p=1, then api/issues/search?componentKeys=PROJECT_KEY&ps=500&p=2, etc.
The total number of items can be found in the response, under "paging" -> "total".

How to get the code causing an issue in SonarQube or a link to it?

Is there a way to parameter the SonarQube web service to get the line of the code causing a specific error?
For instance, if I parameter the webservice to get all the blocking issues like this:
http://localhost:9000/api/issues/search?severities=BLOCKER
the Json returned gives the line's number of the issues but not the line's code. How to have the code of those lines?
Otherwise, is there a possibility to get a link to the line causing the error?
Thank you in advance
Check out the WebAPI documentation embedded in your SonarQube server (linked at the footer). For your specific use-case you'll see that this is a good match: api/sources .

JMeter REST Response is blank

I have searched extensively for the solution of this problem but did not get enough information. I am testing a GET request in REST API and although Sample Result is OK, I do not get any response in Response data tab. A screenshot is attached.
I am getting this error - ERROR - jmeter.protocol.http.sampler.HTTPJavaImpl: readResponse: java.util.zip.ZipException: Not in GZIP format
I have no java code. I know my REST API result is huge. (search result). Please suggest how do I get around this problem?
Thank you
Error
I remember facing this issue! Changing the implementation to java/HttpClient4/3.1 in the HTTP requests will work.

Resources