Alerting: Add notification policy provisioning file export (#70009)

* Alerting: Add notification policy provisioning file export

- Add provisioning API endpoint for exporting notification policies.
- Add option in notification policy view ellipsis dropdown for exporting.
- Update various provisioning documentation.
This commit is contained in:
Matthew Jacobson
2023-07-24 17:56:53 -04:00
committed by GitHub
parent 4c42632ab8
commit cfb1656968
16 changed files with 731 additions and 71 deletions
@@ -496,11 +496,13 @@ settings:
Create or reset the notification policy tree in your Grafana instance(s).
1. Create a YAML or JSON configuration file.
1. Create a notification policy in Grafana.
2. Use the [Alerting provisioning API]({{< relref "../../../../developers/http_api/alerting_provisioning" >}}) export endpoints to download a provisioning file for your notification policy.
3. Copy the contents into a YAML or JSON configuration file in the default provisioning directory or in your configured directory.
Example configuration files can be found below.
2. Add the file(s) to your GitOps workflow, so that they deploy alongside your Grafana instance(s).
4. Ensure that your files are in the right directory on the node running the Grafana server, so that they deploy alongside your Grafana instance(s).
Here is an example of a configuration file for creating notification policies.
@@ -70,11 +70,12 @@ Contact point provisioning is for Grafana-managed alerts only.
### Notification policies
| Method | URI | Name | Summary |
| ------ | ----------------------------- | --------------------------------------------------- | ------------------------------------ |
| DELETE | /api/v1/provisioning/policies | [route reset policy tree](#route-reset-policy-tree) | Clears the notification policy tree. |
| GET | /api/v1/provisioning/policies | [route get policy tree](#route-get-policy-tree) | Get the notification policy tree. |
| PUT | /api/v1/provisioning/policies | [route put policy tree](#route-put-policy-tree) | Sets the notification policy tree. |
| Method | URI | Name | Summary |
| ------ | ------------------------------------ | ------------------------------------------------------------- | ---------------------------------------------------------------- |
| DELETE | /api/v1/provisioning/policies | [route reset policy tree](#route-reset-policy-tree) | Clears the notification policy tree. |
| GET | /api/v1/provisioning/policies | [route get policy tree](#route-get-policy-tree) | Get the notification policy tree. |
| GET | /api/v1/provisioning/policies/export | [route get policy tree export](#route-get-policy-tree-export) | Export the notification policy tree in provisioning file format. |
| PUT | /api/v1/provisioning/policies | [route put policy tree](#route-put-policy-tree) | Sets the notification policy tree. |
### Mute timings
@@ -573,6 +574,37 @@ Status: OK
[Route](#route)
### <span id="route-get-policy-tree-export"></span> Export the notification policy tree in provisioning file format. (_RouteGetPolicyTreeExport_)
```
GET /api/v1/provisioning/policies/export
```
#### All responses
| Code | Status | Description | Has headers | Schema |
| ---------------------------------------- | --------- | ------------------ | :---------: | -------------------------------------------------- |
| [200](#route-get-policy-tree-export-200) | OK | AlertingFileExport | | [schema](#route-get-policy-tree-export-200-schema) |
| [404](#route-get-policy-tree-export-404) | Not Found | NotFound | | [schema](#route-get-policy-tree-export-404-schema) |
#### Responses
##### <span id="route-get-policy-tree-export-200"></span> 200 - AlertingFileExport
Status: OK
###### <span id="route-get-policy-tree-export-200-schema"></span> Schema
[AlertingFileExport](#alerting-file-export)
##### <span id="route-get-policy-tree-export-404"></span> 404 - NotFound
Status: Not Found
###### <span id="route-get-policy-tree-export-404-schema"></span> Schema
[NotFound](#not-found)
### <span id="route-get-template"></span> Get a notification template. (_RouteGetTemplate_)
```
@@ -1182,11 +1214,12 @@ Status: Accepted
{{% responsive-table %}}
| Name | Type | Go type | Required | Default | Description | Example |
| ------------- | -------------------------------------------------- | ------------------------- | :------: | ------- | ----------- | ------- |
| apiVersion | int64 (formatted integer) | `int64` | | | | |
| contactPoints | [][ContactPointExport](#contact-point-export) | `[]*ContactPointExport` | | | | |
| groups | [][AlertRuleGroupExport](#alert-rule-group-export) | `[]*AlertRuleGroupExport` | | | | |
| Name | Type | Go type | Required | Default | Description | Example |
| ------------- | --------------------------------------------------------- | ----------------------------- | :------: | ------- | ----------- | ------- |
| apiVersion | int64 (formatted integer) | `int64` | | | | |
| contactPoints | [][ContactPointExport](#contact-point-export) | `[]*ContactPointExport` | | | | |
| groups | [][AlertRuleGroupExport](#alert-rule-group-export) | `[]*AlertRuleGroupExport` | | | | |
| policies | [][NotificationPolicyExport](#notification-policy-export) | `[]*NotificationPolicyExport` | | | | |
{{% /responsive-table %}}
@@ -1285,6 +1318,19 @@ Status: Accepted
[][MuteTimeInterval](#mute-time-interval)
### <span id="not-found"></span> NotFound
[interface{}](#interface)
### <span id="notification-policy-export"></span> NotificationPolicyExport
**Properties**
| Name | Type | Go type | Required | Default | Description | Example |
| ------ | ---------------------------- | ------------- | :------: | ------- | ----------- | ------- |
| Policy | [RouteExport](#route-export) | `RouteExport` | | | inline | |
| orgId | int64 (formatted integer) | `int64` | | | | |
### <span id="notification-template"></span> NotificationTemplate
**Properties**
@@ -1362,16 +1408,20 @@ Status: Accepted
[][ProvisionedAlertRule](#provisioned-alert-rule)
### <span id="raw-message"></span> RawMessage
[interface{}](#interface)
### <span id="receiver-export"></span> ReceiverExport
**Properties**
| Name | Type | Go type | Required | Default | Description | Example |
| --------------------- | ------------- | -------- | :------: | ------- | ----------- | ------- |
| disableResolveMessage | boolean | `bool` | | | | |
| settings | [JSON](#json) | `JSON` | | | | |
| type | string | `string` | | | | |
| uid | string | `string` | | | | |
| Name | Type | Go type | Required | Default | Description | Example |
| --------------------- | -------------------------- | ------------ | :------: | ------- | ----------- | ------- |
| disableResolveMessage | boolean | `bool` | | | | |
| settings | [RawMessage](#raw-message) | `RawMessage` | | | | |
| type | string | `string` | | | | |
| uid | string | `string` | | | | |
### <span id="regexp"></span> Regexp
@@ -1423,6 +1473,28 @@ Status: Accepted
{{% /responsive-table %}}
### <span id="route-export"></span> RouteExport
> RouteExport is the provisioned file export of definitions.Route. This is needed to hide fields that aren't useable in
> provisioning file format. An alternative would be to define a custom MarshalJSON and MarshalYAML that excludes them.
**Properties**
| Name | Type | Go type | Required | Default | Description | Example |
| ------------------- | ---------------------------------- | ------------------- | :------: | ------- | --------------------------------------- | ------- |
| continue | boolean | `bool` | | | | |
| group_by | []string | `[]string` | | | | |
| group_interval | string | `string` | | | | |
| group_wait | string | `string` | | | | |
| match | map of string | `map[string]string` | | | Deprecated. Remove before v1.0 release. | |
| match_re | [MatchRegexps](#match-regexps) | `MatchRegexps` | | | | |
| matchers | [Matchers](#matchers) | `Matchers` | | | | |
| mute_time_intervals | []string | `[]string` | | | | |
| object_matchers | [ObjectMatchers](#object-matchers) | `ObjectMatchers` | | | | |
| receiver | string | `string` | | | | |
| repeat_interval | string | `string` | | | | |
| routes | [][RouteExport](#route-export) | `[]*RouteExport` | | | | |
### <span id="time-interval"></span> TimeInterval
> TimeInterval describes intervals of time. ContainsTime will tell you if a golang time is contained