mirror of https://github.com/statping/statping
Updated Notifiers (markdown)
parent
9ba90421d3
commit
bd342b7228
95
Notifiers.md
95
Notifiers.md
|
@ -32,98 +32,3 @@ type BasicEvents interface {
|
|||
OnFailure(*types.Service, *types.Failure)
|
||||
}
|
||||
```
|
||||
|
||||
## Basic Example Notifier
|
||||
Below is a full example of a Statup notifier which will give you a good example of how to create your own.
|
||||
```go
|
||||
package notifiers
|
||||
|
||||
import (
|
||||
"github.com/hunterlong/statup/types"
|
||||
"github.com/hunterlong/statup/core/notifier"
|
||||
)
|
||||
|
||||
type Example struct {
|
||||
*notifier.Notification // create a new struct using *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",
|
||||
Form: []notifier.NotificationForm{{
|
||||
Type: "text",
|
||||
Title: "Host",
|
||||
Placeholder: "Insert your Host here.",
|
||||
DbField: "host",
|
||||
}, {
|
||||
Type: "text",
|
||||
Title: "Username",
|
||||
Placeholder: "Insert your Username here.",
|
||||
DbField: "username",
|
||||
}, {
|
||||
Type: "password",
|
||||
Title: "Password",
|
||||
Placeholder: "Insert your Password here.",
|
||||
DbField: "password",
|
||||
}, {
|
||||
Type: "number",
|
||||
Title: "Port",
|
||||
Placeholder: "Insert your Port here.",
|
||||
DbField: "port",
|
||||
}, {
|
||||
Type: "text",
|
||||
Title: "API Key",
|
||||
Placeholder: "Insert your API Key here",
|
||||
DbField: "api_key",
|
||||
}, {
|
||||
Type: "text",
|
||||
Title: "API Secret",
|
||||
Placeholder: "Insert your API Secret here",
|
||||
DbField: "api_secret",
|
||||
}, {
|
||||
Type: "text",
|
||||
Title: "Var 1",
|
||||
Placeholder: "Insert your Var1 here",
|
||||
DbField: "var1",
|
||||
}, {
|
||||
Type: "text",
|
||||
Title: "Var2",
|
||||
Placeholder: "Var2 goes here",
|
||||
DbField: "var2",
|
||||
}}},
|
||||
}
|
||||
|
||||
// AddNotifier(example) inside init() is required!
|
||||
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
|
||||
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 {
|
||||
return n.Notification
|
||||
}
|
||||
|
||||
func (n *Example) OnSuccess(s *types.Service) {
|
||||
// When a service is successful this function will be triggered!
|
||||
}
|
||||
|
||||
func (n *Example) OnFailure(s *types.Service, f *types.Failure) {
|
||||
// When a service is failing this function will be triggered!
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue