-
-
Notifications
You must be signed in to change notification settings - Fork 69
/
main.go
39 lines (31 loc) · 865 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"context"
"fmt"
"net/http"
"os"
"github.com/K-Phoen/grabana"
"github.com/K-Phoen/grabana/datasource/prometheus"
)
func main() {
if len(os.Args) != 3 {
fmt.Fprint(os.Stderr, "Usage: go run main.go http://grafana-host:3000 api-key-string-here\n")
os.Exit(1)
}
ctx := context.Background()
client := grabana.NewClient(&http.Client{}, os.Args[1], grabana.WithAPIToken(os.Args[2]))
options := []prometheus.Option{
prometheus.Default(),
prometheus.SkipTLSVerify(),
}
datasource, err := prometheus.New("grabana-prometheus", "http://172.17.0.1:9090", options...)
if err != nil {
fmt.Printf("Could not build datasource: %s\n", err)
os.Exit(1)
}
if err := client.UpsertDatasource(ctx, datasource); err != nil {
fmt.Printf("Could not create datasource: %s\n", err)
os.Exit(1)
}
fmt.Println("The deed is done.")
}