pull/271/head
Hunter Long 2019-10-25 08:13:32 -07:00
parent 2fd1332906
commit 8aa2dba41c
25 changed files with 289 additions and 404 deletions

View File

@ -20,7 +20,6 @@ import (
"fmt"
"github.com/hunterlong/statping/core"
"github.com/hunterlong/statping/handlers"
_ "github.com/hunterlong/statping/notifiers"
"github.com/hunterlong/statping/plugin"
"github.com/hunterlong/statping/source"
"github.com/hunterlong/statping/utils"
@ -119,11 +118,3 @@ func mainProcess() {
os.Exit(1)
}
}
func ForEachPlugin() {
if len(core.CoreApp.Plugins) > 0 {
//for _, p := range core.Plugins {
// p.OnShutdown()
//}
}
}

View File

@ -19,6 +19,7 @@ import (
"errors"
"fmt"
"github.com/hunterlong/statping/core/notifier"
"github.com/hunterlong/statping/notifiers"
"github.com/hunterlong/statping/source"
"github.com/hunterlong/statping/types"
"github.com/hunterlong/statping/utils"
@ -64,7 +65,8 @@ func InitApp() {
InsertNotifierDB()
CoreApp.SelectAllServices(true)
checkServices()
CoreApp.Notifications = notifier.Load()
AttachNotifiers()
CoreApp.Notifications = notifier.AllCommunications
go DatabaseMaintence()
}
@ -177,6 +179,21 @@ func GetLocalIP() string {
return "http://localhost"
}
// AttachNotifiers will attach all the notifier's into the system
func AttachNotifiers() error {
return notifier.AddNotifiers(
notifiers.Command,
notifiers.Discorder,
notifiers.Emailer,
notifiers.LineNotify,
notifiers.Mobile,
notifiers.Slacker,
notifiers.Telegram,
notifiers.Twilio,
notifiers.Webhook,
)
}
// ServiceOrder will reorder the services based on 'order_id' (Order)
type ServiceOrder []types.ServiceInterface

View File

@ -25,7 +25,7 @@ var (
)
func checkNotifierForm(n Notifier) error {
notifier := asNotification(n)
notifier := n.Select()
for _, f := range notifier.Form {
contains := contains(f.DbField, allowedVars)
if !contains {

View File

@ -54,7 +54,7 @@ sendMessages:
for _, comm := range AllCommunications {
if isType(comm, new(BasicEvents)) && isEnabled(comm) && (s.Online || inLimits(comm)) {
notifier := comm.(Notifier).Select()
utils.Log(1, fmt.Sprintf("Sending failure %v notification for service %v", notifier.Method, s.Name))
utils.Log(1, fmt.Sprintf("Sending [OnFailure] '%v' notification for service %v", notifier.Method, s.Name))
comm.(BasicEvents).OnFailure(s, f)
}
}
@ -74,7 +74,7 @@ func OnSuccess(s *types.Service) {
for _, comm := range AllCommunications {
if isType(comm, new(BasicEvents)) && isEnabled(comm) && (!s.Online || inLimits(comm)) {
notifier := comm.(Notifier).Select()
utils.Log(1, fmt.Sprintf("Sending successful %v notification for service %v", notifier.Method, s.Name))
utils.Log(1, fmt.Sprintf("Sending [OnSuccess] '%v' notification for service %v", notifier.Method, s.Name))
comm.(BasicEvents).OnSuccess(s)
}
}

View File

@ -18,6 +18,7 @@ package notifier
import (
"errors"
"fmt"
c "github.com/hunterlong/statping/core"
"github.com/hunterlong/statping/types"
"time"
)
@ -83,7 +84,7 @@ var example = &ExampleNotifier{&Notification{
// init will be ran when Statping is loaded, AddNotifier will add the notifier instance to the system
func init() {
AddNotifier(example)
c.AttachNotifiers()
}
// Send is the main function to hold your notifier functionality
@ -209,14 +210,14 @@ func ExampleNotification() {
}}
// AddNotifier accepts a Notifier to load into the Statping Notification system
err := AddNotifier(example)
err := AddNotifiers(example)
fmt.Println(err)
// Output: <nil>
}
// Add a Notifier to the AddQueue function to insert it into the system
func ExampleAddNotifier() {
err := AddNotifier(example)
err := AddNotifiers(example)
fmt.Println(err)
// Output: <nil>
}

View File

@ -102,6 +102,7 @@ func (n *Notification) AfterFind() (err error) {
func (n *Notification) AddQueue(uid string, msg interface{}) {
data := &QueueData{uid, msg}
n.Queue = append(n.Queue, data)
utils.Log(0, fmt.Sprintf("Notifier '%v' added new item (%v) to the queue. (%v queued)", n.Method, uid, len(n.Queue)))
}
// CanTest returns true if the notifier implements the OnTest interface
@ -126,29 +127,21 @@ func asNotification(n Notifier) *Notification {
}
// AddNotifier accept a Notifier interface to be added into the array
func AddNotifier(n Notifier) error {
if isType(n, new(Notifier)) {
err := checkNotifierForm(n)
if err != nil {
return err
func AddNotifiers(notifiers ...Notifier) error {
for _, n := range notifiers {
if isType(n, new(Notifier)) {
err := checkNotifierForm(n)
if err != nil {
return err
}
AllCommunications = append(AllCommunications, n)
Init(n)
} else {
return errors.New("notifier does not have the required methods")
}
AllCommunications = append(AllCommunications, n)
} else {
return errors.New("notifier does not have the required methods")
}
return nil
}
// Load is called by core to add all the notifier into memory
func Load() []types.AllNotifiers {
var notifiers []types.AllNotifiers
for _, comm := range AllCommunications {
n := comm.(Notifier)
Init(n)
notifiers = append(notifiers, n)
}
startAllNotifiers()
return notifiers
return nil
}
// normalizeType will accept multiple interfaces and converts it into a string for logging
@ -179,7 +172,6 @@ func (n *Notification) makeLog(msg interface{}) {
Time: utils.Timestamp(time.Now()),
Timestamp: time.Now(),
}
utils.Log(1, fmt.Sprintf("Notifier %v has sent a message %v", n.Method, log.Message))
n.logs = append(n.logs, log)
}
@ -297,7 +289,9 @@ CheckNotifier:
msg := notification.Queue[0]
err := n.Send(msg.Data)
if err != nil {
utils.Log(2, fmt.Sprintf("notifier %v had an error: %v", notification.Method, err))
utils.Log(2, fmt.Sprintf("Notifier '%v' had an error: %v", notification.Method, err))
} else {
utils.Log(1, fmt.Sprintf("Notifier '%v' sent outgoing message (%v) %v left in queue.", notification.Method, msg.Id, len(notification.Queue)))
}
notification.makeLog(msg.Data)
if len(notification.Queue) > 1 {

View File

@ -79,11 +79,6 @@ func TestIsBasicType(t *testing.T) {
assert.True(t, isType(example, new(Tester)))
}
func TestLoad(t *testing.T) {
notifiers := Load()
assert.Equal(t, 1, len(notifiers))
}
func TestIsInDatabase(t *testing.T) {
in := isInDatabase(example.Notification)
assert.True(t, in)

View File

@ -27,10 +27,10 @@ type commandLine struct {
*notifier.Notification
}
var command = &commandLine{&notifier.Notification{
Method: "command",
var Command = &commandLine{&notifier.Notification{
Method: "Command",
Title: "Shell Command",
Description: "Shell Command allows you to run a customized shell/bash command on the local machine it's running on.",
Description: "Shell Command allows you to run a customized shell/bash Command on the local machine it's running on.",
Author: "Hunter Long",
AuthorUrl: "https://github.com/hunterlong",
Delay: time.Duration(1 * time.Second),
@ -47,24 +47,16 @@ var command = &commandLine{&notifier.Notification{
Title: "Command to Run on OnSuccess",
Placeholder: "curl google.com",
DbField: "var1",
SmallText: "This command will run every time a service is receiving a Successful event.",
SmallText: "This Command will run every time a service is receiving a Successful event.",
}, {
Type: "text",
Title: "Command to Run on OnFailure",
Placeholder: "curl offline.com",
DbField: "var2",
SmallText: "This command will run every time a service is receiving a Failing event.",
SmallText: "This Command will run every time a service is receiving a Failing event.",
}}},
}
// init the command notifier
func init() {
err := notifier.AddNotifier(command)
if err != nil {
panic(err)
}
}
func runCommand(app, cmd string) (string, string, error) {
outStr, errStr, err := utils.Command(cmd)
return outStr, errStr, err
@ -102,7 +94,7 @@ func (u *commandLine) OnTest() error {
return err
}
// Send for commandLine will send message to expo command push notifications endpoint
// Send for commandLine will send message to expo Command push notifications endpoint
func (u *commandLine) Send(msg interface{}) error {
cmd := msg.(string)
_, _, err := runCommand(u.Host, cmd)

View File

@ -28,79 +28,75 @@ const (
func TestCommandNotifier(t *testing.T) {
t.Parallel()
command.Host = "sh"
command.Var1 = commandTest
command.Var2 = commandTest
Command.Host = "sh"
Command.Var1 = commandTest
Command.Var2 = commandTest
currentCount = CountNotifiers()
t.Run("Load command", func(t *testing.T) {
command.Host = "sh"
command.Var1 = commandTest
command.Var2 = commandTest
command.Delay = time.Duration(100 * time.Millisecond)
command.Limits = 99
err := notifier.AddNotifier(command)
t.Run("Load Command", func(t *testing.T) {
Command.Host = "sh"
Command.Var1 = commandTest
Command.Var2 = commandTest
Command.Delay = time.Duration(100 * time.Millisecond)
Command.Limits = 99
err := notifier.AddNotifiers(Command)
assert.Nil(t, err)
assert.Equal(t, "Hunter Long", command.Author)
assert.Equal(t, "sh", command.Host)
assert.Equal(t, commandTest, command.Var1)
assert.Equal(t, commandTest, command.Var2)
assert.Equal(t, "Hunter Long", Command.Author)
assert.Equal(t, "sh", Command.Host)
assert.Equal(t, commandTest, Command.Var1)
assert.Equal(t, commandTest, Command.Var2)
})
t.Run("Load command Notifier", func(t *testing.T) {
notifier.Load()
t.Run("Command Notifier Tester", func(t *testing.T) {
assert.True(t, Command.CanTest())
})
t.Run("command Notifier Tester", func(t *testing.T) {
assert.True(t, command.CanTest())
})
t.Run("command Within Limits", func(t *testing.T) {
ok, err := command.WithinLimits()
t.Run("Command Within Limits", func(t *testing.T) {
ok, err := Command.WithinLimits()
assert.Nil(t, err)
assert.True(t, ok)
})
t.Run("command OnFailure", func(t *testing.T) {
command.OnFailure(TestService, TestFailure)
assert.Equal(t, 1, len(command.Queue))
t.Run("Command OnFailure", func(t *testing.T) {
Command.OnFailure(TestService, TestFailure)
assert.Equal(t, 1, len(Command.Queue))
})
t.Run("command OnSuccess", func(t *testing.T) {
command.OnSuccess(TestService)
assert.Equal(t, 1, len(command.Queue))
t.Run("Command OnSuccess", func(t *testing.T) {
Command.OnSuccess(TestService)
assert.Equal(t, 1, len(Command.Queue))
})
t.Run("command OnSuccess Again", func(t *testing.T) {
command.OnSuccess(TestService)
assert.Equal(t, 1, len(command.Queue))
go notifier.Queue(command)
t.Run("Command OnSuccess Again", func(t *testing.T) {
Command.OnSuccess(TestService)
assert.Equal(t, 1, len(Command.Queue))
go notifier.Queue(Command)
time.Sleep(20 * time.Second)
assert.Equal(t, 0, len(command.Queue))
assert.Equal(t, 0, len(Command.Queue))
})
t.Run("command Within Limits again", func(t *testing.T) {
ok, err := command.WithinLimits()
t.Run("Command Within Limits again", func(t *testing.T) {
ok, err := Command.WithinLimits()
assert.Nil(t, err)
assert.True(t, ok)
})
t.Run("command Send", func(t *testing.T) {
command.Send(commandTest)
assert.Equal(t, 0, len(command.Queue))
t.Run("Command Send", func(t *testing.T) {
Command.Send(commandTest)
assert.Equal(t, 0, len(Command.Queue))
})
t.Run("command Test", func(t *testing.T) {
command.OnTest()
t.Run("Command Test", func(t *testing.T) {
Command.OnTest()
})
t.Run("command Queue", func(t *testing.T) {
go notifier.Queue(command)
t.Run("Command Queue", func(t *testing.T) {
go notifier.Queue(Command)
time.Sleep(5 * time.Second)
assert.Equal(t, "sh", command.Host)
assert.Equal(t, commandTest, command.Var1)
assert.Equal(t, commandTest, command.Var2)
assert.Equal(t, 0, len(command.Queue))
assert.Equal(t, "sh", Command.Host)
assert.Equal(t, commandTest, Command.Var1)
assert.Equal(t, commandTest, Command.Var2)
assert.Equal(t, 0, len(Command.Queue))
})
}

View File

@ -31,10 +31,10 @@ type discord struct {
*notifier.Notification
}
var discorder = &discord{&notifier.Notification{
var Discorder = &discord{&notifier.Notification{
Method: "discord",
Title: "discord",
Description: "Send notifications to your discord channel using discord webhooks. Insert your discord channel webhook URL to receive notifications. Based on the <a href=\"https://discordapp.com/developers/docs/resources/webhook\">discord webhooker API</a>.",
Description: "Send notifications to your discord channel using discord webhooks. Insert your discord channel Webhook URL to receive notifications. Based on the <a href=\"https://discordapp.com/developers/docs/resources/Webhook\">discord webhooker API</a>.",
Author: "Hunter Long",
AuthorUrl: "https://github.com/hunterlong",
Delay: time.Duration(5 * time.Second),
@ -43,23 +43,15 @@ var discorder = &discord{&notifier.Notification{
Form: []notifier.NotificationForm{{
Type: "text",
Title: "discord webhooker URL",
Placeholder: "Insert your webhook URL here",
Placeholder: "Insert your Webhook URL here",
DbField: "host",
}}},
}
// init the discord notifier
func init() {
err := notifier.AddNotifier(discorder)
if err != nil {
panic(err)
}
}
// Send will send a HTTP Post to the discord API. It accepts type: []byte
func (u *discord) Send(msg interface{}) error {
message := msg.(string)
_, _, err := utils.HttpRequest(discorder.GetValue("host"), "POST", "application/json", nil, strings.NewReader(message), time.Duration(10*time.Second), true)
_, _, err := utils.HttpRequest(Discorder.GetValue("host"), "POST", "application/json", nil, strings.NewReader(message), time.Duration(10*time.Second), true)
return err
}
@ -98,7 +90,7 @@ func (u *discord) OnSave() error {
func (u *discord) OnTest() error {
outError := errors.New("Incorrect discord URL, please confirm URL is correct")
message := `{"content": "Testing the discord notifier"}`
contents, _, err := utils.HttpRequest(discorder.Host, "POST", "application/json", nil, bytes.NewBuffer([]byte(message)), time.Duration(10*time.Second), true)
contents, _, err := utils.HttpRequest(Discorder.Host, "POST", "application/json", nil, bytes.NewBuffer([]byte(message)), time.Duration(10*time.Second), true)
if string(contents) == "" {
return nil
}

View File

@ -30,7 +30,7 @@ var (
func init() {
DISCORD_URL = os.Getenv("DISCORD_URL")
discorder.Host = DISCORD_URL
Discorder.Host = DISCORD_URL
}
func TestDiscordNotifier(t *testing.T) {
@ -42,36 +42,32 @@ func TestDiscordNotifier(t *testing.T) {
currentCount = CountNotifiers()
t.Run("Load discord", func(t *testing.T) {
discorder.Host = DISCORD_URL
discorder.Delay = time.Duration(100 * time.Millisecond)
err := notifier.AddNotifier(discorder)
Discorder.Host = DISCORD_URL
Discorder.Delay = time.Duration(100 * time.Millisecond)
err := notifier.AddNotifiers(Discorder)
assert.Nil(t, err)
assert.Equal(t, "Hunter Long", discorder.Author)
assert.Equal(t, DISCORD_URL, discorder.Host)
})
t.Run("Load discord Notifier", func(t *testing.T) {
notifier.Load()
assert.Equal(t, "Hunter Long", Discorder.Author)
assert.Equal(t, DISCORD_URL, Discorder.Host)
})
t.Run("discord Notifier Tester", func(t *testing.T) {
assert.True(t, discorder.CanTest())
assert.True(t, Discorder.CanTest())
})
t.Run("discord Within Limits", func(t *testing.T) {
ok, err := discorder.WithinLimits()
ok, err := Discorder.WithinLimits()
assert.Nil(t, err)
assert.True(t, ok)
})
t.Run("discord OnFailure", func(t *testing.T) {
discorder.OnFailure(TestService, TestFailure)
assert.Equal(t, 1, len(discorder.Queue))
Discorder.OnFailure(TestService, TestFailure)
assert.Equal(t, 1, len(Discorder.Queue))
})
t.Run("discord OnSuccess", func(t *testing.T) {
discorder.OnSuccess(TestService)
assert.Equal(t, 1, len(discorder.Queue))
Discorder.OnSuccess(TestService)
assert.Equal(t, 1, len(Discorder.Queue))
})
t.Run("discord Check Back Online", func(t *testing.T) {
@ -79,25 +75,25 @@ func TestDiscordNotifier(t *testing.T) {
})
t.Run("discord OnSuccess Again", func(t *testing.T) {
discorder.OnSuccess(TestService)
assert.Equal(t, 1, len(discorder.Queue))
Discorder.OnSuccess(TestService)
assert.Equal(t, 1, len(Discorder.Queue))
})
t.Run("discord Send", func(t *testing.T) {
err := discorder.Send(discordMessage)
err := Discorder.Send(discordMessage)
assert.Nil(t, err)
})
t.Run("discord Test", func(t *testing.T) {
err := discorder.OnTest()
err := Discorder.OnTest()
assert.Nil(t, err)
})
t.Run("discord Queue", func(t *testing.T) {
go notifier.Queue(discorder)
go notifier.Queue(Discorder)
time.Sleep(1 * time.Second)
assert.Equal(t, DISCORD_URL, discorder.Host)
assert.Equal(t, 0, len(discorder.Queue))
assert.Equal(t, DISCORD_URL, Discorder.Host)
assert.Equal(t, 0, len(Discorder.Queue))
})
}

View File

@ -111,7 +111,7 @@ type email struct {
*notifier.Notification
}
var emailer = &email{&notifier.Notification{
var Emailer = &email{&notifier.Notification{
Method: "email",
Title: "email",
Description: "Send emails via SMTP when services are online or offline.",
@ -157,13 +157,6 @@ var emailer = &email{&notifier.Notification{
}},
}}
func init() {
err := notifier.AddNotifier(emailer)
if err != nil {
panic(err)
}
}
// Send will send the SMTP email with your authentication It accepts type: *emailOutgoing
func (u *email) Send(msg interface{}) error {
email := msg.(*emailOutgoing)
@ -255,7 +248,7 @@ func (u *email) OnTest() error {
}
func (u *email) dialSend(email *emailOutgoing) error {
mailer = mail.NewDialer(emailer.Host, emailer.Port, emailer.Username, emailer.Password)
mailer = mail.NewDialer(Emailer.Host, Emailer.Port, Emailer.Username, Emailer.Password)
emailSource(email)
m := mail.NewMessage()
// if email setting TLS is Disabled

View File

@ -44,12 +44,12 @@ func init() {
EMAIL_SEND_TO = os.Getenv("EMAIL_SEND_TO")
EMAIL_PORT = utils.ToInt(os.Getenv("EMAIL_PORT"))
emailer.Host = EMAIL_HOST
emailer.Username = EMAIL_USER
emailer.Password = EMAIL_PASS
emailer.Var1 = EMAIL_OUTGOING
emailer.Var2 = EMAIL_SEND_TO
emailer.Port = int(EMAIL_PORT)
Emailer.Host = EMAIL_HOST
Emailer.Username = EMAIL_USER
Emailer.Password = EMAIL_PASS
Emailer.Var1 = EMAIL_OUTGOING
Emailer.Var2 = EMAIL_SEND_TO
Emailer.Port = int(EMAIL_PORT)
}
func TestEmailNotifier(t *testing.T) {
@ -61,36 +61,32 @@ func TestEmailNotifier(t *testing.T) {
currentCount = CountNotifiers()
t.Run("New Emailer", func(t *testing.T) {
emailer.Host = EMAIL_HOST
emailer.Username = EMAIL_USER
emailer.Password = EMAIL_PASS
emailer.Var1 = EMAIL_OUTGOING
emailer.Var2 = EMAIL_SEND_TO
emailer.Port = int(EMAIL_PORT)
emailer.Delay = time.Duration(100 * time.Millisecond)
Emailer.Host = EMAIL_HOST
Emailer.Username = EMAIL_USER
Emailer.Password = EMAIL_PASS
Emailer.Var1 = EMAIL_OUTGOING
Emailer.Var2 = EMAIL_SEND_TO
Emailer.Port = int(EMAIL_PORT)
Emailer.Delay = time.Duration(100 * time.Millisecond)
testEmail = &emailOutgoing{
To: emailer.GetValue("var2"),
To: Emailer.GetValue("var2"),
Subject: fmt.Sprintf("Service %v is Failing", TestService.Name),
Template: mainEmailTemplate,
Data: TestService,
From: emailer.GetValue("var1"),
From: Emailer.GetValue("var1"),
}
})
t.Run("Add email Notifier", func(t *testing.T) {
err := notifier.AddNotifier(emailer)
err := notifier.AddNotifiers(Emailer)
assert.Nil(t, err)
assert.Equal(t, "Hunter Long", emailer.Author)
assert.Equal(t, EMAIL_HOST, emailer.Host)
})
t.Run("Emailer Load", func(t *testing.T) {
notifier.Load()
assert.Equal(t, "Hunter Long", Emailer.Author)
assert.Equal(t, EMAIL_HOST, Emailer.Host)
})
t.Run("email Within Limits", func(t *testing.T) {
ok, err := emailer.WithinLimits()
ok, err := Emailer.WithinLimits()
assert.Nil(t, err)
assert.True(t, ok)
})
@ -101,13 +97,13 @@ func TestEmailNotifier(t *testing.T) {
})
t.Run("email OnFailure", func(t *testing.T) {
emailer.OnFailure(TestService, TestFailure)
assert.Equal(t, 1, len(emailer.Queue))
Emailer.OnFailure(TestService, TestFailure)
assert.Equal(t, 1, len(Emailer.Queue))
})
t.Run("email OnSuccess", func(t *testing.T) {
emailer.OnSuccess(TestService)
assert.Equal(t, 1, len(emailer.Queue))
Emailer.OnSuccess(TestService)
assert.Equal(t, 1, len(Emailer.Queue))
})
t.Run("email Check Back Online", func(t *testing.T) {
@ -115,26 +111,26 @@ func TestEmailNotifier(t *testing.T) {
})
t.Run("email OnSuccess Again", func(t *testing.T) {
emailer.OnSuccess(TestService)
assert.Equal(t, 1, len(emailer.Queue))
Emailer.OnSuccess(TestService)
assert.Equal(t, 1, len(Emailer.Queue))
})
t.Run("email Send", func(t *testing.T) {
err := emailer.Send(testEmail)
err := Emailer.Send(testEmail)
assert.Nil(t, err)
})
t.Run("emailer Test", func(t *testing.T) {
t.Run("Emailer Test", func(t *testing.T) {
t.SkipNow()
err := emailer.OnTest()
err := Emailer.OnTest()
assert.Nil(t, err)
})
t.Run("email Run Queue", func(t *testing.T) {
go notifier.Queue(emailer)
go notifier.Queue(Emailer)
time.Sleep(6 * time.Second)
assert.Equal(t, EMAIL_HOST, emailer.Host)
assert.Equal(t, 0, len(emailer.Queue))
assert.Equal(t, EMAIL_HOST, Emailer.Host)
assert.Equal(t, 0, len(Emailer.Queue))
})
}

View File

@ -33,7 +33,7 @@ type lineNotifier struct {
*notifier.Notification
}
var lineNotify = &lineNotifier{&notifier.Notification{
var LineNotify = &lineNotifier{&notifier.Notification{
Method: lineNotifyMethod,
Title: "LINE Notify",
Description: "LINE Notify will send notifications to your LINE Notify account when services are offline or online. Based on the <a href=\"https://notify-bot.line.me/doc/en/\">LINE Notify API</a>.",
@ -48,14 +48,6 @@ var lineNotify = &lineNotifier{&notifier.Notification{
}}},
}
// DEFINE YOUR NOTIFICATION HERE.
func init() {
err := notifier.AddNotifier(lineNotify)
if err != nil {
panic(err)
}
}
// Send will send a HTTP Post with the Authorization to the notify-api.line.me server. It accepts type: string
func (u *lineNotifier) Send(msg interface{}) error {
message := msg.(string)

View File

@ -31,19 +31,19 @@ type mobilePush struct {
*notifier.Notification
}
var mobile = &mobilePush{&notifier.Notification{
Method: "mobile",
var Mobile = &mobilePush{&notifier.Notification{
Method: "Mobile",
Title: "Mobile Notifications",
Description: `Receive push notifications on your mobile device using the Statping App. You can scan the Authentication QR Code found in Settings to get the mobile app setup in seconds.
Description: `Receive push notifications on your Mobile device using the Statping App. You can scan the Authentication QR Code found in Settings to get the Mobile app setup in seconds.
<p align="center"><a href="https://play.google.com/store/apps/details?id=com.statping"><img src="https://img.cjx.io/google-play.svg"></a><a href="https://itunes.apple.com/us/app/apple-store/id1445513219"><img src="https://img.cjx.io/app-store-badge.svg"></a></p>`,
Author: "Hunter Long",
AuthorUrl: "https://github.com/hunterlong",
Delay: time.Duration(5 * time.Second),
Icon: "fas fa-mobile-alt",
Icon: "fas fa-Mobile-alt",
Form: []notifier.NotificationForm{{
Type: "text",
Title: "Device Identifiers",
Placeholder: "A list of your mobile device push notification ID's.",
Placeholder: "A list of your Mobile device push notification ID's.",
DbField: "var1",
IsHidden: true,
}, {
@ -55,14 +55,6 @@ var mobile = &mobilePush{&notifier.Notification{
}}},
}
// init the discord notifier
func init() {
err := notifier.AddNotifier(mobile)
if err != nil {
panic(err)
}
}
func (u *mobilePush) Select() *notifier.Notification {
return u.Notification
}

View File

@ -31,90 +31,79 @@ var (
func init() {
MOBILE_ID = os.Getenv("MOBILE_ID")
MOBILE_NUMBER = os.Getenv("MOBILE_NUMBER")
mobile.Var1 = MOBILE_ID
Mobile.Var1 = MOBILE_ID
}
func TestMobileNotifier(t *testing.T) {
t.Parallel()
mobile.Var1 = MOBILE_ID
mobile.Var2 = os.Getenv("MOBILE_NUMBER")
Mobile.Var1 = MOBILE_ID
Mobile.Var2 = os.Getenv("MOBILE_NUMBER")
if MOBILE_ID == "" {
t.Log("mobile notifier testing skipped, missing MOBILE_ID environment variable")
t.Log("Mobile notifier testing skipped, missing MOBILE_ID environment variable")
t.SkipNow()
}
currentCount = CountNotifiers()
t.Run("Load mobile", func(t *testing.T) {
mobile.Var1 = MOBILE_ID
mobile.Var2 = MOBILE_NUMBER
mobile.Delay = time.Duration(100 * time.Millisecond)
mobile.Limits = 10
err := notifier.AddNotifier(mobile)
t.Run("Load Mobile", func(t *testing.T) {
Mobile.Var1 = MOBILE_ID
Mobile.Var2 = MOBILE_NUMBER
Mobile.Delay = time.Duration(100 * time.Millisecond)
Mobile.Limits = 10
err := notifier.AddNotifiers(Mobile)
assert.Nil(t, err)
assert.Equal(t, "Hunter Long", mobile.Author)
assert.Equal(t, MOBILE_ID, mobile.Var1)
assert.Equal(t, MOBILE_NUMBER, mobile.Var2)
assert.Equal(t, "Hunter Long", Mobile.Author)
assert.Equal(t, MOBILE_ID, Mobile.Var1)
assert.Equal(t, MOBILE_NUMBER, Mobile.Var2)
})
t.Run("Load mobile Notifier", func(t *testing.T) {
notifier.Load()
t.Run("Mobile Notifier Tester", func(t *testing.T) {
assert.True(t, Mobile.CanTest())
})
t.Run("mobile Notifier Tester", func(t *testing.T) {
assert.True(t, mobile.CanTest())
})
t.Run("mobile Within Limits", func(t *testing.T) {
ok, err := mobile.WithinLimits()
t.Run("Mobile Within Limits", func(t *testing.T) {
ok, err := Mobile.WithinLimits()
assert.Nil(t, err)
assert.True(t, ok)
})
t.Run("mobile OnFailure", func(t *testing.T) {
mobile.OnFailure(TestService, TestFailure)
assert.Equal(t, 1, len(mobile.Queue))
t.Run("Mobile OnFailure", func(t *testing.T) {
Mobile.OnFailure(TestService, TestFailure)
assert.Equal(t, 1, len(Mobile.Queue))
})
t.Run("mobile OnFailure multiple times", func(t *testing.T) {
for i := 0; i <= 5; i++ {
mobile.OnFailure(TestService, TestFailure)
}
assert.Equal(t, 7, len(mobile.Queue))
t.Run("Mobile OnSuccess", func(t *testing.T) {
Mobile.OnSuccess(TestService)
assert.Equal(t, 1, len(Mobile.Queue))
})
t.Run("mobile OnSuccess", func(t *testing.T) {
mobile.OnSuccess(TestService)
assert.Equal(t, 7, len(mobile.Queue))
})
t.Run("mobile OnSuccess Again", func(t *testing.T) {
t.Run("Mobile OnSuccess Again", func(t *testing.T) {
t.SkipNow()
assert.True(t, TestService.Online)
mobile.OnSuccess(TestService)
assert.Equal(t, 1, len(mobile.Queue))
go notifier.Queue(mobile)
Mobile.OnSuccess(TestService)
assert.Equal(t, 1, len(Mobile.Queue))
go notifier.Queue(Mobile)
time.Sleep(20 * time.Second)
assert.Equal(t, 1, len(mobile.Queue))
assert.Equal(t, 1, len(Mobile.Queue))
})
t.Run("mobile Within Limits again", func(t *testing.T) {
ok, err := mobile.WithinLimits()
t.Run("Mobile Within Limits again", func(t *testing.T) {
ok, err := Mobile.WithinLimits()
assert.Nil(t, err)
assert.True(t, ok)
})
t.Run("mobile Test", func(t *testing.T) {
t.Run("Mobile Test", func(t *testing.T) {
t.SkipNow()
err := mobile.OnTest()
err := Mobile.OnTest()
assert.Nil(t, err)
})
t.Run("mobile Queue", func(t *testing.T) {
t.Run("Mobile Queue", func(t *testing.T) {
t.SkipNow()
go notifier.Queue(mobile)
go notifier.Queue(Mobile)
time.Sleep(15 * time.Second)
assert.Equal(t, MOBILE_ID, mobile.Var1)
assert.Equal(t, 0, len(mobile.Queue))
assert.Equal(t, MOBILE_ID, Mobile.Var1)
assert.Equal(t, 0, len(Mobile.Queue))
})
}

View File

@ -34,18 +34,11 @@ const (
slackText = `{"text":"{{.}}"}`
)
func init() {
err := notifier.AddNotifier(slacker)
if err != nil {
panic(err)
}
}
type slack struct {
*notifier.Notification
}
var slacker = &slack{&notifier.Notification{
var Slacker = &slack{&notifier.Notification{
Method: slackMethod,
Title: "slack",
Description: "Send notifications to your slack channel when a service is offline. Insert your Incoming webhooker URL for your channel to receive notifications. Based on the <a href=\"https://api.slack.com/incoming-webhooks\">slack API</a>.",
@ -57,7 +50,7 @@ var slacker = &slack{&notifier.Notification{
Form: []notifier.NotificationForm{{
Type: "text",
Title: "Incoming webhooker Url",
Placeholder: "Insert your slack webhook URL here.",
Placeholder: "Insert your slack Webhook URL here.",
SmallText: "Incoming webhooker URL from <a href=\"https://api.slack.com/apps\" target=\"_blank\">slack Apps</a>",
DbField: "Host",
Required: true,
@ -71,7 +64,7 @@ func parseSlackMessage(id int64, temp string, data interface{}) error {
if err != nil {
return err
}
slacker.AddQueue(fmt.Sprintf("service_%v", id), buf.String())
Slacker.AddQueue(fmt.Sprintf("service_%v", id), buf.String())
return nil
}

View File

@ -30,13 +30,13 @@ var (
func init() {
SLACK_URL = os.Getenv("SLACK_URL")
slacker.Host = SLACK_URL
Slacker.Host = SLACK_URL
}
func TestSlackNotifier(t *testing.T) {
t.Parallel()
SLACK_URL = os.Getenv("SLACK_URL")
slacker.Host = SLACK_URL
Slacker.Host = SLACK_URL
if SLACK_URL == "" {
t.Log("slack notifier testing skipped, missing SLACK_URL environment variable")
t.SkipNow()
@ -44,76 +44,72 @@ func TestSlackNotifier(t *testing.T) {
currentCount = CountNotifiers()
t.Run("Load slack", func(t *testing.T) {
slacker.Host = SLACK_URL
slacker.Delay = time.Duration(100 * time.Millisecond)
slacker.Limits = 3
err := notifier.AddNotifier(slacker)
Slacker.Host = SLACK_URL
Slacker.Delay = time.Duration(100 * time.Millisecond)
Slacker.Limits = 3
err := notifier.AddNotifiers(Slacker)
assert.Nil(t, err)
assert.Equal(t, "Hunter Long", slacker.Author)
assert.Equal(t, SLACK_URL, slacker.Host)
})
t.Run("Load slack Notifier", func(t *testing.T) {
notifier.Load()
assert.Equal(t, "Hunter Long", Slacker.Author)
assert.Equal(t, SLACK_URL, Slacker.Host)
})
t.Run("slack Notifier Tester", func(t *testing.T) {
assert.True(t, slacker.CanTest())
assert.True(t, Slacker.CanTest())
})
//t.Run("slack parse message", func(t *testing.T) {
// err := parseSlackMessage(slackText, "this is a test!")
// assert.Nil(t, err)
// assert.Equal(t, 1, len(slacker.Queue))
// assert.Equal(t, 1, len(Slacker.Queue))
//})
t.Run("slack Within Limits", func(t *testing.T) {
ok, err := slacker.WithinLimits()
ok, err := Slacker.WithinLimits()
assert.Nil(t, err)
assert.True(t, ok)
})
t.Run("slack OnFailure", func(t *testing.T) {
slacker.OnFailure(TestService, TestFailure)
assert.Equal(t, 1, len(slacker.Queue))
Slacker.OnFailure(TestService, TestFailure)
assert.Equal(t, 1, len(Slacker.Queue))
})
t.Run("slack OnSuccess", func(t *testing.T) {
slacker.OnSuccess(TestService)
assert.Equal(t, 1, len(slacker.Queue))
Slacker.OnSuccess(TestService)
assert.Equal(t, 1, len(Slacker.Queue))
})
t.Run("slack OnSuccess Again", func(t *testing.T) {
assert.True(t, TestService.Online)
slacker.OnSuccess(TestService)
assert.Equal(t, 1, len(slacker.Queue))
go notifier.Queue(slacker)
Slacker.OnSuccess(TestService)
assert.Equal(t, 1, len(Slacker.Queue))
go notifier.Queue(Slacker)
time.Sleep(15 * time.Second)
assert.Equal(t, 0, len(slacker.Queue))
assert.Equal(t, 0, len(Slacker.Queue))
})
t.Run("slack Within Limits again", func(t *testing.T) {
ok, err := slacker.WithinLimits()
ok, err := Slacker.WithinLimits()
assert.Nil(t, err)
assert.True(t, ok)
})
t.Run("slack Send", func(t *testing.T) {
err := slacker.Send(slackTestMessage)
err := Slacker.Send(slackTestMessage)
assert.Nil(t, err)
assert.Equal(t, 0, len(slacker.Queue))
assert.Equal(t, 0, len(Slacker.Queue))
})
t.Run("slack Test", func(t *testing.T) {
err := slacker.OnTest()
err := Slacker.OnTest()
assert.Nil(t, err)
})
t.Run("slack Queue", func(t *testing.T) {
go notifier.Queue(slacker)
go notifier.Queue(Slacker)
time.Sleep(10 * time.Second)
assert.Equal(t, SLACK_URL, slacker.Host)
assert.Equal(t, 0, len(slacker.Queue))
assert.Equal(t, SLACK_URL, Slacker.Host)
assert.Equal(t, 0, len(Slacker.Queue))
})
}

View File

@ -31,7 +31,7 @@ type telegram struct {
*notifier.Notification
}
var telegramNotifier = &telegram{&notifier.Notification{
var Telegram = &telegram{&notifier.Notification{
Method: "telegram",
Title: "Telegram",
Description: "Receive notifications on your Telegram channel when a service has an issue. You must get a Telegram API token from the /botfather. Review the <a target=\"_blank\" href=\"http://techthoughts.info/how-to-create-a-telegram-bot-and-send-messages-via-api\">Telegram API Tutorial</a> to learn how to generate a new API Token.",
@ -56,14 +56,6 @@ var telegramNotifier = &telegram{&notifier.Notification{
}}},
}
// DEFINE YOUR NOTIFICATION HERE.
func init() {
err := notifier.AddNotifier(telegramNotifier)
if err != nil {
panic(err)
}
}
func (u *telegram) Select() *notifier.Notification {
return u.Notification
}

View File

@ -32,8 +32,8 @@ var (
func init() {
telegramToken = os.Getenv("TELEGRAM_TOKEN")
telegramChannel = os.Getenv("TELEGRAM_CHANNEL")
telegramNotifier.ApiSecret = telegramToken
telegramNotifier.Var1 = telegramChannel
Telegram.ApiSecret = telegramToken
Telegram.Var1 = telegramChannel
}
func TestTelegramNotifier(t *testing.T) {
@ -46,29 +46,25 @@ func TestTelegramNotifier(t *testing.T) {
currentCount = CountNotifiers()
t.Run("Load Telegram", func(t *testing.T) {
telegramNotifier.ApiSecret = telegramToken
telegramNotifier.Var1 = telegramChannel
telegramNotifier.Delay = time.Duration(1 * time.Second)
err := notifier.AddNotifier(telegramNotifier)
Telegram.ApiSecret = telegramToken
Telegram.Var1 = telegramChannel
Telegram.Delay = time.Duration(1 * time.Second)
err := notifier.AddNotifiers(Telegram)
assert.Nil(t, err)
assert.Equal(t, "Hunter Long", telegramNotifier.Author)
assert.Equal(t, telegramToken, telegramNotifier.ApiSecret)
assert.Equal(t, telegramChannel, telegramNotifier.Var1)
})
t.Run("Load Telegram Notifier", func(t *testing.T) {
notifier.Load()
assert.Equal(t, "Hunter Long", Telegram.Author)
assert.Equal(t, telegramToken, Telegram.ApiSecret)
assert.Equal(t, telegramChannel, Telegram.Var1)
})
t.Run("Telegram Within Limits", func(t *testing.T) {
ok, err := telegramNotifier.WithinLimits()
ok, err := Telegram.WithinLimits()
assert.Nil(t, err)
assert.True(t, ok)
})
t.Run("Telegram OnFailure", func(t *testing.T) {
telegramNotifier.OnFailure(TestService, TestFailure)
assert.Equal(t, 1, len(telegramNotifier.Queue))
Telegram.OnFailure(TestService, TestFailure)
assert.Equal(t, 1, len(Telegram.Queue))
})
t.Run("Telegram Check Offline", func(t *testing.T) {
@ -76,8 +72,8 @@ func TestTelegramNotifier(t *testing.T) {
})
t.Run("Telegram OnSuccess", func(t *testing.T) {
telegramNotifier.OnSuccess(TestService)
assert.Equal(t, 1, len(telegramNotifier.Queue))
Telegram.OnSuccess(TestService)
assert.Equal(t, 1, len(Telegram.Queue))
})
t.Run("Telegram Check Back Online", func(t *testing.T) {
@ -85,25 +81,25 @@ func TestTelegramNotifier(t *testing.T) {
})
t.Run("Telegram OnSuccess Again", func(t *testing.T) {
telegramNotifier.OnSuccess(TestService)
assert.Equal(t, 1, len(telegramNotifier.Queue))
Telegram.OnSuccess(TestService)
assert.Equal(t, 1, len(Telegram.Queue))
})
t.Run("Telegram Send", func(t *testing.T) {
err := telegramNotifier.Send(telegramMessage)
err := Telegram.Send(telegramMessage)
assert.Nil(t, err)
})
t.Run("Telegram Test", func(t *testing.T) {
err := telegramNotifier.OnTest()
err := Telegram.OnTest()
assert.Nil(t, err)
})
t.Run("Telegram Queue", func(t *testing.T) {
go notifier.Queue(telegramNotifier)
go notifier.Queue(Telegram)
time.Sleep(3 * time.Second)
assert.Equal(t, telegramToken, telegramNotifier.ApiSecret)
assert.Equal(t, 0, len(telegramNotifier.Queue))
assert.Equal(t, telegramToken, Telegram.ApiSecret)
assert.Equal(t, 0, len(Telegram.Queue))
})
}

View File

@ -31,7 +31,7 @@ type twilio struct {
*notifier.Notification
}
var twilioNotifier = &twilio{&notifier.Notification{
var Twilio = &twilio{&notifier.Notification{
Method: "twilio",
Title: "Twilio",
Description: "Receive SMS text messages directly to your cellphone when a service is offline. You can use a Twilio test account with limits. This notifier uses the <a href=\"https://www.twilio.com/docs/usage/api\">Twilio API</a>.",
@ -66,14 +66,6 @@ var twilioNotifier = &twilio{&notifier.Notification{
}}},
}
// DEFINE YOUR NOTIFICATION HERE.
func init() {
err := notifier.AddNotifier(twilioNotifier)
if err != nil {
panic(err)
}
}
func (u *twilio) Select() *notifier.Notification {
return u.Notification
}

View File

@ -37,10 +37,10 @@ func init() {
TWILIO_FROM = os.Getenv("TWILIO_FROM")
TWILIO_TO = os.Getenv("TWILIO_TO")
twilioNotifier.ApiKey = TWILIO_SID
twilioNotifier.ApiSecret = TWILIO_SECRET
twilioNotifier.Var1 = TWILIO_TO
twilioNotifier.Var2 = TWILIO_FROM
Twilio.ApiKey = TWILIO_SID
Twilio.ApiSecret = TWILIO_SECRET
Twilio.Var1 = TWILIO_TO
Twilio.Var2 = TWILIO_FROM
}
func TestTwilioNotifier(t *testing.T) {
@ -52,27 +52,23 @@ func TestTwilioNotifier(t *testing.T) {
currentCount = CountNotifiers()
t.Run("Load Twilio", func(t *testing.T) {
twilioNotifier.ApiKey = TWILIO_SID
twilioNotifier.Delay = time.Duration(100 * time.Millisecond)
err := notifier.AddNotifier(twilioNotifier)
Twilio.ApiKey = TWILIO_SID
Twilio.Delay = time.Duration(100 * time.Millisecond)
err := notifier.AddNotifiers(Twilio)
assert.Nil(t, err)
assert.Equal(t, "Hunter Long", twilioNotifier.Author)
assert.Equal(t, TWILIO_SID, twilioNotifier.ApiKey)
})
t.Run("Load Twilio Notifier", func(t *testing.T) {
notifier.Load()
assert.Equal(t, "Hunter Long", Twilio.Author)
assert.Equal(t, TWILIO_SID, Twilio.ApiKey)
})
t.Run("Twilio Within Limits", func(t *testing.T) {
ok, err := twilioNotifier.WithinLimits()
ok, err := Twilio.WithinLimits()
assert.Nil(t, err)
assert.True(t, ok)
})
t.Run("Twilio OnFailure", func(t *testing.T) {
twilioNotifier.OnFailure(TestService, TestFailure)
assert.Len(t, twilioNotifier.Queue, 1)
Twilio.OnFailure(TestService, TestFailure)
assert.Len(t, Twilio.Queue, 1)
})
t.Run("Twilio Check Offline", func(t *testing.T) {
@ -80,8 +76,8 @@ func TestTwilioNotifier(t *testing.T) {
})
t.Run("Twilio OnSuccess", func(t *testing.T) {
twilioNotifier.OnSuccess(TestService)
assert.Len(t, twilioNotifier.Queue, 2)
Twilio.OnSuccess(TestService)
assert.Len(t, Twilio.Queue, 2)
})
t.Run("Twilio Check Back Online", func(t *testing.T) {
@ -89,25 +85,25 @@ func TestTwilioNotifier(t *testing.T) {
})
t.Run("Twilio OnSuccess Again", func(t *testing.T) {
twilioNotifier.OnSuccess(TestService)
assert.Len(t, twilioNotifier.Queue, 2)
Twilio.OnSuccess(TestService)
assert.Len(t, Twilio.Queue, 2)
})
t.Run("Twilio Send", func(t *testing.T) {
err := twilioNotifier.Send(twilioMessage)
err := Twilio.Send(twilioMessage)
assert.Nil(t, err)
})
t.Run("Twilio Test", func(t *testing.T) {
err := twilioNotifier.OnTest()
err := Twilio.OnTest()
assert.Nil(t, err)
})
t.Run("Twilio Queue", func(t *testing.T) {
go notifier.Queue(twilioNotifier)
go notifier.Queue(Twilio)
time.Sleep(1 * time.Second)
assert.Equal(t, TWILIO_SID, twilioNotifier.ApiKey)
assert.Equal(t, 0, len(twilioNotifier.Queue))
assert.Equal(t, TWILIO_SID, Twilio.ApiKey)
assert.Equal(t, 0, len(Twilio.Queue))
})
}

View File

@ -28,14 +28,14 @@ import (
)
const (
webhookMethod = "webhook"
webhookMethod = "Webhook"
)
type webhooker struct {
*notifier.Notification
}
var webhook = &webhooker{&notifier.Notification{
var Webhook = &webhooker{&notifier.Notification{
Method: webhookMethod,
Title: "HTTP webhooker",
Description: "Send a custom HTTP request to a specific URL with your own body, headers, and parameters.",
@ -78,14 +78,6 @@ var webhook = &webhooker{&notifier.Notification{
},
}}}
// DEFINE YOUR NOTIFICATION HERE.
func init() {
err := notifier.AddNotifier(webhook)
if err != nil {
panic(err)
}
}
// Send will send a HTTP Post to the webhooker API. It accepts type: string
func (w *webhooker) Send(msg interface{}) error {
resp, err := w.sendHttpWebhook(msg.(string))
@ -158,7 +150,7 @@ func (w *webhooker) OnTest() error {
}
defer resp.Body.Close()
content, err := ioutil.ReadAll(resp.Body)
utils.Log(1, fmt.Sprintf("webhook notifier received: '%v'", string(content)))
utils.Log(1, fmt.Sprintf("Webhook notifier received: '%v'", string(content)))
return err
}

View File

@ -30,10 +30,10 @@ var (
)
func init() {
webhook.Host = webhookTestUrl
webhook.Var1 = "POST"
webhook.Var2 = webhookMessage
webhook.ApiKey = "application/json"
Webhook.Host = webhookTestUrl
Webhook.Var1 = "POST"
Webhook.Var2 = webhookMessage
Webhook.ApiKey = "application/json"
}
func TestWebhookNotifier(t *testing.T) {
@ -41,26 +41,18 @@ func TestWebhookNotifier(t *testing.T) {
currentCount = CountNotifiers()
t.Run("Load webhooker", func(t *testing.T) {
webhook.Host = webhookTestUrl
webhook.Delay = time.Duration(100 * time.Millisecond)
webhook.ApiKey = apiKey
err := notifier.AddNotifier(webhook)
Webhook.Host = webhookTestUrl
Webhook.Delay = time.Duration(100 * time.Millisecond)
Webhook.ApiKey = apiKey
err := notifier.AddNotifiers(Webhook)
assert.Nil(t, err)
assert.Equal(t, "Hunter Long", webhook.Author)
assert.Equal(t, webhookTestUrl, webhook.Host)
assert.Equal(t, apiKey, webhook.ApiKey)
})
t.Run("Load webhooker Notifier", func(t *testing.T) {
notifier.Load()
})
t.Run("Load webhooker Notifier", func(t *testing.T) {
notifier.Load()
assert.Equal(t, "Hunter Long", Webhook.Author)
assert.Equal(t, webhookTestUrl, Webhook.Host)
assert.Equal(t, apiKey, Webhook.ApiKey)
})
t.Run("webhooker Notifier Tester", func(t *testing.T) {
assert.True(t, webhook.CanTest())
assert.True(t, Webhook.CanTest())
})
t.Run("webhooker Replace Body Text", func(t *testing.T) {
@ -69,19 +61,19 @@ func TestWebhookNotifier(t *testing.T) {
})
t.Run("webhooker Within Limits", func(t *testing.T) {
ok, err := webhook.WithinLimits()
ok, err := Webhook.WithinLimits()
assert.Nil(t, err)
assert.True(t, ok)
})
t.Run("webhooker OnFailure", func(t *testing.T) {
webhook.OnFailure(TestService, TestFailure)
assert.Len(t, webhook.Queue, 1)
Webhook.OnFailure(TestService, TestFailure)
assert.Len(t, Webhook.Queue, 1)
})
t.Run("webhooker OnSuccess", func(t *testing.T) {
webhook.OnSuccess(TestService)
assert.Equal(t, len(webhook.Queue), 1)
Webhook.OnSuccess(TestService)
assert.Equal(t, len(Webhook.Queue), 1)
})
t.Run("webhooker Check Back Online", func(t *testing.T) {
@ -89,21 +81,21 @@ func TestWebhookNotifier(t *testing.T) {
})
t.Run("webhooker OnSuccess Again", func(t *testing.T) {
webhook.OnSuccess(TestService)
assert.Equal(t, len(webhook.Queue), 1)
Webhook.OnSuccess(TestService)
assert.Equal(t, len(Webhook.Queue), 1)
})
t.Run("webhooker Send", func(t *testing.T) {
err := webhook.Send(fullMsg)
err := Webhook.Send(fullMsg)
assert.Nil(t, err)
assert.Equal(t, len(webhook.Queue), 1)
assert.Equal(t, len(Webhook.Queue), 1)
})
t.Run("webhooker Queue", func(t *testing.T) {
go notifier.Queue(webhook)
go notifier.Queue(Webhook)
time.Sleep(8 * time.Second)
assert.Equal(t, webhookTestUrl, webhook.Host)
assert.Equal(t, len(webhook.Queue), 0)
assert.Equal(t, webhookTestUrl, Webhook.Host)
assert.Equal(t, len(Webhook.Queue), 0)
})
}

View File

@ -1,6 +1,6 @@
// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at
// 2019-10-24 16:08:58.145719 -0700 PDT m=+0.562621923
// 2019-10-24 23:09:50.152045 -0700 PDT m=+1.326955115
//
// This contains the most recently Markdown source for the Statping Wiki.
package source