which versions are you using: SonarQube - Developer Edition Version 8.4.2 (build 36762)
what are you trying to achieve: I am analyzing C code using
sonar-scanner \
-Dsonar.projectKey=my_code \
-Dsonar.sources=. \
-Dsonar.host.url=http://server:8082/ \
-Dsonar.login=key \
-Dsonar.cpp.file.suffixes=- \
-Dsonar.objc.file.suffixes=- \
-Dsonar.inclusions=src/**,test/** \
-Dsonar.branch.name=${BRANCH} \
-Dsonar.cfamily.threads=8 \
-Dsonar.cfamily.build-wrapper-output=build/sonar
It works like a charm, but I need to make graph per project (overall metrics)
Number of Bugs
Number of Code smells
Number of Vulnerabilities
Coverage
I have these numbers from the web UI, but I need to interface to a grafana graph system automagically. I like to either
log a json/any-structured-format of these numbers to a file every time I scan, or
access the current level via a pull to the sonarqube system
Any ideas for this?
Colin
(Colin)
January 8, 2021, 2:14pm
2
Hey there.
The Web API (documentation linked in the footer of your instance) can be used to pull data from SonarQube â and hereâs a trick, you can use your browserâs dev tools to see what API calls are being made whenever you view a page in SonarQube.
For what youâve mentioned, GET api/measures/component and GET api/measures/search_history will probably be useful for you.
Out of curiosity, what makes viewing these measures in Grafana better/more useful/more interesting than right in SonarQube?
thanx @Colin - the thing is that the sonarqube is just one part of many metrics that I need to track.
The UI in https://sonarqube/project/activity?id=somekey is really good (and similar to what I need)
Colin:
api/measures/component
Looks to be the right direction - I found the âWeb APIâ next to âAboutâ - LOTS of good stuff in there. Now I just need the first example
I am a Linux user, so it seems to be in the line of
$ curl -X GET -u sonaruserid:ColinIsANicePerson https://sonarqube/api/measures/component
But it barfs â{âerrorsâ:[{âmsgâ:âThe âcomponentâ parameter is missingâ}]}â
which seems to be project id - that I have not supplied yetâŚ
(Do we have have the same password G )
peter.toft
(Peter Toft)
February 5, 2021, 3:14pm
6
Colin
(Colin)
February 5, 2021, 3:22pm
7
Checkout GET api/measures/component
And, anywhere you see data in SonarQube, you can open your browserâs Dev Tools and see what network calls are being made. Makes finding the right API (to then go find in the docs for more details) super easy.
peter.toft
(Peter Toft)
February 5, 2021, 5:10pm
8
Huuh - I get
$ curl -k -X GET âhttps://sonarqube/api/measures/component â
{âerrorsâ:[{âmsgâ:âThe âcomponentâ parameter is missingâ}]}
peter.toft
(Peter Toft)
February 17, 2021, 8:55am
10
@Colin or others - it would be fantastic with a hint here
Colin
(Colin)
February 17, 2021, 9:12am
11
Hi Daniel,
The error message is pretty clear. You need to add query parameters (such as component
)
// 20210217101141
// https://next.sonarqube.com/sonarqube/api/measures/component?component=org.sonarsource.javascript%3Ajavascript&metricKeys=coverage
{
"component": {
"id": "5eab015a-1f76-4ba4-bd89-bf547132d673",
"key": "org.sonarsource.javascript:javascript",
"name": "SonarJS",
"description": "SonarQube JavaScript/TypeScript Analyzer",
"qualifier": "TRK",
"measures": [
{
"metric": "coverage",
"value": "95.8",
"bestValue": false
}
]
}
}
I still think following this tip would have helped you.
Colin:
And, anywhere you see data in SonarQube, you can open your browserâs Dev Tools and see what network calls are being made. Makes finding the right API (to then go find in the docs for more details) super easy.
@Colin THANX - you are golden