Sonar Measures API for a given timestamp

Hi,

We are using Sonar 6.7.5. I want to know how can we merge the result of the following APIs. I need this to get metrics data for a given sonar project and for a given timestamp.

Measures API
/api/measures/component?format=json&component=pb&metricKeys=ncloc,violations&includealerts=true

Project_Analyses
/api/project_analyses/search?project=pb

Hi,

I believe what you’re looking for is api/measures/search_history.

 
HTH,
Ann

Hi Ann,

Thanks for the response.

We are trying to build a Streaming Data Platform to load data from Sonar API to a Staging area to build an analytics platform. I have thought of using the following APIs to get the necessary Sonar information.

  • api/ce/activity - Generate the list of project keys for a given timeframe from the background tasks.
  • api/measures/search_history - Run this API for all project keys generated from the

Do you think this is the right strategy i.e would you suggest an event based trigger(if there is one) that would serve as input to the second API over using the project keys from the background tasks API?

Thanks again for all your help!

Vijay

Hi Vijay,

It gets more interesting as I get more hints what you’re after! :slight_smile:

SonarQube has a built-in “event based trigger” called webhooks. Depending on which particular metrics you’re after, it may the only thing you need. After each analysis, your webhooks will be fired and in the payload will be the analysis’ Quality Gate status as well as the values of each of the QG metrics.

 
HTH,
Ann

Hi Ann,

Thanks again for the response. I was actually going through the link and I was kind of interested what metrics the payload would include. It looks like the payload only includes metrics configured with Quality Gate.

I am interested in seeing the following metrics. Just wondering if this is possible.

ncloc,violations,new_vulnerabilities,critical_violations,major_violations,minor_violations,info_violations,blocker_violations,tests,test_success_density,test_errors,test_failures,coverage,line_coverage,sqale_index,alert_status

I have also seen a link in Stack Overflow which says we cannot actually any other metrics than what specified in Quality Gate.

Please clarify. Thank you for your help!

Vijay

Hi Vijay,

Your understanding is correct. That’s why I said “depending on which particular metrics you’re after”. So it looks like you’ll need to use web services for additional data after all.

 
Ann

Hi Ann,

Thanks again for the swift response.

Its OK. We would go the API route :slight_smile:

Vijay