Statping includes multiple Notifiers to alert you when your services are offline. You can also create your own notifier and send a Push Request to this repo! Creating a custom notifier is pretty easy as long as you follow the requirements. A notifier will automatically be installed into the users Statping database, and form values will save without any hassles. 💃
Example Code | Events | View Notifiers
Notifier Requirements
- Must have a unique
METHOD
name - Struct must have
*notifier.Notification
pointer in it. - Must create and add your notifier variable in
init()
- Should have a form for user to input their variables/keys.
Form: []notifier.NotificationForm
Notifier Interface (required)
Statping has the Notifier
interface which you'll need to include in your notifier. Statping includes many other events/triggers for your notifier, checkout Notifier Events to see all of them.
// Notifier interface is required to create a new Notifier
type Notifier interface {
// OnSuccess is triggered when a service is successful
OnSuccess(*services.Service) error
// OnFailure is triggered when a service is failing
OnFailure(*services.Service, *failures.Failure) error
// OnTest is triggered for testing
OnTest() (string, error)
}
var example = &Example{¬ifier.Notification{
Method: "example", // unique method name
Host: "http://exmaplehost.com", // default 'host' field
Form: []notifier.NotificationForm{{
Type: "text", // text, password, number, or email
Title: "Host", // The title of value in form
Placeholder: "Insert your Host here.", // Optional placeholder in input
DbField: "host", // An accepted DbField value (read below)
}},
}
Notifier Form
Include a form with your notifier so other users can save API keys, username, passwords, and other values.
// NotificationForm contains the HTML fields for each variable/input you want the notifier to accept.
type NotificationForm struct {
Type string `json:"type"` // the html input type (text, password, email)
Title string `json:"title"` // include a title for ease of use
Placeholder string `json:"placeholder"` // add a placeholder for the input
DbField string `json:"field"` // true variable key for input
SmallText string `json:"small_text"` // insert small text under a html input
Required bool `json:"required"` // require this input on the html form
IsHidden bool `json:"hidden"` // hide this form element from end user
IsList bool `json:"list"` // make this form element a comma separated list
IsSwitch bool `json:"switch"` // make the notifier a boolean true/false switch
}
Example Notifier Form
This is the Slack Notifier Form
fields.
Form: []notifier.NotificationForm{{
Type: "text",
Title: "Incoming webhooker Url",
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,
}}
}
Accepted DbField Values
The notifier.NotificationForm
has a field called DbField
which is the column to save the value into the database. Below are the acceptable DbField string names to include in your form.
host
used for a URL or API endpointusername
used for a usernamepassword
used for a passwordport
used for a integer port numberapi_key
used for some kind of API keyapi_secret
used for some API secretvar1
used for any type of stringvar2
used for any type of string (extra)
Form Elements
You can completely custom your notifications to include a detailed form.
Type
is a HTML input type for your fieldTitle
give your input element a titlePlaceholder
optional field if you want a placeholder in inputDbField
required field to save variable into database (read above)Placeholder
optional field for inserting small hint under the input
Adding Notifiers
To add a notifier to the Statping application, simply append your Notifier in the AttachNotifiers()
function inside of core/core.go.
// 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,
)
}
AttachNotifiers
Overview
Installation
Extras
Contact
Email: info@statping.com
Badges
Statping.com | Demo | Docker | Notifiers | API