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
### 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.
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
├── /server
......@@ -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.
```yaml
apiVersion: 1
providers:
- name: dashboards
type: file
......@@ -535,4 +535,4 @@ The following sections detail the supported settings for each alert notification
| Name |
| ---- |
| url |
| url |
\ No newline at end of file
......@@ -94,6 +94,7 @@ func (dc *NotificationProvisioner) mergeNotifications(notificationToMerge []*not
Type: notification.Type,
IsDefault: notification.IsDefault,
Settings: notification.SettingsToJSON(),
SecureSettings: notification.SecureSettings,
OrgId: notification.OrgID,
DisableResolveMessage: notification.DisableResolveMessage,
Frequency: notification.Frequency,
......@@ -111,6 +112,7 @@ func (dc *NotificationProvisioner) mergeNotifications(notificationToMerge []*not
Type: notification.Type,
IsDefault: notification.IsDefault,
Settings: notification.SettingsToJSON(),
SecureSettings: notification.SecureSettings,
OrgId: notification.OrgID,
DisableResolveMessage: notification.DisableResolveMessage,
Frequency: notification.Frequency,
......
......@@ -7,6 +7,7 @@ import (
"path/filepath"
"strings"
"github.com/grafana/grafana/pkg/components/securejsondata"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting"
......@@ -147,9 +148,10 @@ func validateNotifications(notifications []*notificationsAsConfig) error {
for _, notification := range notifications[i].Notifications {
_, err := alerting.InitNotifier(&models.AlertNotification{
Name: notification.Name,
Settings: notification.SettingsToJSON(),
Type: notification.Type,
Name: notification.Name,
Settings: notification.SettingsToJSON(),
SecureSettings: securejsondata.GetEncryptedJsonData(notification.SecureSettings),
Type: notification.Type,
})
if err != nil {
......
......@@ -66,6 +66,9 @@ func TestNotificationAsConfig(t *testing.T) {
So(nt.Settings, ShouldResemble, map[string]interface{}{
"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.Frequency, ShouldEqual, "1h")
......
......@@ -11,6 +11,9 @@ notifiers:
token: "xoxb"
uploadImage: true
url: https://slack.com
secure_settings:
url: https://slack.com/secure
token: "xoxbsecure"
- name: another-not-default-notification
type: email
settings:
......
......@@ -30,6 +30,7 @@ type notificationFromConfig struct {
Frequency string
IsDefault bool
Settings map[string]interface{}
SecureSettings map[string]string
}
// notificationsAsConfigV0 is mapping for zero version configs. This is mapped to its normalised version.
......@@ -46,16 +47,17 @@ type deleteNotificationConfigV0 struct {
}
type notificationFromConfigV0 struct {
UID values.StringValue `json:"uid" yaml:"uid"`
OrgID values.Int64Value `json:"org_id" yaml:"org_id"`
OrgName values.StringValue `json:"org_name" yaml:"org_name"`
Name values.StringValue `json:"name" yaml:"name"`
Type values.StringValue `json:"type" yaml:"type"`
SendReminder values.BoolValue `json:"send_reminder" yaml:"send_reminder"`
DisableResolveMessage values.BoolValue `json:"disable_resolve_message" yaml:"disable_resolve_message"`
Frequency values.StringValue `json:"frequency" yaml:"frequency"`
IsDefault values.BoolValue `json:"is_default" yaml:"is_default"`
Settings values.JSONValue `json:"settings" yaml:"settings"`
UID values.StringValue `json:"uid" yaml:"uid"`
OrgID values.Int64Value `json:"org_id" yaml:"org_id"`
OrgName values.StringValue `json:"org_name" yaml:"org_name"`
Name values.StringValue `json:"name" yaml:"name"`
Type values.StringValue `json:"type" yaml:"type"`
SendReminder values.BoolValue `json:"send_reminder" yaml:"send_reminder"`
DisableResolveMessage values.BoolValue `json:"disable_resolve_message" yaml:"disable_resolve_message"`
Frequency values.StringValue `json:"frequency" yaml:"frequency"`
IsDefault values.BoolValue `json:"is_default" yaml:"is_default"`
Settings values.JSONValue `json:"settings" yaml:"settings"`
SecureSettings values.StringMapValue `json:"secure_settings" yaml:"secure_settings"`
}
func (notification notificationFromConfig) SettingsToJSON() *simplejson.Json {
......@@ -88,6 +90,7 @@ func (cfg *notificationsAsConfigV0) mapToNotificationFromConfig() *notifications
DisableResolveMessage: notification.DisableResolveMessage.Value(),
Frequency: notification.Frequency.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