Add Email, Mobile and Discord Online Messages

pull/258/head
Emanuel Bennici 2019-10-04 15:36:45 +02:00
parent c9f140f2dc
commit df3eb914ed
No known key found for this signature in database
GPG Key ID: 17FA2D56BAD01661
3 changed files with 26 additions and 3 deletions

View File

@ -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"
@ -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)
}
}

View File

@ -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"
@ -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,

View File

@ -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"
@ -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,