Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
db8d7ffb
Unverified
Commit
db8d7ffb
authored
Jun 30, 2020
by
Carl Bergquist
Committed by
GitHub
Jun 30, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Linting fixes for the provisioning package (#25690)
parent
891ae24f
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
96 additions
and
72 deletions
+96
-72
.circleci/config.yml
+2
-0
Makefile
+2
-0
pkg/services/provisioning/notifiers/alert_notifications.go
+20
-24
pkg/services/provisioning/notifiers/config_reader.go
+11
-11
pkg/services/provisioning/notifiers/config_reader_test.go
+24
-24
pkg/services/provisioning/notifiers/types.go
+13
-13
pkg/services/provisioning/values/values.go
+24
-0
No files found.
.circleci/config.yml
View file @
db8d7ffb
...
@@ -835,6 +835,8 @@ jobs:
...
@@ -835,6 +835,8 @@ jobs:
./pkg/services/alerting/... \
./pkg/services/alerting/... \
./pkg/services/provisioning/datasources/... \
./pkg/services/provisioning/datasources/... \
./pkg/services/provisioning/dashboards/... \
./pkg/services/provisioning/dashboards/... \
./pkg/services/provisioning/notifiers/... \
./pkg/services/provisioning/values/... \
./pkg/plugins/backendplugin/...
./pkg/plugins/backendplugin/...
test-frontend
:
test-frontend
:
...
...
Makefile
View file @
db8d7ffb
...
@@ -90,6 +90,8 @@ revive-strict: scripts/go/bin/revive
...
@@ -90,6 +90,8 @@ revive-strict: scripts/go/bin/revive
./pkg/services/alerting/...
\
./pkg/services/alerting/...
\
./pkg/services/provisioning/datasources/...
\
./pkg/services/provisioning/datasources/...
\
./pkg/services/provisioning/dashboards/...
\
./pkg/services/provisioning/dashboards/...
\
./pkg/services/provisioning/notifiers/...
\
./pkg/services/provisioning/values/...
\
./pkg/plugins/backendplugin/...
./pkg/plugins/backendplugin/...
scripts/go/bin/golangci-lint
:
scripts/go/go.mod
scripts/go/bin/golangci-lint
:
scripts/go/go.mod
...
...
pkg/services/provisioning/notifiers/alert_notifications.go
View file @
db8d7ffb
package
notifiers
package
notifiers
import
(
import
(
"errors"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/bus"
"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"
)
)
var
(
// Provision alert notifiers
ErrInvalidConfigTooManyDefault
=
errors
.
New
(
"Alert notification provisioning config is invalid. Only one alert notification can be marked as default"
)
)
func
Provision
(
configDirectory
string
)
error
{
func
Provision
(
configDirectory
string
)
error
{
dc
:=
newNotificationProvisioner
(
log
.
New
(
"provisioning.notifiers"
))
dc
:=
newNotificationProvisioner
(
log
.
New
(
"provisioning.notifiers"
))
return
dc
.
applyChanges
(
configDirectory
)
return
dc
.
applyChanges
(
configDirectory
)
}
}
// NotificationProvisioner is responsible for provsioning alert notifiers
type
NotificationProvisioner
struct
{
type
NotificationProvisioner
struct
{
log
log
.
Logger
log
log
.
Logger
cfgProvider
*
configReader
cfgProvider
*
configReader
...
@@ -43,19 +39,19 @@ func (dc *NotificationProvisioner) apply(cfg *notificationsAsConfig) error {
...
@@ -43,19 +39,19 @@ func (dc *NotificationProvisioner) apply(cfg *notificationsAsConfig) error {
func
(
dc
*
NotificationProvisioner
)
deleteNotifications
(
notificationToDelete
[]
*
deleteNotificationConfig
)
error
{
func
(
dc
*
NotificationProvisioner
)
deleteNotifications
(
notificationToDelete
[]
*
deleteNotificationConfig
)
error
{
for
_
,
notification
:=
range
notificationToDelete
{
for
_
,
notification
:=
range
notificationToDelete
{
dc
.
log
.
Info
(
"Deleting alert notification"
,
"name"
,
notification
.
Name
,
"uid"
,
notification
.
U
id
)
dc
.
log
.
Info
(
"Deleting alert notification"
,
"name"
,
notification
.
Name
,
"uid"
,
notification
.
U
ID
)
if
notification
.
OrgI
d
==
0
&&
notification
.
OrgName
!=
""
{
if
notification
.
OrgI
D
==
0
&&
notification
.
OrgName
!=
""
{
getOrg
:=
&
models
.
GetOrgByNameQuery
{
Name
:
notification
.
OrgName
}
getOrg
:=
&
models
.
GetOrgByNameQuery
{
Name
:
notification
.
OrgName
}
if
err
:=
bus
.
Dispatch
(
getOrg
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
getOrg
);
err
!=
nil
{
return
err
return
err
}
}
notification
.
OrgI
d
=
getOrg
.
Result
.
Id
notification
.
OrgI
D
=
getOrg
.
Result
.
Id
}
else
if
notification
.
OrgI
d
<
0
{
}
else
if
notification
.
OrgI
D
<
0
{
notification
.
OrgI
d
=
1
notification
.
OrgI
D
=
1
}
}
getNotification
:=
&
models
.
GetAlertNotificationsWithUidQuery
{
Uid
:
notification
.
U
id
,
OrgId
:
notification
.
OrgId
}
getNotification
:=
&
models
.
GetAlertNotificationsWithUidQuery
{
Uid
:
notification
.
U
ID
,
OrgId
:
notification
.
OrgID
}
if
err
:=
bus
.
Dispatch
(
getNotification
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
getNotification
);
err
!=
nil
{
return
err
return
err
...
@@ -75,31 +71,31 @@ func (dc *NotificationProvisioner) deleteNotifications(notificationToDelete []*d
...
@@ -75,31 +71,31 @@ func (dc *NotificationProvisioner) deleteNotifications(notificationToDelete []*d
func
(
dc
*
NotificationProvisioner
)
mergeNotifications
(
notificationToMerge
[]
*
notificationFromConfig
)
error
{
func
(
dc
*
NotificationProvisioner
)
mergeNotifications
(
notificationToMerge
[]
*
notificationFromConfig
)
error
{
for
_
,
notification
:=
range
notificationToMerge
{
for
_
,
notification
:=
range
notificationToMerge
{
if
notification
.
OrgI
d
==
0
&&
notification
.
OrgName
!=
""
{
if
notification
.
OrgI
D
==
0
&&
notification
.
OrgName
!=
""
{
getOrg
:=
&
models
.
GetOrgByNameQuery
{
Name
:
notification
.
OrgName
}
getOrg
:=
&
models
.
GetOrgByNameQuery
{
Name
:
notification
.
OrgName
}
if
err
:=
bus
.
Dispatch
(
getOrg
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
getOrg
);
err
!=
nil
{
return
err
return
err
}
}
notification
.
OrgI
d
=
getOrg
.
Result
.
Id
notification
.
OrgI
D
=
getOrg
.
Result
.
Id
}
else
if
notification
.
OrgI
d
<
0
{
}
else
if
notification
.
OrgI
D
<
0
{
notification
.
OrgI
d
=
1
notification
.
OrgI
D
=
1
}
}
cmd
:=
&
models
.
GetAlertNotificationsWithUidQuery
{
OrgId
:
notification
.
OrgI
d
,
Uid
:
notification
.
Uid
}
cmd
:=
&
models
.
GetAlertNotificationsWithUidQuery
{
OrgId
:
notification
.
OrgI
D
,
Uid
:
notification
.
UID
}
err
:=
bus
.
Dispatch
(
cmd
)
err
:=
bus
.
Dispatch
(
cmd
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
cmd
.
Result
==
nil
{
if
cmd
.
Result
==
nil
{
dc
.
log
.
Debug
(
"inserting alert notification from configuration"
,
"name"
,
notification
.
Name
,
"uid"
,
notification
.
U
id
)
dc
.
log
.
Debug
(
"inserting alert notification from configuration"
,
"name"
,
notification
.
Name
,
"uid"
,
notification
.
U
ID
)
insertCmd
:=
&
models
.
CreateAlertNotificationCommand
{
insertCmd
:=
&
models
.
CreateAlertNotificationCommand
{
Uid
:
notification
.
U
id
,
Uid
:
notification
.
U
ID
,
Name
:
notification
.
Name
,
Name
:
notification
.
Name
,
Type
:
notification
.
Type
,
Type
:
notification
.
Type
,
IsDefault
:
notification
.
IsDefault
,
IsDefault
:
notification
.
IsDefault
,
Settings
:
notification
.
SettingsToJ
son
(),
Settings
:
notification
.
SettingsToJ
SON
(),
OrgId
:
notification
.
OrgI
d
,
OrgId
:
notification
.
OrgI
D
,
DisableResolveMessage
:
notification
.
DisableResolveMessage
,
DisableResolveMessage
:
notification
.
DisableResolveMessage
,
Frequency
:
notification
.
Frequency
,
Frequency
:
notification
.
Frequency
,
SendReminder
:
notification
.
SendReminder
,
SendReminder
:
notification
.
SendReminder
,
...
@@ -111,12 +107,12 @@ func (dc *NotificationProvisioner) mergeNotifications(notificationToMerge []*not
...
@@ -111,12 +107,12 @@ func (dc *NotificationProvisioner) mergeNotifications(notificationToMerge []*not
}
else
{
}
else
{
dc
.
log
.
Debug
(
"updating alert notification from configuration"
,
"name"
,
notification
.
Name
)
dc
.
log
.
Debug
(
"updating alert notification from configuration"
,
"name"
,
notification
.
Name
)
updateCmd
:=
&
models
.
UpdateAlertNotificationWithUidCommand
{
updateCmd
:=
&
models
.
UpdateAlertNotificationWithUidCommand
{
Uid
:
notification
.
U
id
,
Uid
:
notification
.
U
ID
,
Name
:
notification
.
Name
,
Name
:
notification
.
Name
,
Type
:
notification
.
Type
,
Type
:
notification
.
Type
,
IsDefault
:
notification
.
IsDefault
,
IsDefault
:
notification
.
IsDefault
,
Settings
:
notification
.
SettingsToJ
son
(),
Settings
:
notification
.
SettingsToJ
SON
(),
OrgId
:
notification
.
OrgI
d
,
OrgId
:
notification
.
OrgI
D
,
DisableResolveMessage
:
notification
.
DisableResolveMessage
,
DisableResolveMessage
:
notification
.
DisableResolveMessage
,
Frequency
:
notification
.
Frequency
,
Frequency
:
notification
.
Frequency
,
SendReminder
:
notification
.
SendReminder
,
SendReminder
:
notification
.
SendReminder
,
...
...
pkg/services/provisioning/notifiers/config_reader.go
View file @
db8d7ffb
...
@@ -46,7 +46,7 @@ func (cr *configReader) readConfig(path string) ([]*notificationsAsConfig, error
...
@@ -46,7 +46,7 @@ func (cr *configReader) readConfig(path string) ([]*notificationsAsConfig, error
return
nil
,
err
return
nil
,
err
}
}
checkOrgI
d
AndOrgName
(
notifications
)
checkOrgI
D
AndOrgName
(
notifications
)
err
=
validateNotifications
(
notifications
)
err
=
validateNotifications
(
notifications
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -72,24 +72,24 @@ func (cr *configReader) parseNotificationConfig(path string, file os.FileInfo) (
...
@@ -72,24 +72,24 @@ func (cr *configReader) parseNotificationConfig(path string, file os.FileInfo) (
return
cfg
.
mapToNotificationFromConfig
(),
nil
return
cfg
.
mapToNotificationFromConfig
(),
nil
}
}
func
checkOrgI
d
AndOrgName
(
notifications
[]
*
notificationsAsConfig
)
{
func
checkOrgI
D
AndOrgName
(
notifications
[]
*
notificationsAsConfig
)
{
for
i
:=
range
notifications
{
for
i
:=
range
notifications
{
for
_
,
notification
:=
range
notifications
[
i
]
.
Notifications
{
for
_
,
notification
:=
range
notifications
[
i
]
.
Notifications
{
if
notification
.
OrgI
d
<
1
{
if
notification
.
OrgI
D
<
1
{
if
notification
.
OrgName
==
""
{
if
notification
.
OrgName
==
""
{
notification
.
OrgI
d
=
1
notification
.
OrgI
D
=
1
}
else
{
}
else
{
notification
.
OrgI
d
=
0
notification
.
OrgI
D
=
0
}
}
}
}
}
}
for
_
,
notification
:=
range
notifications
[
i
]
.
DeleteNotifications
{
for
_
,
notification
:=
range
notifications
[
i
]
.
DeleteNotifications
{
if
notification
.
OrgI
d
<
1
{
if
notification
.
OrgI
D
<
1
{
if
notification
.
OrgName
==
""
{
if
notification
.
OrgName
==
""
{
notification
.
OrgI
d
=
1
notification
.
OrgI
D
=
1
}
else
{
}
else
{
notification
.
OrgI
d
=
0
notification
.
OrgI
D
=
0
}
}
}
}
}
}
...
@@ -107,7 +107,7 @@ func validateRequiredField(notifications []*notificationsAsConfig) error {
...
@@ -107,7 +107,7 @@ func validateRequiredField(notifications []*notificationsAsConfig) error {
)
)
}
}
if
notification
.
U
id
==
""
{
if
notification
.
U
ID
==
""
{
errStrings
=
append
(
errStrings
=
append
(
errStrings
,
errStrings
,
fmt
.
Sprintf
(
"Added alert notification item %d in configuration doesn't contain required field uid"
,
index
+
1
),
fmt
.
Sprintf
(
"Added alert notification item %d in configuration doesn't contain required field uid"
,
index
+
1
),
...
@@ -123,7 +123,7 @@ func validateRequiredField(notifications []*notificationsAsConfig) error {
...
@@ -123,7 +123,7 @@ func validateRequiredField(notifications []*notificationsAsConfig) error {
)
)
}
}
if
notification
.
U
id
==
""
{
if
notification
.
U
ID
==
""
{
errStrings
=
append
(
errStrings
=
append
(
errStrings
,
errStrings
,
fmt
.
Sprintf
(
"Deleted alert notification item %d in configuration doesn't contain required field uid"
,
index
+
1
),
fmt
.
Sprintf
(
"Deleted alert notification item %d in configuration doesn't contain required field uid"
,
index
+
1
),
...
@@ -149,7 +149,7 @@ func validateNotifications(notifications []*notificationsAsConfig) error {
...
@@ -149,7 +149,7 @@ 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
.
SettingsToJ
son
(),
Settings
:
notification
.
SettingsToJ
SON
(),
Type
:
notification
.
Type
,
Type
:
notification
.
Type
,
})
})
...
...
pkg/services/provisioning/notifiers/config_reader_test.go
View file @
db8d7ffb
...
@@ -13,10 +13,10 @@ import (
...
@@ -13,10 +13,10 @@ import (
)
)
var
(
var
(
correct
_properties
=
"./testdata/test-configs/correct-properties"
correct
Properties
=
"./testdata/test-configs/correct-properties"
incorrect
_settings
=
"./testdata/test-configs/incorrect-settings"
incorrect
Settings
=
"./testdata/test-configs/incorrect-settings"
no
_required_fields
=
"./testdata/test-configs/no-required-fields"
no
RequiredFields
=
"./testdata/test-configs/no-required-fields"
correct
_properties_with_o
rgName
=
"./testdata/test-configs/correct-properties-with-orgName"
correct
PropertiesWithO
rgName
=
"./testdata/test-configs/correct-properties-with-orgName"
brokenYaml
=
"./testdata/test-configs/broken-yaml"
brokenYaml
=
"./testdata/test-configs/broken-yaml"
doubleNotificationsConfig
=
"./testdata/test-configs/double-default"
doubleNotificationsConfig
=
"./testdata/test-configs/double-default"
emptyFolder
=
"./testdata/test-configs/empty_folder"
emptyFolder
=
"./testdata/test-configs/empty_folder"
...
@@ -46,7 +46,7 @@ func TestNotificationAsConfig(t *testing.T) {
...
@@ -46,7 +46,7 @@ func TestNotificationAsConfig(t *testing.T) {
Convey
(
"Can read correct properties"
,
func
()
{
Convey
(
"Can read correct properties"
,
func
()
{
_
=
os
.
Setenv
(
"TEST_VAR"
,
"default"
)
_
=
os
.
Setenv
(
"TEST_VAR"
,
"default"
)
cfgProvider
:=
&
configReader
{
log
:
log
.
New
(
"test logger"
)}
cfgProvider
:=
&
configReader
{
log
:
log
.
New
(
"test logger"
)}
cfg
,
err
:=
cfgProvider
.
readConfig
(
correct
_p
roperties
)
cfg
,
err
:=
cfgProvider
.
readConfig
(
correct
P
roperties
)
_
=
os
.
Unsetenv
(
"TEST_VAR"
)
_
=
os
.
Unsetenv
(
"TEST_VAR"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"readConfig return an error %v"
,
err
)
t
.
Fatalf
(
"readConfig return an error %v"
,
err
)
...
@@ -60,8 +60,8 @@ func TestNotificationAsConfig(t *testing.T) {
...
@@ -60,8 +60,8 @@ func TestNotificationAsConfig(t *testing.T) {
nt
:=
nts
[
0
]
nt
:=
nts
[
0
]
So
(
nt
.
Name
,
ShouldEqual
,
"default-slack-notification"
)
So
(
nt
.
Name
,
ShouldEqual
,
"default-slack-notification"
)
So
(
nt
.
Type
,
ShouldEqual
,
"slack"
)
So
(
nt
.
Type
,
ShouldEqual
,
"slack"
)
So
(
nt
.
OrgI
d
,
ShouldEqual
,
2
)
So
(
nt
.
OrgI
D
,
ShouldEqual
,
2
)
So
(
nt
.
U
id
,
ShouldEqual
,
"notifier1"
)
So
(
nt
.
U
ID
,
ShouldEqual
,
"notifier1"
)
So
(
nt
.
IsDefault
,
ShouldBeTrue
)
So
(
nt
.
IsDefault
,
ShouldBeTrue
)
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"
,
...
@@ -72,45 +72,45 @@ func TestNotificationAsConfig(t *testing.T) {
...
@@ -72,45 +72,45 @@ func TestNotificationAsConfig(t *testing.T) {
nt
=
nts
[
1
]
nt
=
nts
[
1
]
So
(
nt
.
Name
,
ShouldEqual
,
"another-not-default-notification"
)
So
(
nt
.
Name
,
ShouldEqual
,
"another-not-default-notification"
)
So
(
nt
.
Type
,
ShouldEqual
,
"email"
)
So
(
nt
.
Type
,
ShouldEqual
,
"email"
)
So
(
nt
.
OrgI
d
,
ShouldEqual
,
3
)
So
(
nt
.
OrgI
D
,
ShouldEqual
,
3
)
So
(
nt
.
U
id
,
ShouldEqual
,
"notifier2"
)
So
(
nt
.
U
ID
,
ShouldEqual
,
"notifier2"
)
So
(
nt
.
IsDefault
,
ShouldBeFalse
)
So
(
nt
.
IsDefault
,
ShouldBeFalse
)
nt
=
nts
[
2
]
nt
=
nts
[
2
]
So
(
nt
.
Name
,
ShouldEqual
,
"check-unset-is_default-is-false"
)
So
(
nt
.
Name
,
ShouldEqual
,
"check-unset-is_default-is-false"
)
So
(
nt
.
Type
,
ShouldEqual
,
"slack"
)
So
(
nt
.
Type
,
ShouldEqual
,
"slack"
)
So
(
nt
.
OrgI
d
,
ShouldEqual
,
3
)
So
(
nt
.
OrgI
D
,
ShouldEqual
,
3
)
So
(
nt
.
U
id
,
ShouldEqual
,
"notifier3"
)
So
(
nt
.
U
ID
,
ShouldEqual
,
"notifier3"
)
So
(
nt
.
IsDefault
,
ShouldBeFalse
)
So
(
nt
.
IsDefault
,
ShouldBeFalse
)
nt
=
nts
[
3
]
nt
=
nts
[
3
]
So
(
nt
.
Name
,
ShouldEqual
,
"Added notification with whitespaces in name"
)
So
(
nt
.
Name
,
ShouldEqual
,
"Added notification with whitespaces in name"
)
So
(
nt
.
Type
,
ShouldEqual
,
"email"
)
So
(
nt
.
Type
,
ShouldEqual
,
"email"
)
So
(
nt
.
U
id
,
ShouldEqual
,
"notifier4"
)
So
(
nt
.
U
ID
,
ShouldEqual
,
"notifier4"
)
So
(
nt
.
OrgI
d
,
ShouldEqual
,
3
)
So
(
nt
.
OrgI
D
,
ShouldEqual
,
3
)
deleteNts
:=
ntCfg
.
DeleteNotifications
deleteNts
:=
ntCfg
.
DeleteNotifications
So
(
len
(
deleteNts
),
ShouldEqual
,
4
)
So
(
len
(
deleteNts
),
ShouldEqual
,
4
)
deleteNt
:=
deleteNts
[
0
]
deleteNt
:=
deleteNts
[
0
]
So
(
deleteNt
.
Name
,
ShouldEqual
,
"default-slack-notification"
)
So
(
deleteNt
.
Name
,
ShouldEqual
,
"default-slack-notification"
)
So
(
deleteNt
.
U
id
,
ShouldEqual
,
"notifier1"
)
So
(
deleteNt
.
U
ID
,
ShouldEqual
,
"notifier1"
)
So
(
deleteNt
.
OrgI
d
,
ShouldEqual
,
2
)
So
(
deleteNt
.
OrgI
D
,
ShouldEqual
,
2
)
deleteNt
=
deleteNts
[
1
]
deleteNt
=
deleteNts
[
1
]
So
(
deleteNt
.
Name
,
ShouldEqual
,
"deleted-notification-without-orgId"
)
So
(
deleteNt
.
Name
,
ShouldEqual
,
"deleted-notification-without-orgId"
)
So
(
deleteNt
.
OrgI
d
,
ShouldEqual
,
1
)
So
(
deleteNt
.
OrgI
D
,
ShouldEqual
,
1
)
So
(
deleteNt
.
U
id
,
ShouldEqual
,
"notifier2"
)
So
(
deleteNt
.
U
ID
,
ShouldEqual
,
"notifier2"
)
deleteNt
=
deleteNts
[
2
]
deleteNt
=
deleteNts
[
2
]
So
(
deleteNt
.
Name
,
ShouldEqual
,
"deleted-notification-with-0-orgId"
)
So
(
deleteNt
.
Name
,
ShouldEqual
,
"deleted-notification-with-0-orgId"
)
So
(
deleteNt
.
OrgI
d
,
ShouldEqual
,
1
)
So
(
deleteNt
.
OrgI
D
,
ShouldEqual
,
1
)
So
(
deleteNt
.
U
id
,
ShouldEqual
,
"notifier3"
)
So
(
deleteNt
.
U
ID
,
ShouldEqual
,
"notifier3"
)
deleteNt
=
deleteNts
[
3
]
deleteNt
=
deleteNts
[
3
]
So
(
deleteNt
.
Name
,
ShouldEqual
,
"Deleted notification with whitespaces in name"
)
So
(
deleteNt
.
Name
,
ShouldEqual
,
"Deleted notification with whitespaces in name"
)
So
(
deleteNt
.
OrgI
d
,
ShouldEqual
,
1
)
So
(
deleteNt
.
OrgI
D
,
ShouldEqual
,
1
)
So
(
deleteNt
.
U
id
,
ShouldEqual
,
"notifier4"
)
So
(
deleteNt
.
U
ID
,
ShouldEqual
,
"notifier4"
)
})
})
Convey
(
"One configured notification"
,
func
()
{
Convey
(
"One configured notification"
,
func
()
{
...
@@ -243,7 +243,7 @@ func TestNotificationAsConfig(t *testing.T) {
...
@@ -243,7 +243,7 @@ func TestNotificationAsConfig(t *testing.T) {
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
dc
:=
newNotificationProvisioner
(
logger
)
dc
:=
newNotificationProvisioner
(
logger
)
err
=
dc
.
applyChanges
(
correct
_properties_with_o
rgName
)
err
=
dc
.
applyChanges
(
correct
PropertiesWithO
rgName
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"applyChanges return an error %v"
,
err
)
t
.
Fatalf
(
"applyChanges return an error %v"
,
err
)
}
}
...
@@ -262,7 +262,7 @@ func TestNotificationAsConfig(t *testing.T) {
...
@@ -262,7 +262,7 @@ func TestNotificationAsConfig(t *testing.T) {
Convey
(
"Config doesn't contain required field"
,
func
()
{
Convey
(
"Config doesn't contain required field"
,
func
()
{
dc
:=
newNotificationProvisioner
(
logger
)
dc
:=
newNotificationProvisioner
(
logger
)
err
:=
dc
.
applyChanges
(
no
_required_f
ields
)
err
:=
dc
.
applyChanges
(
no
RequiredF
ields
)
So
(
err
,
ShouldNotBeNil
)
So
(
err
,
ShouldNotBeNil
)
errString
:=
err
.
Error
()
errString
:=
err
.
Error
()
...
@@ -310,7 +310,7 @@ func TestNotificationAsConfig(t *testing.T) {
...
@@ -310,7 +310,7 @@ func TestNotificationAsConfig(t *testing.T) {
Convey
(
"Read incorrect properties"
,
func
()
{
Convey
(
"Read incorrect properties"
,
func
()
{
cfgProvider
:=
&
configReader
{
log
:
log
.
New
(
"test logger"
)}
cfgProvider
:=
&
configReader
{
log
:
log
.
New
(
"test logger"
)}
_
,
err
:=
cfgProvider
.
readConfig
(
incorrect
_s
ettings
)
_
,
err
:=
cfgProvider
.
readConfig
(
incorrect
S
ettings
)
So
(
err
,
ShouldNotBeNil
)
So
(
err
,
ShouldNotBeNil
)
So
(
err
.
Error
(),
ShouldEqual
,
"Alert validation error: Could not find url property in settings"
)
So
(
err
.
Error
(),
ShouldEqual
,
"Alert validation error: Could not find url property in settings"
)
})
})
...
...
pkg/services/provisioning/notifiers/types.go
View file @
db8d7ffb
...
@@ -13,15 +13,15 @@ type notificationsAsConfig struct {
...
@@ -13,15 +13,15 @@ type notificationsAsConfig struct {
}
}
type
deleteNotificationConfig
struct
{
type
deleteNotificationConfig
struct
{
U
id
string
U
ID
string
Name
string
Name
string
OrgI
d
int64
OrgI
D
int64
OrgName
string
OrgName
string
}
}
type
notificationFromConfig
struct
{
type
notificationFromConfig
struct
{
U
id
string
U
ID
string
OrgI
d
int64
OrgI
D
int64
OrgName
string
OrgName
string
Name
string
Name
string
Type
string
Type
string
...
@@ -39,15 +39,15 @@ type notificationsAsConfigV0 struct {
...
@@ -39,15 +39,15 @@ type notificationsAsConfigV0 struct {
}
}
type
deleteNotificationConfigV0
struct
{
type
deleteNotificationConfigV0
struct
{
U
id
values
.
StringValue
`json:"uid" yaml:"uid"`
U
ID
values
.
StringValue
`json:"uid" yaml:"uid"`
Name
values
.
StringValue
`json:"name" yaml:"name"`
Name
values
.
StringValue
`json:"name" yaml:"name"`
OrgI
d
values
.
Int64Value
`json:"org_id" yaml:"org_id"`
OrgI
D
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"`
}
}
type
notificationFromConfigV0
struct
{
type
notificationFromConfigV0
struct
{
U
id
values
.
StringValue
`json:"uid" yaml:"uid"`
U
ID
values
.
StringValue
`json:"uid" yaml:"uid"`
OrgI
d
values
.
Int64Value
`json:"org_id" yaml:"org_id"`
OrgI
D
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"`
...
@@ -58,7 +58,7 @@ type notificationFromConfigV0 struct {
...
@@ -58,7 +58,7 @@ type notificationFromConfigV0 struct {
Settings
values
.
JSONValue
`json:"settings" yaml:"settings"`
Settings
values
.
JSONValue
`json:"settings" yaml:"settings"`
}
}
func
(
notification
notificationFromConfig
)
SettingsToJ
son
()
*
simplejson
.
Json
{
func
(
notification
notificationFromConfig
)
SettingsToJ
SON
()
*
simplejson
.
Json
{
settings
:=
simplejson
.
New
()
settings
:=
simplejson
.
New
()
if
len
(
notification
.
Settings
)
>
0
{
if
len
(
notification
.
Settings
)
>
0
{
for
k
,
v
:=
range
notification
.
Settings
{
for
k
,
v
:=
range
notification
.
Settings
{
...
@@ -78,8 +78,8 @@ func (cfg *notificationsAsConfigV0) mapToNotificationFromConfig() *notifications
...
@@ -78,8 +78,8 @@ func (cfg *notificationsAsConfigV0) mapToNotificationFromConfig() *notifications
for
_
,
notification
:=
range
cfg
.
Notifications
{
for
_
,
notification
:=
range
cfg
.
Notifications
{
r
.
Notifications
=
append
(
r
.
Notifications
,
&
notificationFromConfig
{
r
.
Notifications
=
append
(
r
.
Notifications
,
&
notificationFromConfig
{
U
id
:
notification
.
Uid
.
Value
(),
U
ID
:
notification
.
UID
.
Value
(),
OrgI
d
:
notification
.
OrgId
.
Value
(),
OrgI
D
:
notification
.
OrgID
.
Value
(),
OrgName
:
notification
.
OrgName
.
Value
(),
OrgName
:
notification
.
OrgName
.
Value
(),
Name
:
notification
.
Name
.
Value
(),
Name
:
notification
.
Name
.
Value
(),
Type
:
notification
.
Type
.
Value
(),
Type
:
notification
.
Type
.
Value
(),
...
@@ -93,8 +93,8 @@ func (cfg *notificationsAsConfigV0) mapToNotificationFromConfig() *notifications
...
@@ -93,8 +93,8 @@ func (cfg *notificationsAsConfigV0) mapToNotificationFromConfig() *notifications
for
_
,
notification
:=
range
cfg
.
DeleteNotifications
{
for
_
,
notification
:=
range
cfg
.
DeleteNotifications
{
r
.
DeleteNotifications
=
append
(
r
.
DeleteNotifications
,
&
deleteNotificationConfig
{
r
.
DeleteNotifications
=
append
(
r
.
DeleteNotifications
,
&
deleteNotificationConfig
{
U
id
:
notification
.
Uid
.
Value
(),
U
ID
:
notification
.
UID
.
Value
(),
OrgI
d
:
notification
.
OrgId
.
Value
(),
OrgI
D
:
notification
.
OrgID
.
Value
(),
OrgName
:
notification
.
OrgName
.
Value
(),
OrgName
:
notification
.
OrgName
.
Value
(),
Name
:
notification
.
Name
.
Value
(),
Name
:
notification
.
Name
.
Value
(),
})
})
...
...
pkg/services/provisioning/values/values.go
View file @
db8d7ffb
...
@@ -22,11 +22,14 @@ import (
...
@@ -22,11 +22,14 @@ import (
"github.com/grafana/grafana/pkg/util/errutil"
"github.com/grafana/grafana/pkg/util/errutil"
)
)
// IntValue represents a string value in a YAML
// config that can be overridden by environment variables
type
IntValue
struct
{
type
IntValue
struct
{
value
int
value
int
Raw
string
Raw
string
}
}
// UnmarshalYAML converts YAML into an *IntValue
func
(
val
*
IntValue
)
UnmarshalYAML
(
unmarshal
func
(
interface
{})
error
)
error
{
func
(
val
*
IntValue
)
UnmarshalYAML
(
unmarshal
func
(
interface
{})
error
)
error
{
interpolated
,
err
:=
getInterpolated
(
unmarshal
)
interpolated
,
err
:=
getInterpolated
(
unmarshal
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -41,15 +44,19 @@ func (val *IntValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
...
@@ -41,15 +44,19 @@ func (val *IntValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
return
errutil
.
Wrap
(
"cannot convert value int"
,
err
)
return
errutil
.
Wrap
(
"cannot convert value int"
,
err
)
}
}
// Value returns the wrapped int value
func
(
val
*
IntValue
)
Value
()
int
{
func
(
val
*
IntValue
)
Value
()
int
{
return
val
.
value
return
val
.
value
}
}
// Int64Value represents a string value in a YAML
// config that can be overridden by environment variables
type
Int64Value
struct
{
type
Int64Value
struct
{
value
int64
value
int64
Raw
string
Raw
string
}
}
// UnmarshalYAML converts YAML into an *Int64Value
func
(
val
*
Int64Value
)
UnmarshalYAML
(
unmarshal
func
(
interface
{})
error
)
error
{
func
(
val
*
Int64Value
)
UnmarshalYAML
(
unmarshal
func
(
interface
{})
error
)
error
{
interpolated
,
err
:=
getInterpolated
(
unmarshal
)
interpolated
,
err
:=
getInterpolated
(
unmarshal
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -64,15 +71,19 @@ func (val *Int64Value) UnmarshalYAML(unmarshal func(interface{}) error) error {
...
@@ -64,15 +71,19 @@ func (val *Int64Value) UnmarshalYAML(unmarshal func(interface{}) error) error {
return
err
return
err
}
}
// Value returns the wrapped int64 value
func
(
val
*
Int64Value
)
Value
()
int64
{
func
(
val
*
Int64Value
)
Value
()
int64
{
return
val
.
value
return
val
.
value
}
}
// StringValue represents a string value in a YAML
// config that can be overridden by environment variables
type
StringValue
struct
{
type
StringValue
struct
{
value
string
value
string
Raw
string
Raw
string
}
}
// UnmarshalYAML converts YAML into an *StringValue
func
(
val
*
StringValue
)
UnmarshalYAML
(
unmarshal
func
(
interface
{})
error
)
error
{
func
(
val
*
StringValue
)
UnmarshalYAML
(
unmarshal
func
(
interface
{})
error
)
error
{
interpolated
,
err
:=
getInterpolated
(
unmarshal
)
interpolated
,
err
:=
getInterpolated
(
unmarshal
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -83,15 +94,19 @@ func (val *StringValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
...
@@ -83,15 +94,19 @@ func (val *StringValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
return
err
return
err
}
}
// Value returns the wrapped string value
func
(
val
*
StringValue
)
Value
()
string
{
func
(
val
*
StringValue
)
Value
()
string
{
return
val
.
value
return
val
.
value
}
}
// BoolValue represents a string value in a YAML
// config that can be overridden by environment variables
type
BoolValue
struct
{
type
BoolValue
struct
{
value
bool
value
bool
Raw
string
Raw
string
}
}
// UnmarshalYAML converts YAML into an *BoolValue
func
(
val
*
BoolValue
)
UnmarshalYAML
(
unmarshal
func
(
interface
{})
error
)
error
{
func
(
val
*
BoolValue
)
UnmarshalYAML
(
unmarshal
func
(
interface
{})
error
)
error
{
interpolated
,
err
:=
getInterpolated
(
unmarshal
)
interpolated
,
err
:=
getInterpolated
(
unmarshal
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -102,15 +117,19 @@ func (val *BoolValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
...
@@ -102,15 +117,19 @@ func (val *BoolValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
return
err
return
err
}
}
// Value returns the wrapped bool value
func
(
val
*
BoolValue
)
Value
()
bool
{
func
(
val
*
BoolValue
)
Value
()
bool
{
return
val
.
value
return
val
.
value
}
}
// JSONValue represents a string value in a YAML
// config that can be overridden by environment variables
type
JSONValue
struct
{
type
JSONValue
struct
{
value
map
[
string
]
interface
{}
value
map
[
string
]
interface
{}
Raw
map
[
string
]
interface
{}
Raw
map
[
string
]
interface
{}
}
}
// UnmarshalYAML converts YAML into an *JSONValue
func
(
val
*
JSONValue
)
UnmarshalYAML
(
unmarshal
func
(
interface
{})
error
)
error
{
func
(
val
*
JSONValue
)
UnmarshalYAML
(
unmarshal
func
(
interface
{})
error
)
error
{
unmarshaled
:=
make
(
map
[
string
]
interface
{})
unmarshaled
:=
make
(
map
[
string
]
interface
{})
err
:=
unmarshal
(
unmarshaled
)
err
:=
unmarshal
(
unmarshaled
)
...
@@ -131,15 +150,19 @@ func (val *JSONValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
...
@@ -131,15 +150,19 @@ func (val *JSONValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
return
err
return
err
}
}
// Value returns the wrapped JSON value as map[string]interface{}
func
(
val
*
JSONValue
)
Value
()
map
[
string
]
interface
{}
{
func
(
val
*
JSONValue
)
Value
()
map
[
string
]
interface
{}
{
return
val
.
value
return
val
.
value
}
}
// StringMapValue represents a string value in a YAML
// config that can be overridden by environment variables
type
StringMapValue
struct
{
type
StringMapValue
struct
{
value
map
[
string
]
string
value
map
[
string
]
string
Raw
map
[
string
]
string
Raw
map
[
string
]
string
}
}
// UnmarshalYAML converts YAML into an *StringMapValue
func
(
val
*
StringMapValue
)
UnmarshalYAML
(
unmarshal
func
(
interface
{})
error
)
error
{
func
(
val
*
StringMapValue
)
UnmarshalYAML
(
unmarshal
func
(
interface
{})
error
)
error
{
unmarshaled
:=
make
(
map
[
string
]
string
)
unmarshaled
:=
make
(
map
[
string
]
string
)
err
:=
unmarshal
(
unmarshaled
)
err
:=
unmarshal
(
unmarshaled
)
...
@@ -159,6 +182,7 @@ func (val *StringMapValue) UnmarshalYAML(unmarshal func(interface{}) error) erro
...
@@ -159,6 +182,7 @@ func (val *StringMapValue) UnmarshalYAML(unmarshal func(interface{}) error) erro
return
err
return
err
}
}
// Value returns the wrapped map[string]string value
func
(
val
*
StringMapValue
)
Value
()
map
[
string
]
string
{
func
(
val
*
StringMapValue
)
Value
()
map
[
string
]
string
{
return
val
.
value
return
val
.
value
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment