Skip to content

Commit f232d48

Browse files
Issue-88: Add advanced reporting support (#89)
* feat: Add the reporting features * docs: Update the Readme.md *fix: Update the unit tests --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 4569dce commit f232d48

File tree

17 files changed

+1873
-58
lines changed

17 files changed

+1873
-58
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,15 @@ In general, my focus on this project is to implement and deliver old and new fea
226226
- Delete playlist by uid
227227

228228
### Reporting
229+
- Get reports
230+
- Get report by id
231+
- Create report
232+
- Update report
233+
- Delete report
229234
- Send report
235+
- Get report branding settings
236+
- Save report branding settings
237+
- Send report test email
230238

231239
### Query History
232240
- Add query to history

docs/content/grafana_api/model.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
* [DatasourceCache](#model.DatasourceCache)
3939
* [PublicDashboard](#model.PublicDashboard)
4040
* [SSOSetting](#model.SSOSetting)
41+
* [DashboardSchema](#model.DashboardSchema)
42+
* [Report](#model.Report)
43+
* [ReportBrandingSettings](#model.ReportBrandingSettings)
4144

4245
<a id="model"></a>
4346

@@ -746,3 +749,70 @@ The class includes all necessary variables to generate an SSO setting object
746749
- `enabled` _bool_ - Specify if the SSO provider is enabled or not
747750
- `scopes` _str_ - Specify the SSO scopes
748751

752+
<a id="model.DashboardSchema"></a>
753+
754+
## DashboardSchema Objects
755+
756+
```python
757+
@dataclass
758+
class DashboardSchema()
759+
```
760+
761+
The class includes all necessary variables to generate a dashboard schema object that is used for the reporting functionality
762+
763+
**Arguments**:
764+
765+
- `dashboard_uid` _str_ - Specify the dashboard uid
766+
- `time_range_from` _str_ - Specify the dashboard time range from
767+
- `time_range_to` _str_ - Specify the dashboard time range to
768+
- `report_variables` _dict_ - Specify the key-value pairs containing the template variables for this report, in dict format. If the value is None, the template variables from the reports dashboard will be used (default None)
769+
770+
<a id="model.Report"></a>
771+
772+
## Report Objects
773+
774+
```python
775+
@dataclass
776+
class Report()
777+
```
778+
779+
The class includes all necessary variables to generate a report object
780+
781+
**Arguments**:
782+
783+
- `name` _str_ - Specify the name of the report that is used as an email subject
784+
- `recipients` _str_ - Specify the comma-separated list of emails to which to send the report to
785+
- `reply_to` _str_ - Specify the comma-separated list of emails used in a reply-to field of the report email
786+
- `message` _str_ - Specify the text message used for the body of the report email
787+
- `start_date` _str_ - Specify the distribution starts from this date
788+
- `end_date` _str_ - Specify the distribution end from this date
789+
- `time_zone` _str_ - Specify the time zone used to schedule report execution
790+
- `orientation` _str_ - Specify if the orientation should be portrait or landscape
791+
- `layout` _str_ - Specify if the layout should be grid or simple
792+
- `enable_dashboard_url` _str_ - Specify if the dashboard url should be added to the bottom of the report email
793+
- `dashboards` _List[DashboardSchema]_ - Specify the dashboards for which the reports should be generated
794+
- `frequency` _str_ - Specify how often the report should be sent. Can be once, hourly, daily, weekly, monthly, last or custom. The value last schedules the report for the last day of the month. The value custom schedules the report to be sent on a custom interval. It requires interval_frequency and interval_amount to be specified e.g. every 2 weeks, where 2 is an interval_amount and weeks is an interval_frequency (default last)
795+
- `interval_frequency` _str_ - Specify the type of the custom interval hours, days, weeks, months (default None)
796+
- `interval_amount` _int_ - Specify the interval amount of the custom type (default 0)
797+
- `workdays_only` _bool_ - Specify if the report only on Monday-Friday should be sent. Applicable to hourly and daily types of schedule (default None)
798+
- `formats` _List[str]_ - Specify what kind of attachment to generate for the report. Available report formats are csv, pdf and image. The type csv attaches a CSV file for each table panel and the type image embeds an image of a dashboard into the emails body (default List["pdf"])
799+
800+
<a id="model.ReportBrandingSettings"></a>
801+
802+
## ReportBrandingSettings Objects
803+
804+
```python
805+
@dataclass
806+
class ReportBrandingSettings()
807+
```
808+
809+
The class includes all necessary variables to generate a report branding settings object
810+
811+
**Arguments**:
812+
813+
- `report_logo_url` _str_ - Specify the url of an image used as a logo on every page of the report
814+
- `email_logo_url` _str_ - Specify the url of an image used as a logo in the email
815+
- `email_footer_mode` _str_ - Specify the email footer mode. Can be sent-by or none. The value sent-by adds a 'Sent by email footer text' footer link to the email. Requires specifying values in the email_footer_text and email_footer_link fields. The value none suppresses adding a 'Sent by' footer link to the email
816+
- `email_footer_text` _str_ - Specify the text of a URL added to the email 'Sent by' footer (default None)
817+
- `email_footer_link` _str_ - Specify the url address value added to the email 'Sent by' footer (default None)
818+

docs/content/grafana_api/reporting.md

Lines changed: 231 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22

33
* [reporting](#reporting)
44
* [Reporting](#reporting.Reporting)
5+
* [get\_reports](#reporting.Reporting.get_reports)
6+
* [get\_report\_by\_id](#reporting.Reporting.get_report_by_id)
7+
* [create\_report](#reporting.Reporting.create_report)
8+
* [update\_report](#reporting.Reporting.update_report)
9+
* [delete\_report](#reporting.Reporting.delete_report)
510
* [send\_report](#reporting.Reporting.send_report)
11+
* [get\_report\_branding\_settings](#reporting.Reporting.get_report_branding_settings)
12+
* [save\_report\_branding\_settings](#reporting.Reporting.save_report_branding_settings)
13+
* [send\_report\_test\_email](#reporting.Reporting.send_report_test_email)
614

715
<a id="reporting"></a>
816

@@ -29,6 +37,146 @@ HINT: Note Grafana Enterprise API need required permissions if fine-grained acce
2937

3038
- `grafana_api_model` _APIModel_ - This is where we store the grafana_api_model
3139

40+
<a id="reporting.Reporting.get_reports"></a>
41+
42+
#### get\_reports
43+
44+
```python
45+
def get_reports() -> list
46+
```
47+
48+
The method includes a functionality to get all reports
49+
50+
Required Permissions:
51+
Action: reports:read
52+
Scope: [reports:*, reports:id:*]
53+
54+
**Raises**:
55+
56+
- `Exception` - Unspecified error by executing the API call
57+
58+
59+
**Returns**:
60+
61+
- `api_call` _list_ - Returns all reports
62+
63+
<a id="reporting.Reporting.get_report_by_id"></a>
64+
65+
#### get\_report\_by\_id
66+
67+
```python
68+
def get_report_by_id(id: int) -> dict
69+
```
70+
71+
The method includes a functionality to get a report specified by the report id
72+
73+
**Arguments**:
74+
75+
- `id` _int_ - Specify the report id
76+
77+
Required Permissions:
78+
- `Action` - reports:read
79+
- `Scope` - [reports:*, reports:id:*, reports:id:<report_id>]
80+
81+
82+
**Raises**:
83+
84+
- `ValueError` - Missed specifying a necessary value
85+
- `Exception` - Unspecified error by executing the API call
86+
87+
88+
**Returns**:
89+
90+
- `api_call` _dict_ - Returns the report
91+
92+
<a id="reporting.Reporting.create_report"></a>
93+
94+
#### create\_report
95+
96+
```python
97+
def create_report(report: Report) -> int
98+
```
99+
100+
The method includes a functionality to create a report
101+
102+
**Arguments**:
103+
104+
- `report` _Report_ - Specify the report object
105+
106+
Required Permissions:
107+
- `Action` - reports:create
108+
- `Scope` - N/A
109+
110+
111+
**Raises**:
112+
113+
- `ValueError` - Missed specifying a necessary value
114+
- `Exception` - Unspecified error by executing the API call
115+
116+
117+
**Returns**:
118+
119+
- `api_call` _int_ - Returns the report id
120+
121+
<a id="reporting.Reporting.update_report"></a>
122+
123+
#### update\_report
124+
125+
```python
126+
def update_report(id: int, report: Report)
127+
```
128+
129+
The method includes a functionality to update a report
130+
131+
**Arguments**:
132+
133+
- `id` _int_ - Specify the report id
134+
- `report` _Report_ - Specify the report object
135+
136+
Required Permissions:
137+
- `Action` - reports:write
138+
- `Scope` - [reports:*, reports:id:*, reports:id:<report_id>]
139+
140+
141+
**Raises**:
142+
143+
- `ValueError` - Missed specifying a necessary value
144+
- `Exception` - Unspecified error by executing the API call
145+
146+
147+
**Returns**:
148+
149+
None
150+
151+
<a id="reporting.Reporting.delete_report"></a>
152+
153+
#### delete\_report
154+
155+
```python
156+
def delete_report(id: int)
157+
```
158+
159+
The method includes a functionality to delete a report specified by the report id
160+
161+
**Arguments**:
162+
163+
- `id` _int_ - Specify the report id
164+
165+
Required Permissions:
166+
- `Action` - reports:delete
167+
- `Scope` - [reports:*, reports:id:*, reports:id:<report_id>]
168+
169+
170+
**Raises**:
171+
172+
- `ValueError` - Missed specifying a necessary value
173+
- `Exception` - Unspecified error by executing the API call
174+
175+
176+
**Returns**:
177+
178+
None
179+
32180
<a id="reporting.Reporting.send_report"></a>
33181

34182
#### send\_report
@@ -43,9 +191,9 @@ The method includes a functionality to send a report to a specified email addres
43191

44192
**Arguments**:
45193

46-
- `id` _int_ - Specify the id of sented report. It is the same as in the URL when editing a report, not to be confused with the id of the dashboard.
194+
- `id` _int_ - Specify the id of forwarded report. It is the same as in the URL when editing a report, not to be confused with the id of the dashboard.
47195
- `emails` _str_ - Specify the comma-separated list of emails to which to send the report to. Overrides the emails from the report. Required if useEmailsFromReport is not present (default None)
48-
- `use_emails_from_report` _bool_ - Specify the if the emails inside the report should be used. Required if emails is not present (default None)
196+
- `use_emails_from_report` _bool_ - Specify if the emails inside the report should be used. Required if emails is not present (default None)
49197

50198
Required Permissions:
51199
- `Action` - reports:send
@@ -58,6 +206,87 @@ The method includes a functionality to send a report to a specified email addres
58206
- `Exception` - Unspecified error by executing the API call
59207

60208

209+
**Returns**:
210+
211+
None
212+
213+
<a id="reporting.Reporting.get_report_branding_settings"></a>
214+
215+
#### get\_report\_branding\_settings
216+
217+
```python
218+
def get_report_branding_settings() -> dict
219+
```
220+
221+
The method includes a functionality to get the report branding settings
222+
223+
Required Permissions:
224+
Action: reports.settings:read
225+
Scope: N/A
226+
227+
**Raises**:
228+
229+
- `Exception` - Unspecified error by executing the API call
230+
231+
232+
**Returns**:
233+
234+
- `api_call` _dict_ - Returns the report branding settings
235+
236+
<a id="reporting.Reporting.save_report_branding_settings"></a>
237+
238+
#### save\_report\_branding\_settings
239+
240+
```python
241+
def save_report_branding_settings(branding_settings: ReportBrandingSettings)
242+
```
243+
244+
The method includes a functionality to save the report branding settings
245+
246+
**Arguments**:
247+
248+
- `branding_settings` _ReportBrandingSettings_ - Specify the report branding settings object.
249+
250+
Required Permissions:
251+
- `Action` - reports.settings:write
252+
- `Scope` - N/A
253+
254+
255+
**Raises**:
256+
257+
- `ValueError` - Missed specifying a necessary value
258+
- `Exception` - Unspecified error by executing the API call
259+
260+
261+
**Returns**:
262+
263+
None
264+
265+
<a id="reporting.Reporting.send_report_test_email"></a>
266+
267+
#### send\_report\_test\_email
268+
269+
```python
270+
def send_report_test_email(report: Report)
271+
```
272+
273+
The method includes a functionality to send a test report email
274+
275+
**Arguments**:
276+
277+
- `report` _Report_ - Specify the report object
278+
279+
Required Permissions:
280+
- `Action` - reports: send
281+
- `Scope` - N/A
282+
283+
284+
**Raises**:
285+
286+
- `ValueError` - Missed specifying a necessary value
287+
- `Exception` - Unspecified error by executing the API call
288+
289+
61290
**Returns**:
62291

63292
None

0 commit comments

Comments
 (0)