mirror of https://github.com/statping/statping
Merge pull request #83 from adamboutcher/remove_email
Remove statping emailer - NOT SMTPpull/1081/head
commit
e70df4b22f
File diff suppressed because one or more lines are too long
|
@ -36,7 +36,6 @@ func InitNotifiers() {
|
|||
Webhook,
|
||||
Mobile,
|
||||
Pushover,
|
||||
statpingMailer,
|
||||
Gotify,
|
||||
AmazonSNS,
|
||||
)
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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)
|
||||
})
|
||||
|
||||
}
|
Loading…
Reference in New Issue