From 4ec3a46732a9419e1159b89f5d0c5043423f4026 Mon Sep 17 00:00:00 2001 From: Jimmy Casey Date: Mon, 30 Sep 2019 17:13:34 +0100 Subject: [PATCH 01/17] Fixed incorrect service status on prompt. Boolean was being evaluated as string. --- source/js/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/js/main.js b/source/js/main.js index 3ddf566d..ee0a1db1 100644 --- a/source/js/main.js +++ b/source/js/main.js @@ -90,7 +90,7 @@ $('.toggle-service').on('click',function(e) { let obj = $(this); let serviceId = obj.attr("data-id"); let online = obj.attr("data-online"); - let d = confirm("Do you want to "+(online ? "stop" : "start")+" checking this service?"); + let d = confirm("Do you want to "+(eval(online) ? "stop" : "start")+" checking this service?"); if (d) { $.ajax({ url: "/api/services/" + serviceId + "/running", From b1bcc67833db2060f6b8d6e9765ce359cd7cbd24 Mon Sep 17 00:00:00 2001 From: Emanuel Bennici Date: Fri, 4 Oct 2019 14:18:57 +0200 Subject: [PATCH 02/17] Add new Field to Core Struct Add Field `UpdateNotify` to `Core` Struct. This Field shows if the User want that only Updates are send, or every Status Message. --- types/core.go | 1 + 1 file changed, 1 insertion(+) diff --git a/types/core.go b/types/core.go index 03756cc2..ca73c684 100644 --- a/types/core.go +++ b/types/core.go @@ -37,6 +37,7 @@ type Core struct { Version string `gorm:"column:version" json:"version"` MigrationId int64 `gorm:"column:migration_id" json:"migration_id,omitempty"` UseCdn NullBool `gorm:"column:use_cdn;default:false" json:"using_cdn,omitempty"` + UpdateNotify NullBool `gorm:"column:update_notify;default:false" json:"update_notify,omitempty"` Timezone float32 `gorm:"column:timezone;default:-8.0" json:"timezone,omitempty"` CreatedAt time.Time `gorm:"column:created_at" json:"created_at"` UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"` From e73993cef2a0d70d04c45e151c81695bece615cc Mon Sep 17 00:00:00 2001 From: Emanuel Bennici Date: Fri, 4 Oct 2019 14:22:20 +0200 Subject: [PATCH 03/17] Add Toggle-Switch to settings HTML Template --- source/tmpl/settings.gohtml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/source/tmpl/settings.gohtml b/source/tmpl/settings.gohtml index 39cd66b1..05324939 100644 --- a/source/tmpl/settings.gohtml +++ b/source/tmpl/settings.gohtml @@ -37,6 +37,20 @@ +
+
+ + + + + + + + + +
+
+
From 29ace420ae90f71b5bbf1d8b12d753ab15ba1c42 Mon Sep 17 00:00:00 2001 From: Emanuel Bennici Date: Fri, 4 Oct 2019 14:22:35 +0200 Subject: [PATCH 04/17] Add `UpdateNotify` Type to saveSettingsHandler() --- handlers/settings.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/handlers/settings.go b/handlers/settings.go index 89b5839b..93976c84 100644 --- a/handlers/settings.go +++ b/handlers/settings.go @@ -62,11 +62,15 @@ func saveSettingsHandler(w http.ResponseWriter, r *http.Request) { timeFloat, _ := strconv.ParseFloat(timezone, 10) app.Timezone = float32(timeFloat) + app.UpdateNotify = types.NewNullBool(form.Get("update_notify") == "true") + app.UseCdn = types.NewNullBool(form.Get("enable_cdn") == "on") core.CoreApp, err = core.UpdateCore(app) if err != nil { utils.Log(3, fmt.Sprintf("issue updating Core: %v", err.Error())) } + + //notifiers.OnSettingsSaved(core.CoreApp.ToCore()) ExecuteResponse(w, r, "settings.gohtml", core.CoreApp, "/settings") } From 4227f3c88f394fe9bc5342b4415f8f3f99c0d1f4 Mon Sep 17 00:00:00 2001 From: Emanuel Bennici Date: Fri, 4 Oct 2019 14:23:07 +0200 Subject: [PATCH 05/17] Add `UPDATENOTIFY` Handler Function --- handlers/function.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/handlers/function.go b/handlers/function.go index d17f1452..7ac44649 100644 --- a/handlers/function.go +++ b/handlers/function.go @@ -63,6 +63,9 @@ var handlerFuncs = func(w http.ResponseWriter, r *http.Request) template.FuncMap "USE_CDN": func() bool { return core.CoreApp.UseCdn.Bool }, + "UPDATENOTIFY": func() bool { + return core.CoreApp.UpdateNotify.Bool + }, "QrAuth": func() string { return fmt.Sprintf("statping://setup?domain=%v&api=%v", core.CoreApp.Domain, core.CoreApp.ApiSecret) }, From d062839b52a721a7c7a28a4aabe25ebc765f5d98 Mon Sep 17 00:00:00 2001 From: Emanuel Bennici Date: Fri, 4 Oct 2019 14:47:56 +0200 Subject: [PATCH 06/17] Add Field `UserNotified` to Service Struct The Field `UserNotified` is to indicate if a User has already been notified about the Downtime of a Service. --- types/service.go | 1 + 1 file changed, 1 insertion(+) diff --git a/types/service.go b/types/service.go index f0435dba..f607064e 100644 --- a/types/service.go +++ b/types/service.go @@ -50,6 +50,7 @@ type Service struct { Checkpoint time.Time `gorm:"-" json:"-"` SleepDuration time.Duration `gorm:"-" json:"-"` LastResponse string `gorm:"-" json:"-"` + UserNotified bool `gorm:"-" json:"-"` /// True if the User was already notified about a Downtime LastStatusCode int `gorm:"-" json:"status_code"` LastOnline time.Time `gorm:"-" json:"last_success"` Failures []FailureInterface `gorm:"-" json:"failures,omitempty"` From 2a3c68201340da0920b775500a4f0fa22396ff3d Mon Sep 17 00:00:00 2001 From: Emanuel Bennici Date: Fri, 4 Oct 2019 14:48:56 +0200 Subject: [PATCH 07/17] Add implementation for `UpdateNotified` Check --- core/notifier/events.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/core/notifier/events.go b/core/notifier/events.go index de9eb1b5..2fd45b61 100644 --- a/core/notifier/events.go +++ b/core/notifier/events.go @@ -19,6 +19,7 @@ import ( "fmt" "github.com/hunterlong/statping/types" "github.com/hunterlong/statping/utils" + "github.com/hunterlong/statping/core" ) // OnSave will trigger a notifier when it has been saved - Notifier interface @@ -38,6 +39,19 @@ func OnFailure(s *types.Service, f *types.Failure) { if !s.AllowNotifications.Bool { return } + + // check if User wants to receive every Status Change + if core.CoreApp.UpdateNotify.Bool { + // send only if User hasn't been already notified about the Downtime + if !s.UserNotified { + s.UserNotified = true + goto sendMessages + } else { + return + } + } + +sendMessages: for _, comm := range AllCommunications { if isType(comm, new(BasicEvents)) && isEnabled(comm) && inLimits(comm) { notifier := comm.(Notifier).Select() @@ -45,7 +59,6 @@ func OnFailure(s *types.Service, f *types.Failure) { comm.(BasicEvents).OnFailure(s, f) } } - } // OnSuccess will be triggered when a service is successful - BasicEvents interface @@ -53,6 +66,12 @@ func OnSuccess(s *types.Service) { if !s.AllowNotifications.Bool { return } + + // check if User wants to receive every Status Change + if core.CoreApp.UpdateNotify.Bool && s.UserNotified { + s.UserNotified = false + } + for _, comm := range AllCommunications { if isType(comm, new(BasicEvents)) && isEnabled(comm) && inLimits(comm) { notifier := comm.(Notifier).Select() @@ -60,7 +79,6 @@ func OnSuccess(s *types.Service) { comm.(BasicEvents).OnSuccess(s) } } - } // OnNewService is triggered when a new service is created - ServiceEvents interface From c9f140f2dcef85be130bba3f555610c73b1e87fb Mon Sep 17 00:00:00 2001 From: Emanuel Bennici Date: Fri, 4 Oct 2019 15:29:26 +0200 Subject: [PATCH 08/17] Update Online Message for Telegram Notifier --- notifiers/telegram.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/notifiers/telegram.go b/notifiers/telegram.go index 000b3292..c8497bb6 100644 --- a/notifiers/telegram.go +++ b/notifiers/telegram.go @@ -20,6 +20,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" "net/url" @@ -99,7 +100,12 @@ func (u *telegram) OnFailure(s *types.Service, f *types.Failure) { func (u *telegram) OnSuccess(s *types.Service) { if !s.Online { u.ResetUniqueQueue(fmt.Sprintf("service_%v", s.Id)) - msg := fmt.Sprintf("Your service '%v' is back online!", s.Name) + var msg interface{} + if core.CoreApp.UpdateNotify.Bool { + msg = core.ReturnService(s).SmallText() + } else { + msg = fmt.Sprintf("Your service '%v' is currently offline!", s.Name) + } u.AddQueue(fmt.Sprintf("service_%v", s.Id), msg) } } From df3eb914ed840bc8f3a5f7f8936f6ab5826f0f0b Mon Sep 17 00:00:00 2001 From: Emanuel Bennici Date: Fri, 4 Oct 2019 15:36:45 +0200 Subject: [PATCH 09/17] Add Email, Mobile and Discord Online Messages --- notifiers/discord.go | 9 ++++++++- notifiers/email.go | 10 +++++++++- notifiers/mobile.go | 10 +++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/notifiers/discord.go b/notifiers/discord.go index 82cb1c70..3bc3730f 100644 --- a/notifiers/discord.go +++ b/notifiers/discord.go @@ -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) } } diff --git a/notifiers/email.go b/notifiers/email.go index dd08e355..fc5f6674 100644 --- a/notifiers/email.go +++ b/notifiers/email.go @@ -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, diff --git a/notifiers/mobile.go b/notifiers/mobile.go index 3cceebf1..4bc146a3 100644 --- a/notifiers/mobile.go +++ b/notifiers/mobile.go @@ -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, From a9b559262ab16ff9d03526f32797eb2d6cdb298e Mon Sep 17 00:00:00 2001 From: Emanuel Bennici Date: Fri, 4 Oct 2019 15:38:40 +0200 Subject: [PATCH 10/17] Update Online Message for Line-Notify Notifier --- notifiers/line_notify.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/notifiers/line_notify.go b/notifiers/line_notify.go index 4e5cd3f8..131d2f4c 100644 --- a/notifiers/line_notify.go +++ b/notifiers/line_notify.go @@ -18,6 +18,7 @@ package notifiers import ( "fmt" "github.com/hunterlong/statping/core/notifier" + "github.com/hunterlong/statping/core" "github.com/hunterlong/statping/types" "github.com/hunterlong/statping/utils" "net/url" @@ -79,8 +80,14 @@ func (u *lineNotifier) OnFailure(s *types.Service, f *types.Failure) { // OnSuccess will trigger successful service func (u *lineNotifier) OnSuccess(s *types.Service) { if !s.Online { + var msg string + if core.CoreApp.UpdateNotify.Bool { + msg = core.ReturnService(s).SmallText() + } else { + msg = fmt.Sprintf("Your Service %v is Back Online", s.Name) + } + u.ResetUniqueQueue(fmt.Sprintf("service_%v", s.Id)) - msg := fmt.Sprintf("Your service '%v' is back online!", s.Name) u.AddQueue(fmt.Sprintf("service_%v", s.Id), msg) } } From 786bfe75fc19b1b413adda7090f7e4bfab9a5b6b Mon Sep 17 00:00:00 2001 From: Emanuel Bennici Date: Fri, 4 Oct 2019 15:40:34 +0200 Subject: [PATCH 11/17] Update Online Message for Twilio Notifier --- notifiers/twilio.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/notifiers/twilio.go b/notifiers/twilio.go index 6dcf9fbd..82a82838 100644 --- a/notifiers/twilio.go +++ b/notifiers/twilio.go @@ -20,6 +20,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" "net/url" @@ -109,7 +110,12 @@ func (u *twilio) OnFailure(s *types.Service, f *types.Failure) { func (u *twilio) OnSuccess(s *types.Service) { if !s.Online { u.ResetUniqueQueue(fmt.Sprintf("service_%v", s.Id)) - msg := fmt.Sprintf("Your service '%v' is back online!", s.Name) + var msg string + if core.CoreApp.UpdateNotify.Bool { + msg = core.ReturnService(s).SmallText() + } else { + msg = fmt.Sprintf("Your Service %v is Back Online", s.Name) + } u.AddQueue(fmt.Sprintf("service_%v", s.Id), msg) } } From d81c525d71b60ae0fa685fa0be403f4ab4fa85f8 Mon Sep 17 00:00:00 2001 From: Emanuel Bennici Date: Fri, 4 Oct 2019 17:18:33 +0200 Subject: [PATCH 12/17] Add new Fields to `Service` Struct Add `UpdateNotify` Field to allow the Notifiers to check if `UpdateNotify` has been enabled in `CoreApp`. Add `DownText` Field to have a default Downtime Text which also has the 'Service has been down for n-Seconds' Text. Add `SuccessNotified` Field to check if a "Success" Message has already been send. This is because the `s.Online` Field is always "false" if the OnSuccess() Function is called of an Notifier. --- types/service.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/types/service.go b/types/service.go index f607064e..a904f980 100644 --- a/types/service.go +++ b/types/service.go @@ -50,7 +50,10 @@ type Service struct { Checkpoint time.Time `gorm:"-" json:"-"` SleepDuration time.Duration `gorm:"-" json:"-"` LastResponse string `gorm:"-" json:"-"` - UserNotified bool `gorm:"-" json:"-"` /// True if the User was already notified about a Downtime + UserNotified bool `gorm:"-" json:"-"` // True if the User was already notified about a Downtime + UpdateNotify bool `gorm:"-" json:"-"` // This Variable is a simple copy of `core.CoreApp.UpdateNotify.Bool` + DownText string `gorm:"-" json:"-"` // Contains the current generated Downtime Text + SuccessNotified bool `gorm:"-" json:"-"` // Is 'true' if the user has already be informed that the Services now again available LastStatusCode int `gorm:"-" json:"status_code"` LastOnline time.Time `gorm:"-" json:"last_success"` Failures []FailureInterface `gorm:"-" json:"failures,omitempty"` From e1c41966e4d81b31f4034be1196008e1cdd9f4a1 Mon Sep 17 00:00:00 2001 From: Emanuel Bennici Date: Fri, 4 Oct 2019 17:23:20 +0200 Subject: [PATCH 13/17] Add implementation of new `Service` Fields in checker.go Add Variable Value changes of `SuccessNOtified`, `UpdateNotify` and `DownText` to checker.go. So the Values can be used in other packages. --- core/checker.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/checker.go b/core/checker.go index 6eff907e..2f837f80 100644 --- a/core/checker.go +++ b/core/checker.go @@ -263,6 +263,7 @@ func recordSuccess(s *Service) { s.CreateHit(hit) s.Online = true notifier.OnSuccess(s.Service) + s.SuccessNotified = true } // recordFailure will create a new 'Failure' record in the database for a offline service @@ -277,5 +278,8 @@ func recordFailure(s *Service, issue string) { utils.Log(2, fmt.Sprintf("Service %v Failing: %v | Lookup in: %0.2f ms", s.Name, issue, fail.PingTime*1000)) s.CreateFailure(fail) s.Online = false + s.SuccessNotified = false + s.UpdateNotify = CoreApp.UpdateNotify.Bool + s.DownText = s.DowntimeText() notifier.OnFailure(s.Service, fail.Failure) } From 2534078e116fd0a1c9533bcbdf467da62a385ea6 Mon Sep 17 00:00:00 2001 From: Emanuel Bennici Date: Fri, 4 Oct 2019 17:24:28 +0200 Subject: [PATCH 14/17] Switch to new Service-Fields in events.go --- core/notifier/events.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/notifier/events.go b/core/notifier/events.go index 2fd45b61..a6a93246 100644 --- a/core/notifier/events.go +++ b/core/notifier/events.go @@ -19,7 +19,6 @@ import ( "fmt" "github.com/hunterlong/statping/types" "github.com/hunterlong/statping/utils" - "github.com/hunterlong/statping/core" ) // OnSave will trigger a notifier when it has been saved - Notifier interface @@ -41,7 +40,7 @@ func OnFailure(s *types.Service, f *types.Failure) { } // check if User wants to receive every Status Change - if core.CoreApp.UpdateNotify.Bool { + if s.UpdateNotify { // send only if User hasn't been already notified about the Downtime if !s.UserNotified { s.UserNotified = true @@ -68,7 +67,7 @@ func OnSuccess(s *types.Service) { } // check if User wants to receive every Status Change - if core.CoreApp.UpdateNotify.Bool && s.UserNotified { + if s.UpdateNotify && s.UserNotified { s.UserNotified = false } From 6ba5d53a504685bce3dd7278b225b66cf9e47406 Mon Sep 17 00:00:00 2001 From: Emanuel Bennici Date: Fri, 4 Oct 2019 17:25:03 +0200 Subject: [PATCH 15/17] Remove `/core` include from notifier Package Since we have special Fields for that prupose we can remove the `core` Package include. --- notifiers/discord.go | 1 - notifiers/email.go | 1 - notifiers/line_notify.go | 1 - notifiers/mobile.go | 1 - notifiers/telegram.go | 1 - notifiers/twilio.go | 1 - 6 files changed, 6 deletions(-) diff --git a/notifiers/discord.go b/notifiers/discord.go index 3bc3730f..7fd6beeb 100644 --- a/notifiers/discord.go +++ b/notifiers/discord.go @@ -21,7 +21,6 @@ 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" diff --git a/notifiers/email.go b/notifiers/email.go index fc5f6674..9d8a65d9 100644 --- a/notifiers/email.go +++ b/notifiers/email.go @@ -20,7 +20,6 @@ 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" diff --git a/notifiers/line_notify.go b/notifiers/line_notify.go index 131d2f4c..5f0c5bf4 100644 --- a/notifiers/line_notify.go +++ b/notifiers/line_notify.go @@ -18,7 +18,6 @@ package notifiers import ( "fmt" "github.com/hunterlong/statping/core/notifier" - "github.com/hunterlong/statping/core" "github.com/hunterlong/statping/types" "github.com/hunterlong/statping/utils" "net/url" diff --git a/notifiers/mobile.go b/notifiers/mobile.go index 4bc146a3..d91eb121 100644 --- a/notifiers/mobile.go +++ b/notifiers/mobile.go @@ -19,7 +19,6 @@ 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" diff --git a/notifiers/telegram.go b/notifiers/telegram.go index c8497bb6..692843e0 100644 --- a/notifiers/telegram.go +++ b/notifiers/telegram.go @@ -20,7 +20,6 @@ import ( "errors" "fmt" "github.com/hunterlong/statping/core/notifier" - "github.com/hunterlong/statping/core" "github.com/hunterlong/statping/types" "github.com/hunterlong/statping/utils" "net/url" diff --git a/notifiers/twilio.go b/notifiers/twilio.go index 82a82838..12e1c8ca 100644 --- a/notifiers/twilio.go +++ b/notifiers/twilio.go @@ -20,7 +20,6 @@ import ( "errors" "fmt" "github.com/hunterlong/statping/core/notifier" - "github.com/hunterlong/statping/core" "github.com/hunterlong/statping/types" "github.com/hunterlong/statping/utils" "net/url" From d462e54053db4c1e7d43811755abd010b266d557 Mon Sep 17 00:00:00 2001 From: Emanuel Bennici Date: Fri, 4 Oct 2019 17:25:57 +0200 Subject: [PATCH 16/17] Replace all `core.*` Code Lines from notifier Package Replace all `core.*` Code Lines from notifier Package with the new Fields of the Service-Struct. --- notifiers/discord.go | 9 ++++----- notifiers/email.go | 9 ++++----- notifiers/line_notify.go | 9 ++++----- notifiers/mobile.go | 9 ++++----- notifiers/telegram.go | 10 +++++----- notifiers/twilio.go | 10 +++++----- 6 files changed, 26 insertions(+), 30 deletions(-) diff --git a/notifiers/discord.go b/notifiers/discord.go index 7fd6beeb..2d9c345b 100644 --- a/notifiers/discord.go +++ b/notifiers/discord.go @@ -75,14 +75,13 @@ func (u *discord) OnFailure(s *types.Service, f *types.Failure) { // OnSuccess will trigger successful service func (u *discord) OnSuccess(s *types.Service) { - if !s.Online { + if !s.Online || !s.SuccessNotified { u.ResetUniqueQueue(fmt.Sprintf("service_%v", s.Id)) 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) + if s.UpdateNotify { + s.UpdateNotify = false } + msg = s.DownText u.AddQueue(fmt.Sprintf("service_%v", s.Id), msg) } diff --git a/notifiers/email.go b/notifiers/email.go index 9d8a65d9..d57beee1 100644 --- a/notifiers/email.go +++ b/notifiers/email.go @@ -198,13 +198,12 @@ 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 { + if !s.Online || !s.SuccessNotified { var msg string - if core.CoreApp.UpdateNotify.Bool { - msg = core.ReturnService(s).SmallText() - } else { - msg = fmt.Sprintf("Service %v is Back Online", s.Name) + if s.UpdateNotify { + s.UpdateNotify = false } + msg = s.DownText u.ResetUniqueQueue(fmt.Sprintf("service_%v", s.Id)) email := &emailOutgoing{ diff --git a/notifiers/line_notify.go b/notifiers/line_notify.go index 5f0c5bf4..069de7ef 100644 --- a/notifiers/line_notify.go +++ b/notifiers/line_notify.go @@ -78,13 +78,12 @@ func (u *lineNotifier) OnFailure(s *types.Service, f *types.Failure) { // OnSuccess will trigger successful service func (u *lineNotifier) OnSuccess(s *types.Service) { - if !s.Online { + if !s.Online || !s.SuccessNotified { var msg string - if core.CoreApp.UpdateNotify.Bool { - msg = core.ReturnService(s).SmallText() - } else { - msg = fmt.Sprintf("Your Service %v is Back Online", s.Name) + if s.UpdateNotify { + s.UpdateNotify = false } + msg = s.DownText u.ResetUniqueQueue(fmt.Sprintf("service_%v", s.Id)) u.AddQueue(fmt.Sprintf("service_%v", s.Id), msg) diff --git a/notifiers/mobile.go b/notifiers/mobile.go index d91eb121..ed238580 100644 --- a/notifiers/mobile.go +++ b/notifiers/mobile.go @@ -105,13 +105,12 @@ func (u *mobilePush) OnFailure(s *types.Service, f *types.Failure) { // OnSuccess will trigger successful service func (u *mobilePush) OnSuccess(s *types.Service) { data := dataJson(s, nil) - if !s.Online { + if !s.Online || !s.SuccessNotified { 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) + if s.UpdateNotify { + s.UpdateNotify = false } + msgStr = s.DownText u.ResetUniqueQueue(fmt.Sprintf("service_%v", s.Id)) msg := &pushArray{ diff --git a/notifiers/telegram.go b/notifiers/telegram.go index 692843e0..6215cf43 100644 --- a/notifiers/telegram.go +++ b/notifiers/telegram.go @@ -97,14 +97,14 @@ func (u *telegram) OnFailure(s *types.Service, f *types.Failure) { // OnSuccess will trigger successful service func (u *telegram) OnSuccess(s *types.Service) { - if !s.Online { + if !s.Online || !s.SuccessNotified { u.ResetUniqueQueue(fmt.Sprintf("service_%v", s.Id)) var msg interface{} - if core.CoreApp.UpdateNotify.Bool { - msg = core.ReturnService(s).SmallText() - } else { - msg = fmt.Sprintf("Your service '%v' is currently offline!", s.Name) + if s.UpdateNotify { + s.UpdateNotify = false } + msg = s.DownText + u.AddQueue(fmt.Sprintf("service_%v", s.Id), msg) } } diff --git a/notifiers/twilio.go b/notifiers/twilio.go index 12e1c8ca..e660173d 100644 --- a/notifiers/twilio.go +++ b/notifiers/twilio.go @@ -107,14 +107,14 @@ func (u *twilio) OnFailure(s *types.Service, f *types.Failure) { // OnSuccess will trigger successful service func (u *twilio) OnSuccess(s *types.Service) { - if !s.Online { + if !s.Online || !s.SuccessNotified { u.ResetUniqueQueue(fmt.Sprintf("service_%v", s.Id)) var msg string - if core.CoreApp.UpdateNotify.Bool { - msg = core.ReturnService(s).SmallText() - } else { - msg = fmt.Sprintf("Your Service %v is Back Online", s.Name) + if s.UpdateNotify { + s.UpdateNotify = false } + msg = s.DownText + u.AddQueue(fmt.Sprintf("service_%v", s.Id), msg) } } From ca2a7e69ba06919a90b31055fd8251c19ce11984 Mon Sep 17 00:00:00 2001 From: Kanin Peanviriyakulkit Date: Wed, 9 Oct 2019 15:46:40 +0700 Subject: [PATCH 17/17] Update line_notify.go I think we should send notify when update the Access token. --- notifiers/line_notify.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/notifiers/line_notify.go b/notifiers/line_notify.go index 4e5cd3f8..8ab5ab6c 100644 --- a/notifiers/line_notify.go +++ b/notifiers/line_notify.go @@ -87,7 +87,8 @@ func (u *lineNotifier) OnSuccess(s *types.Service) { // OnSave triggers when this notifier has been saved func (u *lineNotifier) OnSave() error { - utils.Log(1, fmt.Sprintf("Notification %v is receiving updated information.", u.Method)) - // Do updating stuff here + msg := fmt.Sprintf("Notification %v is receiving updated information.", u.Method) + utils.Log(1, msg) + u.AddQueue("saved", message) return nil }