2017-09-20 14:24:11 +02:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"os/exec"
|
|
|
|
|
|
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/log"
|
2017-09-21 17:02:40 +02:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/backend/shared"
|
|
|
|
|
"github.com/grafana/grafana/pkg/tsdb/models"
|
2017-09-20 14:24:11 +02:00
|
|
|
plugin "github.com/hashicorp/go-plugin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func Init() (*plugin.Client, error) {
|
|
|
|
|
/*
|
2017-09-20 17:25:46 +02:00
|
|
|
setup protoc using https://gist.github.com/bergquist/5df1f201bb605e42538ef40f6ccf82a9
|
|
|
|
|
run "protoc --go_out=plugins=grpc:. *.proto" to update proto files
|
2017-09-20 14:24:11 +02:00
|
|
|
*/
|
|
|
|
|
|
2017-09-20 17:08:09 +02:00
|
|
|
logger := log.New("grafana.plugins")
|
2017-09-20 14:24:11 +02:00
|
|
|
client := plugin.NewClient(&plugin.ClientConfig{
|
2017-09-20 17:08:09 +02:00
|
|
|
HandshakeConfig: plugin.HandshakeConfig{
|
|
|
|
|
ProtocolVersion: 1,
|
|
|
|
|
MagicCookieKey: "BASIC_PLUGIN",
|
|
|
|
|
MagicCookieValue: "hello",
|
|
|
|
|
},
|
2017-09-20 14:24:11 +02:00
|
|
|
Plugins: shared.PluginMap,
|
2017-09-21 17:02:40 +02:00
|
|
|
Cmd: exec.Command("sh", "-c", "/home/carl/go/src/github.com/grafana/grafana/pkg/plugins/backend/mock_tsdb_plugin/simple-plugin"),
|
2017-09-20 14:24:11 +02:00
|
|
|
AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
|
2017-09-20 17:08:09 +02:00
|
|
|
Logger: logWrapper{logger: logger},
|
2017-09-20 14:24:11 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Connect via RPC
|
|
|
|
|
rpcClient, err := client.Client()
|
|
|
|
|
if err != nil {
|
2017-09-20 17:08:09 +02:00
|
|
|
return nil, err
|
2017-09-20 14:24:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Request the plugin
|
2017-09-20 17:08:09 +02:00
|
|
|
raw, err := rpcClient.Dispense("tsdb_mock")
|
2017-09-20 14:24:11 +02:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
plugin := raw.(shared.TsdbPlugin)
|
|
|
|
|
response, err := plugin.Get(context.Background(), &proto.TsdbRequest{})
|
|
|
|
|
|
2017-09-20 17:08:09 +02:00
|
|
|
if err != nil {
|
|
|
|
|
logger.Error("Response from plugin. ", "response", response)
|
|
|
|
|
} else {
|
|
|
|
|
logger.Info("Response from plugin. ", "response", response)
|
|
|
|
|
}
|
2017-09-20 14:24:11 +02:00
|
|
|
|
|
|
|
|
return client, nil
|
|
|
|
|
}
|