Delete datasource event


I’ve developed an datasource plugin with a datasource server in backend. This datasource server connects to an programmable logic controller via an industrial communication protocol.

So I have do bind an external source to my datasource server.

Everything is ok with this configuration, BUT: in case of deleting the grafana datasource, I have to remove the backend binding. Is there a possibility to be informed about the deletion of the datasource so I can handle the backend connection release?


At the moment it’s not possible, but you can file a feature request for this at Github.


Thank you for your response!

I’ve found a solution: I override the backend service delete method in my datasource plugin and restore it on leaving the edit mode. This solution works for me.

In case of two opened datasources of the me type I could only delete the datasource till I leave one of the edit modes.

hello where is the delete method??

Inject the backendSrv to your class. This service contains a method with the name “delete”.

class MyCtrl {
  constructor($scope, backendSrv) {
    // replace the method
    backendSrv.oldDeleteMethod = backendSrv.delete;
    backendSrv.delete = (paramaters) => {
        // do your magic here

    // don't forget to restore the original method on leave!
    $scope.$on('$destroy', () => {
       backendSrv.delete = backendSrv.oldDeleteMethod;
       delete backendSrv.oldDeleteMethod;