mirror of https://github.com/statping/statping
notifiers - split interfaces/packages
parent
4ce7ca7530
commit
949ba3958a
|
@ -1,5 +1,5 @@
|
|||
.idea
|
||||
rice-box.go
|
||||
./rice-box.go
|
||||
config.yml
|
||||
statup.db
|
||||
plugins/*.so
|
||||
|
|
|
@ -18,7 +18,7 @@ services:
|
|||
|
||||
env:
|
||||
global:
|
||||
- VERSION=0.29.9
|
||||
- VERSION=0.30
|
||||
- DB_HOST=localhost
|
||||
- DB_USER=travis
|
||||
- DB_PASS=
|
||||
|
|
|
@ -95,8 +95,8 @@ func CreateAllAssets() {
|
|||
utils.Log(1, "Inserting scss, css, emails, and javascript files into assets..")
|
||||
CopyToPublic(ScssBox, "scss", "base.scss")
|
||||
CopyToPublic(ScssBox, "scss", "variables.scss")
|
||||
CopyToPublic(EmailBox, "emails", "message.html")
|
||||
CopyToPublic(EmailBox, "emails", "failure.html")
|
||||
//CopyToPublic(EmailBox, "emails", "message.html")
|
||||
//CopyToPublic(EmailBox, "emails", "failure.html")
|
||||
CopyToPublic(CssBox, "css", "bootstrap.min.css")
|
||||
CopyToPublic(JsBox, "js", "bootstrap.min.js")
|
||||
CopyToPublic(JsBox, "js", "Chart.bundle.min.js")
|
||||
|
|
|
@ -42,7 +42,6 @@ var (
|
|||
ScssBox *rice.Box
|
||||
JsBox *rice.Box
|
||||
TmplBox *rice.Box
|
||||
EmailBox *rice.Box
|
||||
SetupMode bool
|
||||
UsingAssets bool
|
||||
VERSION string
|
||||
|
|
1
main.go
1
main.go
|
@ -50,7 +50,6 @@ func RenderBoxes() {
|
|||
core.ScssBox = rice.MustFindBox("source/scss")
|
||||
core.JsBox = rice.MustFindBox("source/js")
|
||||
core.TmplBox = rice.MustFindBox("source/tmpl")
|
||||
core.EmailBox = rice.MustFindBox("source/emails")
|
||||
}
|
||||
|
||||
func LoadDotEnvs() {
|
||||
|
|
|
@ -21,11 +21,12 @@ var (
|
|||
emailer *Email
|
||||
emailArray []string
|
||||
emailQueue []*types.Email
|
||||
emailBox *rice.Box
|
||||
mailer *gomail.Dialer
|
||||
)
|
||||
|
||||
type Email struct {
|
||||
*Notification
|
||||
mailer *gomail.Dialer
|
||||
}
|
||||
|
||||
// DEFINE YOUR NOTIFICATION HERE.
|
||||
|
@ -84,7 +85,9 @@ func (u *Email) Select() *Notification {
|
|||
|
||||
// WHEN NOTIFIER LOADS
|
||||
func (u *Email) Init() error {
|
||||
emailBox = rice.MustFindBox("emails")
|
||||
err := u.Install()
|
||||
utils.Log(1, fmt.Sprintf("Creating Mailer: %v:%v", u.Notification.Host, u.Notification.Port))
|
||||
|
||||
if err == nil {
|
||||
notifier, _ := SelectNotification(u.Id)
|
||||
|
@ -94,29 +97,33 @@ func (u *Email) Init() error {
|
|||
if u.Enabled {
|
||||
|
||||
utils.Log(1, fmt.Sprintf("Loading SMTP Emailer using host: %v:%v", u.Notification.Host, u.Notification.Port))
|
||||
u.mailer = gomail.NewDialer(u.Notification.Host, u.Notification.Port, u.Notification.Username, u.Notification.Password)
|
||||
u.mailer.TLSConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
mailer = gomail.NewDialer(u.Notification.Host, u.Notification.Port, u.Notification.Username, u.Notification.Password)
|
||||
mailer.TLSConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
|
||||
go u.Run()
|
||||
}
|
||||
}
|
||||
|
||||
//go u.Run()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *Email) Test() error {
|
||||
//email := &types.Email{
|
||||
// To: "info@socialeck.com",
|
||||
// Subject: "Test Email",
|
||||
// Template: "message.html",
|
||||
// Data: nil,
|
||||
// From: emailer.Var1,
|
||||
//}
|
||||
//SendEmail(core.EmailBox, email)
|
||||
if u.Enabled {
|
||||
email := &types.Email{
|
||||
To: "info@socialeck.com",
|
||||
Subject: "Test Email",
|
||||
Template: "message.html",
|
||||
Data: nil,
|
||||
From: emailer.Var1,
|
||||
}
|
||||
SendEmail(emailBox, email)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type emailMessage struct {
|
||||
Service *types.Service
|
||||
}
|
||||
|
||||
// AFTER NOTIFIER LOADS, IF ENABLED, START A QUEUE PROCESS
|
||||
func (u *Email) Run() error {
|
||||
var sentAddresses []string
|
||||
|
@ -146,8 +153,20 @@ func (u *Email) Run() error {
|
|||
// ON SERVICE FAILURE, DO YOUR OWN FUNCTIONS
|
||||
func (u *Email) OnFailure(s *types.Service) error {
|
||||
if u.Enabled {
|
||||
utils.Log(1, fmt.Sprintf("Notification %v is receiving a failure notification.", u.Method))
|
||||
// Do failing stuff here!
|
||||
|
||||
msg := emailMessage{
|
||||
Service: s,
|
||||
}
|
||||
|
||||
email := &types.Email{
|
||||
To: "info@socialeck.com",
|
||||
Subject: fmt.Sprintf("Service %v is Failing", s.Name),
|
||||
Template: "failure.html",
|
||||
Data: msg,
|
||||
From: emailer.Var1,
|
||||
}
|
||||
SendEmail(emailBox, email)
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -155,8 +174,7 @@ func (u *Email) OnFailure(s *types.Service) error {
|
|||
// ON SERVICE SUCCESS, DO YOUR OWN FUNCTIONS
|
||||
func (u *Email) OnSuccess(s *types.Service) error {
|
||||
if u.Enabled {
|
||||
utils.Log(1, fmt.Sprintf("Notification %v is receiving a failure notification.", u.Method))
|
||||
// Do failing stuff here!
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -172,6 +190,9 @@ func (u *Email) OnSave() error {
|
|||
|
||||
// ON SERVICE FAILURE, DO YOUR OWN FUNCTIONS
|
||||
func (u *Email) Install() error {
|
||||
|
||||
fmt.Println("installing emailer")
|
||||
|
||||
inDb, err := emailer.Notification.isInDatabase()
|
||||
if !inDb {
|
||||
newNotifer, err := InsertDatabase(u.Notification)
|
||||
|
@ -185,12 +206,13 @@ func (u *Email) Install() error {
|
|||
}
|
||||
|
||||
func (u *Email) dialSend(email *types.Email) error {
|
||||
fmt.Println("sending dailsend to emailer")
|
||||
m := gomail.NewMessage()
|
||||
m.SetHeader("From", email.From)
|
||||
m.SetHeader("To", email.To)
|
||||
m.SetHeader("Subject", email.Subject)
|
||||
m.SetBody("text/html", email.Source)
|
||||
if err := u.mailer.DialAndSend(m); err != nil {
|
||||
if err := mailer.DialAndSend(m); err != nil {
|
||||
utils.Log(3, fmt.Sprintf("Email '%v' sent to: %v using the %v template (size: %v) %v", email.Subject, email.To, email.Template, len([]byte(email.Source)), err))
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -50,15 +50,13 @@
|
|||
|
||||
<table class="body-sub" style="border-top-color: #EDEFF2; border-top-style: solid; border-top-width: 1px; box-sizing: border-box; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; margin-top: 25px; padding-top: 25px;">
|
||||
<td style="box-sizing: border-box; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; word-break: break-word;">
|
||||
<a href="{{.Domain}}/service/{{.Service.Id}}" class="button button--blue" target="_blank" style="-webkit-text-size-adjust: none; background: #3869D4; border-color: #3869d4; border-radius: 3px; border-style: solid; border-width: 10px 18px; box-shadow: 0 2px 3px rgba(0, 0, 0, 0.16); box-sizing: border-box; color: #FFF; display: inline-block; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; text-decoration: none;">View Service</a>
|
||||
<a href="/service/{{.Service.Id}}" class="button button--blue" target="_blank" style="-webkit-text-size-adjust: none; background: #3869D4; border-color: #3869d4; border-radius: 3px; border-style: solid; border-width: 10px 18px; box-shadow: 0 2px 3px rgba(0, 0, 0, 0.16); box-sizing: border-box; color: #FFF; display: inline-block; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; text-decoration: none;">View Service</a>
|
||||
</td>
|
||||
<td style="box-sizing: border-box; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; word-break: break-word;">
|
||||
<a href="{{.Domain}}/dashboard" class="button button--blue" target="_blank" style="-webkit-text-size-adjust: none; background: #3869D4; border-color: #3869d4; border-radius: 3px; border-style: solid; border-width: 10px 18px; box-shadow: 0 2px 3px rgba(0, 0, 0, 0.16); box-sizing: border-box; color: #FFF; display: inline-block; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; text-decoration: none;">Statup Dashboard</a>
|
||||
<a href="/dashboard" class="button button--blue" target="_blank" style="-webkit-text-size-adjust: none; background: #3869D4; border-color: #3869d4; border-radius: 3px; border-style: solid; border-width: 10px 18px; box-shadow: 0 2px 3px rgba(0, 0, 0, 0.16); box-sizing: border-box; color: #FFF; display: inline-block; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; text-decoration: none;">Statup Dashboard</a>
|
||||
</td>
|
||||
</table>
|
||||
</td>
|
||||
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
|
@ -169,7 +169,7 @@ func uniqueStrings(elements []string) []string {
|
|||
// Scan slice for a previous element of the same value.
|
||||
exists := false
|
||||
for v := 0; v < i; v++ {
|
||||
if elements[v][:10] == elements[i][:10] {
|
||||
if elements[v] == elements[i] {
|
||||
exists = true
|
||||
break
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -14,8 +14,8 @@ import (
|
|||
const (
|
||||
SLACK_ID = 2
|
||||
SLACK_METHOD = "slack"
|
||||
FAILING_TEMPLATE = `{ "attachments": [ { "fallback": "Service {{.Service.Name}} - is currently failing", "text": "<{{.Service.Domain}}|{{.Service.Name}}> - Your Statup service '{{.Service.Name}}' has just received a Failure notification with a HTTP Status code of {{.Service.LastStatusCode}}.", "fields": [ { "title": "Expected", "value": "{{.Service.Expected}}", "short": true }, { "title": "Status Code", "value": "{{.Service.LastStatusCode}}", "short": true } ], "color": "#FF0000", "thumb_url": "https://statup.io", "footer": "Statup", "footer_icon": "https://img.cjx.io/statuplogo32.png", "ts": {{.Time}} } ] }`
|
||||
SUCCESS_TEMPLATE = `{ "attachments": [ { "fallback": "Service {{.Service.Name}} - is now back online", "text": "<{{.Service.Domain}}|{{.Service.Name}}> - Your Statup service '{{.Service.Name}}' has just received a Failure notification.", "fields": [ { "title": "Issue", "value": "Awesome Project", "short": true }, { "title": "Status Code", "value": "{{.Service.LastStatusCode}}", "short": true } ], "color": "#00FF00", "thumb_url": "https://statup.io", "footer": "Statup", "footer_icon": "https://img.cjx.io/statuplogo32.png", "ts": {{.Time}} } ] }`
|
||||
FAILING_TEMPLATE = `{ "attachments": [ { "fallback": "Service {{.Service.Name}} - is currently failing", "text": "<{{.Service.Domain}}|{{.Service.Name}}> - Your Statup service '{{.Service.Name}}' has just received a Failure notification with a HTTP Status code of {{.Service.LastStatusCode}}.", "fields": [ { "title": "Expected", "value": "{{.Service.Expected}}", "short": true }, { "title": "Status Code", "value": "{{.Service.LastStatusCode}}", "short": true } ], "color": "#FF0000", "thumb_url": "https://statup.io", "footer": "Statup", "footer_icon": "https://img.cjx.io/statuplogo32.png" } ] }`
|
||||
SUCCESS_TEMPLATE = `{ "attachments": [ { "fallback": "Service {{.Service.Name}} - is now back online", "text": "<{{.Service.Domain}}|{{.Service.Name}}> - Your Statup service '{{.Service.Name}}' has just received a Failure notification.", "fields": [ { "title": "Issue", "value": "Awesome Project", "short": true }, { "title": "Status Code", "value": "{{.Service.LastStatusCode}}", "short": true } ], "color": "#00FF00", "thumb_url": "https://statup.io", "footer": "Statup", "footer_icon": "https://img.cjx.io/statuplogo32.png" } ] }`
|
||||
TEST_TEMPLATE = `{"text":"{{.}}"}`
|
||||
)
|
||||
|
||||
|
@ -90,9 +90,8 @@ func (u *Slack) Run() error {
|
|||
if err != nil {
|
||||
utils.Log(3, fmt.Sprintf("Issue sending Slack notification: %v", err))
|
||||
}
|
||||
|
||||
fmt.Println(msg)
|
||||
}
|
||||
slackMessages = []string{}
|
||||
messageLock.Unlock()
|
||||
time.Sleep(60 * time.Second)
|
||||
if u.Enabled {
|
||||
|
@ -115,13 +114,10 @@ func SendSlack(temp string, data interface{}) error {
|
|||
// ON SERVICE FAILURE, DO YOUR OWN FUNCTIONS
|
||||
func (u *Slack) OnFailure(s *types.Service) error {
|
||||
if u.Enabled {
|
||||
// Do failing stuff here!
|
||||
|
||||
message := slackMessage{
|
||||
Service: s,
|
||||
Time: time.Now().Unix(),
|
||||
}
|
||||
|
||||
SendSlack(FAILING_TEMPLATE, message)
|
||||
}
|
||||
return nil
|
||||
|
@ -130,8 +126,11 @@ func (u *Slack) OnFailure(s *types.Service) error {
|
|||
// ON SERVICE SUCCESS, DO YOUR OWN FUNCTIONS
|
||||
func (u *Slack) OnSuccess(s *types.Service) error {
|
||||
if u.Enabled {
|
||||
SendSlack(SUCCESS_TEMPLATE, s)
|
||||
// Do checking or any successful things here
|
||||
//message := slackMessage{
|
||||
// Service: s,
|
||||
// Time: time.Now().Unix(),
|
||||
//}
|
||||
//SendSlack(SUCCESS_TEMPLATE, message)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue