Skip to content

Commit

Permalink
Add Email, Mobile and Discord Online Messages
Browse files Browse the repository at this point in the history
  • Loading branch information
l0nax committed Oct 4, 2019
1 parent c9f140f commit df3eb91
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
9 changes: 8 additions & 1 deletion notifiers/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"github.com/hunterlong/statping/core/notifier"
"github.com/hunterlong/statping/core"
"github.com/hunterlong/statping/types"
"github.com/hunterlong/statping/utils"
"strings"
Expand Down Expand Up @@ -77,7 +78,13 @@ func (u *discord) OnFailure(s *types.Service, f *types.Failure) {
func (u *discord) OnSuccess(s *types.Service) {
if !s.Online {
u.ResetUniqueQueue(fmt.Sprintf("service_%v", s.Id))
msg := fmt.Sprintf(`{"content": "Your service '%v' is back online!"}`, s.Name)
var msg interface{}
if core.CoreApp.UpdateNotify.Bool {
msg = fmt.Sprintf(`{"content": "%s"}`, core.ReturnService(s).SmallText())
} else {
msg = fmt.Sprintf(`{"content": "Your service '%v' is back online!"}`, s.Name)
}

u.AddQueue(fmt.Sprintf("service_%v", s.Id), msg)
}
}
Expand Down
10 changes: 9 additions & 1 deletion notifiers/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"crypto/tls"
"fmt"
"github.com/go-mail/mail"
"github.com/hunterlong/statping/core"
"github.com/hunterlong/statping/core/notifier"
"github.com/hunterlong/statping/types"
"github.com/hunterlong/statping/utils"
Expand Down Expand Up @@ -199,10 +200,17 @@ func (u *email) OnFailure(s *types.Service, f *types.Failure) {
// OnSuccess will trigger successful service
func (u *email) OnSuccess(s *types.Service) {
if !s.Online {
var msg string
if core.CoreApp.UpdateNotify.Bool {
msg = core.ReturnService(s).SmallText()
} else {
msg = fmt.Sprintf("Service %v is Back Online", s.Name)
}

u.ResetUniqueQueue(fmt.Sprintf("service_%v", s.Id))
email := &emailOutgoing{
To: u.Var2,
Subject: fmt.Sprintf("Service %v is Back Online", s.Name),
Subject: msg,
Template: mainEmailTemplate,
Data: interface{}(s),
From: u.Var1,
Expand Down
10 changes: 9 additions & 1 deletion notifiers/mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/hunterlong/statping/core"
"github.com/hunterlong/statping/core/notifier"
"github.com/hunterlong/statping/types"
"github.com/hunterlong/statping/utils"
Expand Down Expand Up @@ -106,9 +107,16 @@ func (u *mobilePush) OnFailure(s *types.Service, f *types.Failure) {
func (u *mobilePush) OnSuccess(s *types.Service) {
data := dataJson(s, nil)
if !s.Online {
var msgStr string
if core.CoreApp.UpdateNotify.Bool {
msgStr = core.ReturnService(s).SmallText()
} else {
msgStr = fmt.Sprintf("Your Service %v is Back Online", s.Name)
}

u.ResetUniqueQueue(fmt.Sprintf("service_%v", s.Id))
msg := &pushArray{
Message: fmt.Sprintf("Your service '%v' is back online!", s.Name),
Message: msgStr,
Title: "Service Online",
Topic: mobileIdentifier,
Data: data,
Expand Down

0 comments on commit df3eb91

Please sign in to comment.