From c343a573f5896c064dda6b3704f67d72bc3d2162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20L=C3=B3pez=20de=20la=20Franca=20Beltran?= <5459617+joanlopez@users.noreply.github.com> Date: Fri, 6 Oct 2023 09:06:47 +0200 Subject: [PATCH] Retrieve data source by name (#164) --- datasource.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/datasource.go b/datasource.go index f697c91b..ad8d6b37 100644 --- a/datasource.go +++ b/datasource.go @@ -95,6 +95,18 @@ func (c *Client) DataSourceByUID(uid string) (*DataSource, error) { return result, err } +// DataSourceByName fetches and returns the Grafana data source whose name is passed. +func (c *Client) DataSourceByName(name string) (*DataSource, error) { + path := fmt.Sprintf("/api/datasources/name/%s", name) + result := &DataSource{} + err := c.request("GET", path, nil, nil, result) + if err != nil { + return nil, err + } + + return result, err +} + // DataSourceIDByName returns the Grafana data source ID by name. func (c *Client) DataSourceIDByName(name string) (int64, error) { path := fmt.Sprintf("/api/datasources/id/%s", name)