Sonar API accessing Multiple Metrics - sonarqube

I am trying to use Sonar API for getting multiple metrices. When I am trying to get single Metric it is working fine but when giving a comma separated list it is returning blank response. E.g.
https://localhost/sonar/api/resources?format=json&metrics=tests [Works fine and returns response]
https://localhost/sonar/api/resources?format=json&metrics=ncloc [Works fine and returns response]
https://tools.publicis.sapient.com/sonar/api/resources?format=json&metrics=ncloc,tests [Returns blank reponse i.e [] json ]
Am I doing it wrong. I have used comma separated list previously and it used to work fine. But now I am not able to figure out what is the issue
My Sonar version is 5.6

api/resources is deprecated. Its metrics parameter does accept comma-separated values (test it in a browser first, and careful with any reverse-proxy that may rewrite URLs), but you're better off using the most modern and up-to-date API: api/measures (documentation embedded in your SonarQube server), which also supports multiple values for metricKeys parameter.

for me api/resources works fine with multiples metrics, i call like that
https://localhost/sonar/api/resources?resource=[keyproject]&metrics=coverage,blocker_violations,critical_violations,sqale_debt_ratio

Related

Is there a NiFi API to read the Processor History?

I am using NiFi API to build a custom application. I am unable to find an API that captures the processor history in a format as shown below. Does anyone know if this API exists?
I have tried many of the API's here, but it's not obvious any of these can do the trick.
NiFi REST Api documentation
You can use the GET/processors/{id} to get back this information in the form of a ProcessorEntity. This contains all fields as shown in your screenshot: name, type, status, counters of last 5 minutes...
Inside the ProcessorEntity object, you can find the ProcessorStatus object which contains the name, type, status, 5min snapshot information per node and aggregated etc...
I included some links as examples to these objects from the NiFi python client, but you can also find some examples on the NiFi REST API docs you linked yourself.

SonarQube REST APIs : Read Metrics for individual projects

My question:
I am using SonarQube version 7.1 and trying to extract the metrics and quality gate related to individual projects.
What we have tried
We were using Python SonarQube API to extract these data before our company upgraded to version 7.1. "api/resources" web service Deprecated since sonarqube5.4, so we cannot use it anymore.
I have also tried using getting data using CURL command via Web API using
curl -i -H "Content-Type: application/json" -H "x-api-key:token" -X GET 'http://MY_HOST/api/measures/component?metricKeys=key&component=project_key'
We are able to get a json payload for individual metrics, but involves tedious task of creating the URL every single time.
But I wanted to know if there is a better/smarter way to access these "measures", be it any language or implementation.
You could do this:
Call the API api/metrics/search first to get a (json) list of all the metrics and then iterate over that list and create a comma separated string of all the metric keys.
For example something like this: ncloc,complexity,violations .. as mentioned in the parameters example value in the API documentation here.
Then you could just add this comma separated list to the url as a parameter something like: http://MY_HOST/api/measures/component?metricKeys=ncloc,complexity,violations&component=project_key
and call it once to get the response for all metrics.
Also, I haven't tried this, but as per the latest documentation, the parameter component is optional. So if you omit that, ideally you should get a response with metrics of all the projects.

Wercker API v3 - /builds endpoint is empty

I have a public project on Wercker :
https://app.wercker.com/xurei/redux-api-react-switch/runs
I would like to list the builds via the API, but it outputs an empty array...
https://app.wercker.com/api/v3/applications/xurei/redux-api-react-switch/builds
What am I missing ?
So to get the last runs you have to use
https://app.wercker.com/api/v3/runs?applicationId=:your_application_id
which you can find out
https://app.wercker.com/api/v3/applications/:username/:application
In your case this link (https://app.wercker.com/api/v3/runs?applicationId=591dc80e1ff866010052b3d2) will give you the last 20 runs you can see the rest of the options in the documentation here

How to poll the quality gate execution status?

I would like to poll the quality gate execution status of my SonarQube 6.3 instance using a REST api call. I went through a few api calls, which did not give me the expected results.
I tried to use these urls:
http://localhost:9000/api/resources
http://localhost:9000/api/components
But I always got this response:
{"errors":[{"msg":"Unknown url : /api/resources"}]}
How can I poll the quality gate execution status via REST?
http://localhost:9000/web_api lists the web service endpoints available on your server and provides documentation for each one. In my copy of 6.3, the documentation for "api/resources" says
Removed since 6.3, please use api/components and api/measures instead
You say you've tried http://localhost:9000/api/components and gotten an error. That's because there's not actually a web service there. You'll have to add the qualifier for the service you want, such as /api/components/search, as described in the docs for that set of services: http://localhost:9000/web_api/api/components
In fact there are 5 parts in a correct SonarQube web api url. They can be seen like that domain/api/controller/action?parameters, for example http://localhost:9000/api/components/show?componentKey=blue.
So we have:
domain: which is represented by http://localhost:9000 in the example, it is the address where you can call your SonarQube server
api: which is represented by /api in the example, it is the base path of all web service in SonarQube
controller: which is represented by /components in the example, it represents a pool of web service concerning a given theme (issues, profiles, components, etc.)
action: which is represented by /show in the example, it is a unit action that you can perform through the web service, for example: show, search, list, backup, delete, etc.
parameters: which is represented by ?componentKey=bluein the example, they are not always mandatory but often allow you to specify further information to get more precise results
What you have forgotten here is at means to specify an action.
http://localhost:9000/api/project_analyses/search?project=myProjectname&category=QUALITY_GATE
This query returned the status of my quality gate. Here I have mentioned the project name as myProjectname

Change CSV Delimiter in ORDS

I've recently setup Oracle Rest Data Services (ORDS) and managed to successfully create several endpoints returning both JSON and CSV data. However, is there was a way to change the delimiter (such as to a tab or pipe) on csv/query services? Since the ORDS packages are encrypted, there's no way to do modifications on that front, and none of the documentation I've read suggests there's a built in option to make this change.
I'm considering creating an plugin into ORDS that would basically call the CSV path and then convert it to the new delimiter before returning the data, but before that I wanted to make sure there wasn't any easier way of accomplishing this.
Take a look at Developing Oracle Rest Data Applications
Pattern: POST http://< HOST>:< PORT >/ords/< SchemaAlias>/< ObjectAlias>/batchload?< Parameters>
One parameter is: delimiter
"Sets the field delimiter for the fields in the file. The default is the comma (,)."

Resources