-
Notifications
You must be signed in to change notification settings - Fork 7
/
clients.go
51 lines (46 loc) · 1.93 KB
/
clients.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
40
41
42
43
44
45
46
47
48
49
50
51
package gografana
var (
clients map[string]func(string, string, Authenticator) GrafanaClienter
)
//根据Grafana的版本号来获取指定的Client
func GetClientByVersion(version, apiAddress string, auth Authenticator) (GrafanaClienter, error) {
if v, ok := clients[version]; ok {
return v(apiAddress, "", auth), nil
}
return nil, ErrNoSpecifiedVerClient{}
}
//根据Grafana的版本号来获取指定的Client,并设置 http proxy
func GetClientByVersionWithProxy(version, apiAddress, httpProxy string, auth Authenticator) (GrafanaClienter, error) {
if v, ok := clients[version]; ok {
return v(apiAddress, httpProxy, auth), nil
}
return nil, ErrNoSpecifiedVerClient{}
}
func init() {
clients = make(map[string]func(string, string, Authenticator) GrafanaClienter)
clients["5.x"] = func(apiAddress string, httpProxy string, auth Authenticator) GrafanaClienter {
return &GrafanaClient_5_0{basicAddress: apiAddress, authenticator: auth, httpProxy: httpProxy}
}
}
type GrafanaClienter interface {
GetAllDashboards() ([]Board, error)
GetAllFolders() ([]Folder, error)
GetDashboardsByTitleAndFolderId(title string, folderId int) ([]Board, error)
GetDashboardsByFolderId(folderId int) ([]Board, error)
IsBoardExists(title string) (bool, *Board, error)
NewDashboard(board *Board, folderId uint, overwrite bool) (*Board, error)
DeleteDashboard(uid string) (bool, error)
GetDashboardDetails(uid string) (*Board, error)
EnsureFolderExists(folderId int, uid, title string) (int, bool, error)
CreateAPIKey(name string, role string, secondsToLive int) (string, error)
FindAllAPIKeys() ([]APIKey, error)
DeleteAPIKey(id int) (bool, error)
//DATA SOURCE
GetAllDataSources() ([]*DataSource, error)
GetDashSourceById(id int) (*DataSource, error)
DeleteDashSource(id int) error
CreateDashSource(ds *DataSource) error
//NOTIFICATIONS
GetAllNotificationChannels() ([]NotificationChannel, error)
CreateNotificationChannel(nc *NotificationChannel) error
}