From d339e967a619fce7f8447f8bb79ef30bbcc10256 Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Fri, 2 Oct 2020 21:05:04 -0600 Subject: [PATCH] fixing notifications. --- webapp/backend/pkg/config/config.go | 2 ++ webapp/backend/pkg/config/interface.go | 2 +- webapp/backend/pkg/notify/notify.go | 5 +++++ webapp/backend/pkg/web/handler/upload_device_metrics.go | 1 + webapp/backend/pkg/web/server_test.go | 1 + 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/webapp/backend/pkg/config/config.go b/webapp/backend/pkg/config/config.go index 95111b0..6349b55 100644 --- a/webapp/backend/pkg/config/config.go +++ b/webapp/backend/pkg/config/config.go @@ -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{}) diff --git a/webapp/backend/pkg/config/interface.go b/webapp/backend/pkg/config/interface.go index 479142c..fabe8af 100644 --- a/webapp/backend/pkg/config/interface.go +++ b/webapp/backend/pkg/config/interface.go @@ -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 diff --git a/webapp/backend/pkg/notify/notify.go b/webapp/backend/pkg/notify/notify.go index 01b5306..f2ccedc 100644 --- a/webapp/backend/pkg/notify/notify.go +++ b/webapp/backend/pkg/notify/notify.go @@ -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{} diff --git a/webapp/backend/pkg/web/handler/upload_device_metrics.go b/webapp/backend/pkg/web/handler/upload_device_metrics.go index d94bd05..2024b07 100644 --- a/webapp/backend/pkg/web/handler/upload_device_metrics.go +++ b/webapp/backend/pkg/web/handler/upload_device_metrics.go @@ -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. } diff --git a/webapp/backend/pkg/web/server_test.go b/webapp/backend/pkg/web/server_test.go index b4821db..9892424 100644 --- a/webapp/backend/pkg/web/server_test.go +++ b/webapp/backend/pkg/web/server_test.go @@ -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{