I want to create a Grafana plugin that uses MSSQL databases. I know there is a builtin MSSQL datasource plugin, but that requires the user to type entire SQL queries. I want to create a custom datasource that allows the user to select a name from a list, and the plugin will create the corresponding query for that. Therefore I want to build a full custom query builder (which is part of the datasource plugin).
I started with the simple data source plugin [https://github.com/grafana/simple-datasource/tree/master][1], and I am able to compile it and it is visible in Grafana.
I thought it would be easy if my datasource extends the existing MSSQL plugin.
My testDatasource looks like this:
async testDatasource() {
return getBackendSrv()
.datasourceRequest({
url: '/api/tsdb/query',
method: 'POST',
data: {
from: '5m',
to: 'now',
queries: [
{
refId: 'A',
intervalMs: 1,
maxDataPoints: 1,
datasourceId: this.id,
rawSql: 'SELECT 1',
format: 'table',
},
],
},
})
.then((res: any) => {
return { status: 'success', message: 'Database Connection OK' };
})
.catch((err: any) => {
if (err.data && err.data.message) {
return { status: 'error', message: err.data.message };
} else {
return { status: 'error', message: err.status };
}
});
and everytime I test it I get an error in the log
error="Could not find executor for data source type: my-mssql-datasource" remote_addr=[::1]
I have checked the sources on github for this error and I can find that the Grafana code in grafana/pkg/tsdb/query_endpoint.go cannot find my-mssql-datasource
name in its registered plugins.
Is there a way I can use the MSSQL backend handling that already exists in Grafana ? If so, any guides or hints that show how to do that ? I have tried to follow the Grafana documentation, but it does not help me with this.
For example: Can I add something to my datasourceRequest
that makes Grafana to execute my queries against MSSQL ? Or can I register my datasource so it uses MSSQL ?
EDIT As @Jan Garaj mentioned in the comments it can be done with dashboard variables. However the dashboard variables are used for an entire dashboard. If I want to have 2 panels with different signals, that can be chosen by the user, I cannot use dashboard variables. Then I need something like panel-variables. Because it then is per panel, I wanted to do this with a query builder. [1]: https://github.com/grafana/simple-datasource/tree/master