/
getAnnotations.go
49 lines (39 loc) · 1.11 KB
/
getAnnotations.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
package grafana
import (
"encoding/json"
"strconv"
"time"
"github.com/go-kit/kit/log/level"
)
// Annotation : grafana annotation
type Annotation struct {
ID int
AlertID int
DashboardID int
PanelID int
UserID int
UserName string
NewState string
PrevState string
Time int64
Text string
Metric string
RegionID int
Tags []string
}
// AnnotationsResp : Grafana annotations list
type AnnotationsResp []Annotation
// GetAnnotations : get annotations list from Grafana
func (client *Client) GetAnnotations(fromTime time.Time, toTime time.Time) (AnnotationsResp, error) {
respJSON := AnnotationsResp{}
query := map[string]string{}
query["from"] = strconv.FormatInt(fromTime.UnixNano()/int64(time.Millisecond), 10)
query["to"] = strconv.FormatInt(toTime.UnixNano()/int64(time.Millisecond), 10)
respText, err := client.apiGetRequest("/api/annotations", query)
if err != nil {
level.Error(client.logger).Log("msg", "could not get grafana annotations", "err", err)
return respJSON, err
}
json.Unmarshal([]byte(respText), &respJSON)
return respJSON, nil
}