From b58656000f240880c94497d881b2f8135ab7d155 Mon Sep 17 00:00:00 2001 From: Hunter Long Date: Fri, 14 Sep 2018 18:25:48 -0700 Subject: [PATCH] Updated Notifier Example (markdown) --- Notifier-Example.md | 119 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 95 insertions(+), 24 deletions(-) diff --git a/Notifier-Example.md b/Notifier-Example.md index aeb4142..13b3304 100644 --- a/Notifier-Example.md +++ b/Notifier-Example.md @@ -4,26 +4,30 @@ Below is a full example of a Statup notifier which will give you a good example package notifiers import ( + "errors" + "fmt" "github.com/hunterlong/statup/types" "github.com/hunterlong/statup/core/notifier" + "time" ) type Example struct { - *notifier.Notification // create a new struct using *Notification + *notifier.Notification } -const ( - EXAMPLE_METHOD = "example" // give your notifier a unique name (no spaces) -) - var example = &Example{¬ifier.Notification{ - Method: EXAMPLE_METHOD, - Host: "http://exmaplehost.com", + Method: METHOD, + Title: "Example", + Description: "Example Notifier", + Author: "Hunter Long", + AuthorUrl: "https://github.com/hunterlong", + Delay: time.Duration(5 * time.Second), Form: []notifier.NotificationForm{{ Type: "text", Title: "Host", Placeholder: "Insert your Host here.", DbField: "host", + SmallText: "this is where you would put the host", }, { Type: "text", Title: "Username", @@ -59,36 +63,103 @@ var example = &Example{¬ifier.Notification{ Title: "Var2", Placeholder: "Var2 goes here", DbField: "var2", - }}}, -} + }}, +}} -// AddNotifier(example) inside init() is required! +// REQUIRED init() will install/load the notifier func init() { notifier.AddNotifier(example) } -// Run is required for the Notifier interface -func (n *Example) Run() error { - // this function can be a go routine if you need it +// REQUIRED - Send is where you would put the action's of your notifier +func (n *Example) Send(msg interface{}) error { + message := msg.(string) + fmt.Printf("i received this string: %v\n", message) return nil } -// OnSave is required for the Notifier interface -func (n *Example) OnSave() error { - // this function is triggered when the notifier's form is saved - return nil -} - -// Select is required for the Notifier interface -func (n *Example) Select() *Notification { +// REQUIRED +func (n *Example) Select() *notifier.Notification { return n.Notification } -func (n *Example) OnSuccess(s *types.Service) { - // When a service is successful this function will be triggered! +// REQUIRED +func (n *Example) OnSave() error { + msg := fmt.Sprintf("received on save trigger") + n.AddQueue(msg) + return nil } +// REQUIRED +func (n *Example) Test() error { + msg := fmt.Sprintf("received a test trigger\n") + n.AddQueue(msg) + return nil +} + +// REQUIRED - BASIC EVENT +func (n *Example) OnSuccess(s *types.Service) { + msg := fmt.Sprintf("received a count trigger for service: %v\n", s.Name) + n.AddQueue(msg) +} + +// REQUIRED - BASIC EVENT func (n *Example) OnFailure(s *types.Service, f *types.Failure) { - // When a service is failing this function will be triggered! + msg := fmt.Sprintf("received a failure trigger for service: %v\n", s.Name) + n.AddQueue(msg) +} + +// OPTIONAL +func (n *Example) OnNewService(s *types.Service) { + msg := fmt.Sprintf("received a new service trigger for service: %v\n", s.Name) + n.AddQueue(msg) +} + +// OPTIONAL +func (n *Example) OnUpdatedService(s *types.Service) { + msg := fmt.Sprintf("received a update service trigger for service: %v\n", s.Name) + n.AddQueue(msg) +} + +// OPTIONAL +func (n *Example) OnDeletedService(s *types.Service) { + msg := fmt.Sprintf("received a delete service trigger for service: %v\n", s.Name) + n.AddQueue(msg) +} + +// OPTIONAL +func (n *Example) OnNewUser(s *types.User) { + msg := fmt.Sprintf("received a new user trigger for user: %v\n", s.Username) + n.AddQueue(msg) +} + +// OPTIONAL +func (n *Example) OnUpdatedUser(s *types.User) { + msg := fmt.Sprintf("received a updated user trigger for user: %v\n", s.Username) + n.AddQueue(msg) +} + +// OPTIONAL +func (n *Example) OnDeletedUser(s *types.User) { + msg := fmt.Sprintf("received a deleted user trigger for user: %v\n", s.Username) + n.AddQueue(msg) +} + +// OPTIONAL +func (n *Example) OnUpdatedCore(s *types.Core) { + msg := fmt.Sprintf("received a updated core trigger for core: %v\n", s.Name) + n.AddQueue(msg) +} + +// OPTIONAL +func (n *Example) OnNewNotifier(s *Notification) { + msg := fmt.Sprintf("received a new notifier trigger for notifier: %v\n", s.Method) + n.AddQueue(msg) +} + +// OPTIONAL +func (n *Example) OnUpdatedNotifier(s *Notification) { + msg := fmt.Sprintf("received a update notifier trigger for notifier: %v\n", s.Method) + n.AddQueue(msg) } ``` \ No newline at end of file