From cc29c9b7dbb318692c6de3577d9ac180a69e87b6 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 16 Dec 2021 15:51:04 +0000 Subject: [PATCH 1/3] Delete statping_emailer.go Remove Notifier as it's broken. --- notifiers/statping_emailer.go | 106 ---------------------------------- 1 file changed, 106 deletions(-) delete mode 100644 notifiers/statping_emailer.go diff --git a/notifiers/statping_emailer.go b/notifiers/statping_emailer.go deleted file mode 100644 index c6026c0e..00000000 --- a/notifiers/statping_emailer.go +++ /dev/null @@ -1,106 +0,0 @@ -package notifiers - -import ( - "bytes" - "encoding/json" - "github.com/statping-ng/statping-ng/types/core" - "github.com/statping-ng/statping-ng/types/failures" - "github.com/statping-ng/statping-ng/types/notifications" - "github.com/statping-ng/statping-ng/types/notifier" - "github.com/statping-ng/statping-ng/types/services" - "github.com/statping-ng/statping-ng/utils" - "time" -) - -var _ notifier.Notifier = (*statpingEmailer)(nil) - -const ( - statpingEmailerName = "statping_emailer" - statpingEmailerHost = "https://news.statping.com" -) - -type statpingEmailer struct { - *notifications.Notification -} - -func (s *statpingEmailer) Select() *notifications.Notification { - return s.Notification -} - -func (s *statpingEmailer) Valid(values notifications.Values) error { - return nil -} - -var statpingMailer = &statpingEmailer{¬ifications.Notification{ - Method: statpingEmailerName, - Title: "Email", - Description: "Send an email when a service becomes offline or back online using Statping's email service. You will need to verify your email address.", - Author: "Hunter Long", - AuthorUrl: "https://github.com/hunterlong", - Delay: time.Duration(10 * time.Second), - Icon: "fas envelope-square", - Limits: 60, - Form: []notifications.NotificationForm{{ - Type: "email", - Title: "Send to Email Address", - Placeholder: "info@statping.com", - DbField: "Host", - Required: true, - }}}, -} - -// Send will send a HTTP Post to the slack webhooker API. It accepts type: string -func (s *statpingEmailer) sendStatpingEmail(msg statpingMail) (string, error) { - data, _ := json.Marshal(msg) - resp, _, err := utils.HttpRequest(statpingEmailerHost+"/notifier", "POST", "application/json", nil, bytes.NewBuffer(data), time.Duration(10*time.Second), true, nil) - if err != nil { - return "", err - } - return string(resp), nil -} - -func (s *statpingEmailer) OnTest() (string, error) { - return "", nil -} - -type statpingMail struct { - Email string `json:"email"` - Core core.Core `json:"core,omitempty"` - Service services.Service `json:"service,omitempty"` - Failure failures.Failure `json:"failure,omitempty"` -} - -// OnFailure will trigger failing service -func (s *statpingEmailer) OnFailure(srv services.Service, f failures.Failure) (string, error) { - ee := statpingMail{ - Email: s.Host.String, - Core: *core.App, - Service: srv, - Failure: f, - } - return s.sendStatpingEmail(ee) -} - -// OnSuccess will trigger successful service -func (s *statpingEmailer) OnSuccess(srv services.Service) (string, error) { - ee := statpingMail{ - Email: s.Host.String, - Core: *core.App, - Service: srv, - Failure: failures.Failure{}, - } - return s.sendStatpingEmail(ee) -} - -// OnSave will trigger when this notifier is saved -func (s *statpingEmailer) OnSave() (string, error) { - ee := statpingMail{ - Email: s.Host.String, - Core: *core.App, - Service: services.Service{}, - Failure: failures.Failure{}, - } - out, err := s.sendStatpingEmail(ee) - log.Println("statping emailer response", out) - return out, err -} From 4c1eaea964009268c5e3152124a590b0a306267d Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 16 Dec 2021 15:51:15 +0000 Subject: [PATCH 2/3] Delete statping_emailer_test.go Remove Notifier test as it's broken. --- notifiers/statping_emailer_test.go | 70 ------------------------------ 1 file changed, 70 deletions(-) delete mode 100644 notifiers/statping_emailer_test.go diff --git a/notifiers/statping_emailer_test.go b/notifiers/statping_emailer_test.go deleted file mode 100644 index 4c72b3f9..00000000 --- a/notifiers/statping_emailer_test.go +++ /dev/null @@ -1,70 +0,0 @@ -package notifiers - -import ( - "github.com/statping-ng/statping-ng/database" - "github.com/statping-ng/statping-ng/types/core" - "github.com/statping-ng/statping-ng/types/failures" - "github.com/statping-ng/statping-ng/types/notifications" - "github.com/statping-ng/statping-ng/types/null" - "github.com/statping-ng/statping-ng/types/services" - "github.com/statping-ng/statping-ng/utils" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "testing" - "time" -) - -var ( - testEmail string -) - -func TestStatpingEmailerNotifier(t *testing.T) { - err := utils.InitLogs() - require.Nil(t, err) - - t.Parallel() - db, err := database.OpenTester() - require.Nil(t, err) - db.AutoMigrate(¬ifications.Notification{}) - notifications.SetDB(db) - core.Example() - - testEmail = utils.Params.GetString("TEST_EMAIL") - statpingMailer.Host = null.NewNullString(testEmail) - statpingMailer.Enabled = null.NewNullBool(true) - - if testEmail == "" { - t.Log("statping email notifier testing skipped, missing TEST_EMAIL environment variable") - t.SkipNow() - } - - t.Run("Load statping emailer", func(t *testing.T) { - statpingMailer.Host = null.NewNullString(testEmail) - statpingMailer.Delay = time.Duration(100 * time.Millisecond) - statpingMailer.Limits = 3 - Add(statpingMailer) - assert.Equal(t, "Hunter Long", statpingMailer.Author) - assert.Equal(t, testEmail, statpingMailer.Host.String) - }) - - t.Run("statping emailer Within Limits", func(t *testing.T) { - ok := statpingMailer.CanSend() - assert.True(t, ok) - }) - - t.Run("statping emailer OnSave", func(t *testing.T) { - _, err := statpingMailer.OnSave() - assert.Nil(t, err) - }) - - t.Run("statping emailer OnFailure", func(t *testing.T) { - _, err := statpingMailer.OnFailure(services.Example(false), failures.Example()) - assert.Nil(t, err) - }) - - t.Run("statping emailer OnSuccess", func(t *testing.T) { - _, err := statpingMailer.OnSuccess(services.Example(true)) - assert.Nil(t, err) - }) - -} From 980612ecdd782097716d7d5de2ba9d83c2233255 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 16 Dec 2021 15:52:21 +0000 Subject: [PATCH 3/3] Update postman.json Remove Notifier test as it's broken. --- dev/postman.json | 52 +----------------------------------------------- 1 file changed, 1 insertion(+), 51 deletions(-) diff --git a/dev/postman.json b/dev/postman.json index 3e2f60ff..cd061232 100644 --- a/dev/postman.json +++ b/dev/postman.json @@ -4205,7 +4205,7 @@ "", "pm.test(\"View All Notifiers\", function () {", " var jsonData = pm.response.json();", - " pm.expect(jsonData.length).to.eql(14);", + " pm.expect(jsonData.length).to.eql(13);", "});" ], "type": "text/javascript" @@ -4598,56 +4598,6 @@ "body": "{\n \"success\": true,\n \"response\": \"There's been a glitch… | Slack

