forked from mayunlei/aliyun-log-grafana-datasource-plugin
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathmodels.go
82 lines (71 loc) · 2.1 KB
/
models.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"encoding/json"
"fmt"
"github.com/grafana/grafana-plugin-sdk-go/backend"
)
type Header struct {
Name string `json:"name"`
Value string `json:"value"`
}
type LogSource struct {
Endpoint string
Project string `json:"project"`
LogStore string `json:"logstore"`
RoleArn string `json:"roleArn"`
Region string
AccessKeyId string
AccessKeySecret string
Headers []Header `json:"headers"`
}
type QueryInfo struct {
Type string `json:"type"`
QueryMode string `json:"mode"`
Query string `json:"query"`
Xcol string `json:"xcol"`
Ycol string `json:"ycol"`
LogsPerPage int64 `json:"logsPerPage"`
CurrentPage int64 `json:"currentPage"`
LogStore string `json:"logStore"`
LegendFormat string `json:"legendFormat"`
QueryType string `json:"queryType"`
Step string `json:"step"`
IntervalMs int64 `json:"intervalMs"`
TotalLogs int64 `json:"totalLogs"`
PowerSql bool `json:"powerSql"`
}
type Result struct {
refId string
dataResponse backend.DataResponse
}
// Contents {"keys":["c","c1","t"],"terms":[["*",""]],"limited":"100"}
type Contents struct {
Keys []string `json:"keys"`
Terms [][]string `json:"terms"`
Limited string `json:"limited"`
}
type ResultItem struct {
Metric map[string]string `json:"metric"`
Values [][]interface{} `json:"values"`
Value []interface{} `json:"value"`
}
type MetricData struct {
ResultType string `json:"resultType"`
Result []ResultItem `json:"result"`
}
type MetricLogs struct {
Status string `json:"status"`
Data MetricData `json:"data"`
}
func LoadSettings(ctx backend.PluginContext) (*LogSource, error) {
model := &LogSource{}
settings := ctx.DataSourceInstanceSettings
err := json.Unmarshal(settings.JSONData, &model)
if err != nil {
return nil, fmt.Errorf("error reading settings: %s", err.Error())
}
model.Endpoint = settings.URL
model.AccessKeyId = settings.DecryptedSecureJSONData["accessKeyId"]
model.AccessKeySecret = settings.DecryptedSecureJSONData["accessKeySecret"]
return model, nil
}