Skip to content

Notifier Example

Hunter Long edited this page May 1, 2020 · 12 revisions

Below is a full example of a Statping notifier which will give you a good example of how to create your own. Insert your new notifier inside the /notifiers folder once your ready!

notifiers/example.go

package notifiers
import (
"fmt""github.com/statping/statping/types/failures""github.com/statping/statping/types/notifications""github.com/statping/statping/types/notifier""github.com/statping/statping/types/services""time"
)
var_ notifier.Notifier= (*example)(nil)
typeexamplestruct {
*notifications.Notification
}
func (t*example) Select() *notifications.Notification {
returnt.Notification
}
varExample=&example{&notifications.Notification{
Method: "example",
Title: "Example Notifier",
Description: "This notifier only prints messages in the console.",
Author: "Hunter Long",
AuthorUrl: "https://github.com/hunterlong",
Icon: "fa dot-circle",
Delay: time.Duration(10*time.Second),
Limits: 60,
Form: []notifications.NotificationForm{{
Type: "text",
Title: "User Token",
Placeholder: "Insert your Token",
DbField: "api_key",
Required: true,
}, {
Type: "text",
Title: "Application API Key",
Placeholder: "Insert something secret here",
DbField: "api_secret",
Required: true,
},
}},
}
// OnFailure will trigger failing servicefunc (t*example) OnFailure(s*services.Service, f*failures.Failure) error {
msg:=fmt.Sprintf("Your service '%v' is currently offline!", s.Name)
fmt.Println(msg)
returnnil
}
// OnSuccess will trigger successful servicefunc (t*example) OnSuccess(s*services.Service) error {
msg:=fmt.Sprintf("Your service '%v' is currently online!", s.Name)
fmt.Println(msg)
returnnil
}
// OnTest will test the example notifierfunc (t*example) OnTest() (string, error) {
msg:=fmt.Sprintf("Testing the Pushover Notifier")
fmt.Println(msg)
returnmsg, nil
}

Clone this wiki locally