fixing notifications.

pull/75/head
Jason Kulatunga 4 years ago
parent 6377a258f6
commit d339e967a6

@ -35,6 +35,8 @@ func (c *configuration) Init() error {
c.SetDefault("log.level", "INFO")
c.SetDefault("log.file", "")
c.SetDefault("notify.urls", []string{})
//c.SetDefault("disks.include", []string{})
//c.SetDefault("disks.exclude", []string{})

@ -5,7 +5,7 @@ import (
)
// Create mock using:
// mockgen -source=pkg/config/interface.go -destination=pkg/config/mock/mock_config.go
// mockgen -source=webapp/backend/pkg/config/interface.go -destination=webapp/backend/pkg/config/mock/mock_config.go
type Interface interface {
Init() error
ReadConfig(configFilePath string) error

@ -71,6 +71,11 @@ func (n *Notify) Send() error {
configUrls := n.Config.GetStringSlice("notify.urls")
n.Logger.Debugf("Configured notification services: %v", configUrls)
if len(configUrls) == 0 {
n.Logger.Infof("No notification endpoints configured. Skipping failure notification.")
return nil
}
//remove http:// https:// and script:// prefixed urls
notifyWebhooks := []string{}
notifyScripts := []string{}

@ -60,6 +60,7 @@ func UploadDeviceMetrics(c *gin.Context) {
DeviceSerial: device.SerialNumber,
Test: false,
},
Logger: logger,
}
_ = testNotify.Send() //we ignore error message when sending notifications.
}

@ -109,6 +109,7 @@ func TestPopulateMultiple(t *testing.T) {
defer mockCtrl.Finish()
fakeConfig := mock_config.NewMockInterface(mockCtrl)
//fakeConfig.EXPECT().GetString("web.database.location").AnyTimes().Return("testdata/scrutiny_test.db")
fakeConfig.EXPECT().GetStringSlice("notify.urls").Return([]string{}).AnyTimes()
fakeConfig.EXPECT().GetString("web.database.location").AnyTimes().Return(path.Join(parentPath, "scrutiny_test.db"))
fakeConfig.EXPECT().GetString("web.src.frontend.path").AnyTimes().Return(parentPath)
ae := web.AppEngine{

Loading…
Cancel
Save