There’s been a glitch…

We’re not quite sure what went wrong. You can go back, or try looking on our Help Center if you need a hand.

\\n\\n\\n\\n\"\n}" } ] - }, - { - "name": "Statping Emailer", - "event": [ - { - "listen": "test", - "script": { - "id": "00f5c79e-e927-4305-b276-265b4d51b1e1", - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "auth": { - "type": "noauth" - }, - "method": "POST", - "header": [ - { - "key": "Content-Type", - "name": "Content-Type", - "type": "text", - "value": "application/json" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"email\": \"info@socialeck.com\",\n \"core\": {\n \"allow_reports\": true,\n \"created_at\": \"2020-06-21T05:00:12.735144154Z\",\n \"description\": \"This status page has sample data included\",\n \"domain\": \"http://localhost:8080\",\n \"footer\": null,\n \"language\": \"en\",\n \"migration_id\": 1592715612,\n \"name\": \"Statping Sample Data\",\n \"setup\": true,\n \"started_on\": \"2020-06-21T05:01:01.406134998Z\",\n \"updated_at\": \"2020-06-21T05:00:59.652965634Z\",\n \"using_cdn\": false,\n \"version\": \"0.90.54\"\n },\n \"service\": {\n \"name\": \"Statping Website\",\n \"domain\": \"https://statping.com\",\n \"last_error\": \"2020-06-21T01:01:01.406134998Z\",\n \"last_success\": \"2020-06-21T05:01:01.406134998Z\",\n \"expected\": \"\",\n \"online\": true,\n \"expected_status\": 200,\n \"check_interval\": 30,\n \"type\": \"http\",\n \"method\": \"GET\",\n \"post_data\": \"\",\n \"port\": 0,\n \"timeout\": 30,\n \"order_id\": 0\n },\n \"failure\": {\n \"created_at\": \"2020-06-21T05:01:00.67942464Z\",\n \"error_code\": 406,\n \"id\": 1613,\n \"issue\": \"HTTP Status Code 406 did not match 200\",\n \"method_id\": 0,\n \"ping\": 10889\n }\n}", - "options": { - "raw": {} - } - }, - "url": { - "raw": "https://news.statping.com/notifier", - "protocol": "https", - "host": [ - "news", - "statping", - "com" - ], - "path": [ - "notifier" - ] - }, - "description": "This endpoint will send emails from our servers rather than you using your own SMTP email settings. Once you save the Statping Emailer Notifier, we will send you a verification email. Once you've confirmed your email address you will recieve emails whenever your service status changes." - }, - "response": [] } ], "description": "Statping contains multiple notifiers that will send you a notification whenever a service become offline, or online. You can create your own 3rd party notifier by reading more on the [Notifiers Wiki](https://github.com/statping-ng/statping-ng/wiki/Notifiers) on the Github repo.",