Commit 7969d664 by Marcus Efraimsson Committed by GitHub

Provisioning: Support alert notification channel secure settings (#26168)

Closes #25968
parent 8746a774
...@@ -307,7 +307,7 @@ By default Grafana will delete dashboards in the database if the file is removed ...@@ -307,7 +307,7 @@ By default Grafana will delete dashboards in the database if the file is removed
### Provision folders structure from filesystem to Grafana ### Provision folders structure from filesystem to Grafana
If you already store your dashboards using folders in a git repo or on a filesystem, and also you want to have the same folder names in the Grafana menu, you can use `foldersFromFilesStructure` option. If you already store your dashboards using folders in a git repo or on a filesystem, and also you want to have the same folder names in the Grafana menu, you can use `foldersFromFilesStructure` option.
For example, to replicate these dashboards structure from the filesystem to Grafana, For example, to replicate these dashboards structure from the filesystem to Grafana,
``` ```
/etc/dashboards /etc/dashboards
├── /server ├── /server
...@@ -320,7 +320,7 @@ For example, to replicate these dashboards structure from the filesystem to Graf ...@@ -320,7 +320,7 @@ For example, to replicate these dashboards structure from the filesystem to Graf
you need to specify just this short provision configuration file. you need to specify just this short provision configuration file.
```yaml ```yaml
apiVersion: 1 apiVersion: 1
providers: providers:
- name: dashboards - name: dashboards
type: file type: file
...@@ -535,4 +535,4 @@ The following sections detail the supported settings for each alert notification ...@@ -535,4 +535,4 @@ The following sections detail the supported settings for each alert notification
| Name | | Name |
| ---- | | ---- |
| url | | url |
\ No newline at end of file
...@@ -94,6 +94,7 @@ func (dc *NotificationProvisioner) mergeNotifications(notificationToMerge []*not ...@@ -94,6 +94,7 @@ func (dc *NotificationProvisioner) mergeNotifications(notificationToMerge []*not
Type: notification.Type, Type: notification.Type,
IsDefault: notification.IsDefault, IsDefault: notification.IsDefault,
Settings: notification.SettingsToJSON(), Settings: notification.SettingsToJSON(),
SecureSettings: notification.SecureSettings,
OrgId: notification.OrgID, OrgId: notification.OrgID,
DisableResolveMessage: notification.DisableResolveMessage, DisableResolveMessage: notification.DisableResolveMessage,
Frequency: notification.Frequency, Frequency: notification.Frequency,
...@@ -111,6 +112,7 @@ func (dc *NotificationProvisioner) mergeNotifications(notificationToMerge []*not ...@@ -111,6 +112,7 @@ func (dc *NotificationProvisioner) mergeNotifications(notificationToMerge []*not
Type: notification.Type, Type: notification.Type,
IsDefault: notification.IsDefault, IsDefault: notification.IsDefault,
Settings: notification.SettingsToJSON(), Settings: notification.SettingsToJSON(),
SecureSettings: notification.SecureSettings,
OrgId: notification.OrgID, OrgId: notification.OrgID,
DisableResolveMessage: notification.DisableResolveMessage, DisableResolveMessage: notification.DisableResolveMessage,
Frequency: notification.Frequency, Frequency: notification.Frequency,
......
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/grafana/grafana/pkg/components/securejsondata"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
...@@ -147,9 +148,10 @@ func validateNotifications(notifications []*notificationsAsConfig) error { ...@@ -147,9 +148,10 @@ func validateNotifications(notifications []*notificationsAsConfig) error {
for _, notification := range notifications[i].Notifications { for _, notification := range notifications[i].Notifications {
_, err := alerting.InitNotifier(&models.AlertNotification{ _, err := alerting.InitNotifier(&models.AlertNotification{
Name: notification.Name, Name: notification.Name,
Settings: notification.SettingsToJSON(), Settings: notification.SettingsToJSON(),
Type: notification.Type, SecureSettings: securejsondata.GetEncryptedJsonData(notification.SecureSettings),
Type: notification.Type,
}) })
if err != nil { if err != nil {
......
...@@ -66,6 +66,9 @@ func TestNotificationAsConfig(t *testing.T) { ...@@ -66,6 +66,9 @@ func TestNotificationAsConfig(t *testing.T) {
So(nt.Settings, ShouldResemble, map[string]interface{}{ So(nt.Settings, ShouldResemble, map[string]interface{}{
"recipient": "XXX", "token": "xoxb", "uploadImage": true, "url": "https://slack.com", "recipient": "XXX", "token": "xoxb", "uploadImage": true, "url": "https://slack.com",
}) })
So(nt.SecureSettings, ShouldResemble, map[string]string{
"token": "xoxbsecure", "url": "https://slack.com/secure",
})
So(nt.SendReminder, ShouldBeTrue) So(nt.SendReminder, ShouldBeTrue)
So(nt.Frequency, ShouldEqual, "1h") So(nt.Frequency, ShouldEqual, "1h")
......
...@@ -11,6 +11,9 @@ notifiers: ...@@ -11,6 +11,9 @@ notifiers:
token: "xoxb" token: "xoxb"
uploadImage: true uploadImage: true
url: https://slack.com url: https://slack.com
secure_settings:
url: https://slack.com/secure
token: "xoxbsecure"
- name: another-not-default-notification - name: another-not-default-notification
type: email type: email
settings: settings:
......
...@@ -30,6 +30,7 @@ type notificationFromConfig struct { ...@@ -30,6 +30,7 @@ type notificationFromConfig struct {
Frequency string Frequency string
IsDefault bool IsDefault bool
Settings map[string]interface{} Settings map[string]interface{}
SecureSettings map[string]string
} }
// notificationsAsConfigV0 is mapping for zero version configs. This is mapped to its normalised version. // notificationsAsConfigV0 is mapping for zero version configs. This is mapped to its normalised version.
...@@ -46,16 +47,17 @@ type deleteNotificationConfigV0 struct { ...@@ -46,16 +47,17 @@ type deleteNotificationConfigV0 struct {
} }
type notificationFromConfigV0 struct { type notificationFromConfigV0 struct {
UID values.StringValue `json:"uid" yaml:"uid"` UID values.StringValue `json:"uid" yaml:"uid"`
OrgID values.Int64Value `json:"org_id" yaml:"org_id"` OrgID values.Int64Value `json:"org_id" yaml:"org_id"`
OrgName values.StringValue `json:"org_name" yaml:"org_name"` OrgName values.StringValue `json:"org_name" yaml:"org_name"`
Name values.StringValue `json:"name" yaml:"name"` Name values.StringValue `json:"name" yaml:"name"`
Type values.StringValue `json:"type" yaml:"type"` Type values.StringValue `json:"type" yaml:"type"`
SendReminder values.BoolValue `json:"send_reminder" yaml:"send_reminder"` SendReminder values.BoolValue `json:"send_reminder" yaml:"send_reminder"`
DisableResolveMessage values.BoolValue `json:"disable_resolve_message" yaml:"disable_resolve_message"` DisableResolveMessage values.BoolValue `json:"disable_resolve_message" yaml:"disable_resolve_message"`
Frequency values.StringValue `json:"frequency" yaml:"frequency"` Frequency values.StringValue `json:"frequency" yaml:"frequency"`
IsDefault values.BoolValue `json:"is_default" yaml:"is_default"` IsDefault values.BoolValue `json:"is_default" yaml:"is_default"`
Settings values.JSONValue `json:"settings" yaml:"settings"` Settings values.JSONValue `json:"settings" yaml:"settings"`
SecureSettings values.StringMapValue `json:"secure_settings" yaml:"secure_settings"`
} }
func (notification notificationFromConfig) SettingsToJSON() *simplejson.Json { func (notification notificationFromConfig) SettingsToJSON() *simplejson.Json {
...@@ -88,6 +90,7 @@ func (cfg *notificationsAsConfigV0) mapToNotificationFromConfig() *notifications ...@@ -88,6 +90,7 @@ func (cfg *notificationsAsConfigV0) mapToNotificationFromConfig() *notifications
DisableResolveMessage: notification.DisableResolveMessage.Value(), DisableResolveMessage: notification.DisableResolveMessage.Value(),
Frequency: notification.Frequency.Value(), Frequency: notification.Frequency.Value(),
SendReminder: notification.SendReminder.Value(), SendReminder: notification.SendReminder.Value(),
SecureSettings: notification.SecureSettings.Value(),
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment