Get details of datasource in Panel

Currently I have a MQTT Datasource (it has all connection details) and I have created a panel for this, the panel should able to publish message on MQTT Broker.

Now to do this operation:

  • We need to able to call datasource method OR
  • Fetch MQTT Broker details on Panel so I can create a new MQTT client to do the message publish operation

Currently, I what I am doing on panel side is:

  • fetch('/api/datasources') API call
  • filter API output with data.request.targets > datasource
  • use the filtered output come as MQTT config
  • create MQTT client on panel side as well by using the config
  • publish message from there

What would be the best solution to do these all things?

I replaced that fetch('/api/datasource') with @grafana/runtime > getDataSourceSrv().