Get timestamp out of SonarQube database

issues
web_api

(Josh) #1

We have some automation scripts working with SonarQube at the command-line and we need to get the date that issues were found.

We see that the issues table has a field “created_at”, which I think has what we want, but it has a long number that is too long for a SQL timestamp.

How do we get the timestamp out of the database and how can we convert it to a regular date timestamp?

Edit: We really just need to know the format of these timestamp fields in the database.


(G Ann Campbell) #2

Hi,

You should treat the database as a black box and use web services instead. I’m looking at the JSON response for an issue search, and it has this, which I find quite readable:

"creationDate":"2018-06-14T17:56:57+0200"

Ann


(Josh) #3

Ann, thanks for the response.

We already have a full command-line based automation system for our tools in place which we cannot just toss out. These tools are based on command-line because they are scheduled with automation tasks.

Putting that aside, we really just need to know the format of the fields. If we really can’t get the date for issues at the command-line, we will give up on this feature. We will say that the web interface is nice for human-interaction activity though, and we do appreciate you guys for it :).


(Nicolas Bontoux) #4

Hey Josh,

Just to be clear: the reason for which you should not query the database directly is simple, it’s because we do not maintain the database as an API. There’s no API contract for database structures, meaning they can evolve at any point in time without any prior notice. This would lead your custom integration to suddenly break whenever upgrading or deploying a fix.

Note that Ann did not mention the interface, but the Web Services a.k.a Web API more specifically. There’s an intro here, and the API is then fully documented in your own SonarQube server.

The SonarQube WebAPI is a charm to use from the command line. Just get a standard command-line HTTP tool like wget or curl, and you can programmatically obtain all of the SonarQube data you need (see for example api/issues/search for your need here).