Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.

Commit ed90dc7

Browse files
New report data structure (#126)
Following the new docs: https://grafana.com/docs/grafana/latest/developers/http_api/reporting
1 parent 21beb08 commit ed90dc7

File tree

2 files changed

+50
-24
lines changed

2 files changed

+50
-24
lines changed

report.go

+22-9
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,30 @@ type ReportSchedule struct {
1919
DayOfMonth string `json:"dayOfMonth,omitempty"`
2020
}
2121

22-
// ReportTimeRange represents the time range from a Grafana report.
23-
type ReportTimeRange struct {
22+
// ReportOptions represents the options for a Grafana report.
23+
type ReportOptions struct {
24+
Orientation string `json:"orientation"`
25+
Layout string `json:"layout"`
26+
}
27+
28+
// ReportDashboardTimeRange represents the time range from a dashboard on a Grafana report.
29+
type ReportDashboardTimeRange struct {
2430
From string `json:"from"`
2531
To string `json:"to"`
2632
}
2733

28-
// ReportOptions represents the options for a Grafana report.
29-
type ReportOptions struct {
30-
Orientation string `json:"orientation"`
31-
Layout string `json:"layout"`
32-
TimeRange ReportTimeRange `json:"timeRange"`
34+
// ReportDashboardIdentifier represents the identifier for a dashboard on a Grafana report.
35+
type ReportDashboardIdentifier struct {
36+
ID int64 `json:"id,omitempty"`
37+
UID string `json:"uid,omitempty"`
38+
Name string `json:"name,omitempty"`
39+
}
40+
41+
// ReportDashboard represents a dashboard on a Grafana report.
42+
type ReportDashboard struct {
43+
Dashboard ReportDashboardIdentifier `json:"dashboard"`
44+
TimeRange ReportDashboardTimeRange `json:"timeRange"`
45+
Variables map[string]string `json:"reportVariables"`
3346
}
3447

3548
// Report represents a Grafana report.
@@ -40,8 +53,8 @@ type Report struct {
4053
OrgID int64 `json:"orgId,omitempty"`
4154
State string `json:"state,omitempty"`
4255

43-
DashboardID int64 `json:"dashboardId"`
44-
DashboardUID string `json:"dashboardUid"`
56+
Dashboards []ReportDashboard `json:"dashboards"`
57+
4558
Name string `json:"name"`
4659
Recipients string `json:"recipients"`
4760
ReplyTo string `json:"replyTo"`

report_test.go

+28-15
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,19 @@ var (
1313
"id": 4,
1414
"userId": 0,
1515
"orgId": 1,
16-
"dashboardId": 33,
17-
"dashboardName": "Terraform Acceptance Test",
18-
"dashboardUid": "",
16+
"dashboards": [
17+
{
18+
"dashboard": {
19+
"id": 33,
20+
"uid": "nErXDvCkzz",
21+
"name": "Terraform Acceptance Test"
22+
},
23+
"timeRange": {
24+
"from": "now-1h",
25+
"to": "now"
26+
}
27+
}
28+
],
1929
"name": "My Report",
2030
"recipients": "[email protected]",
2131
"replyTo": "",
@@ -35,11 +45,7 @@ var (
3545
},
3646
"options": {
3747
"orientation": "landscape",
38-
"layout": "grid",
39-
"timeRange": {
40-
"from": "now-1h",
41-
"to": "now"
42-
}
48+
"layout": "grid"
4349
},
4450
"templateVars": {},
4551
"enableDashboardUrl": true,
@@ -56,9 +62,8 @@ var (
5662
`
5763
now = time.Now()
5864
testReport = Report{
59-
DashboardID: 33,
60-
Name: "My Report",
61-
Recipients: "[email protected]",
65+
Name: "My Report",
66+
Recipients: "[email protected]",
6267
Schedule: ReportSchedule{
6368
StartDate: &now,
6469
EndDate: nil,
@@ -68,13 +73,21 @@ var (
6873
WorkdaysOnly: true,
6974
TimeZone: "GMT",
7075
},
76+
Dashboards: []ReportDashboard{
77+
{
78+
Dashboard: ReportDashboardIdentifier{
79+
ID: 33,
80+
UID: "nErXDvCkzz",
81+
},
82+
TimeRange: ReportDashboardTimeRange{
83+
From: "now-1h",
84+
To: "now",
85+
},
86+
},
87+
},
7188
Options: ReportOptions{
7289
Orientation: "landscape",
7390
Layout: "grid",
74-
TimeRange: ReportTimeRange{
75-
From: "now-1h",
76-
To: "now",
77-
},
7891
},
7992
EnableDashboardURL: true,
8093
EnableCSV: true,

0 commit comments

Comments
 (0)