Hi all,
i follow the example code and try creating a new dashboard.
package main
import (
"context"
"fmt"
"os"
"github.com/grafana-tools/sdk"
)
func main() {
const GRAFANA_URL = "http://localhost:3000"
const GRAFANA_API_KEY = "<GRAFANA_API_KEY>"
// Initialize the grafana client
grafanaClient, err := sdk.NewClient(GRAFANA_URL, GRAFANA_API_KEY, sdk.DefaultHTTPClient)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create a client: %s\n", err)
os.Exit(1)
}
// Create dashboard
board := sdk.NewBoard("Sample dashboard title")
board.ID = 1
board.Time.From = "now-30m"
board.Time.To = "now"
row1 := board.AddRow("Sample row title")
row1.Add(sdk.NewGraph("Sample graph"))
graph := sdk.NewGraph("Sample graph 2")
target := sdk.Target{
RefID: "A",
Datasource: "Sample Source 1",
Expr: "sample request 1"}
graph.AddTarget(&target)
row1.Add(graph)
response, err := grafanaClient.SetDashboard(context.TODO() ,*board, sdk.SetDashboardParams{
Overwrite: false,
})
if err != nil {
fmt.Printf("error on uploading dashboard %s", board.Title)
} else {
fmt.Printf("dashboard URL: %v", GRAFANA_URL + *response.URL)
}
}
The dashboard is successfully created but there is no row with name "Sample row title".

What i suppose to have...

What did i miss?
Thanks for developing this project.
Regards,
Kit
Hi all,
i follow the example code and try creating a new dashboard.
The dashboard is successfully created but there is no row with name "Sample row title".

What i suppose to have...

What did i miss?
Thanks for developing this project.
Regards,
Kit