mirror of https://github.com/statping/statping
Page:
Notifier Example
Pages
API
AWS EC2
Badges
Build and Test
Bulk Import Services
Cloud Foundry
Commands
Config with .env File
Contributing
Development
Docker Compose
Docker
Environment Variables
Features
GraphQL
Heroku
Home
Issues and Solutions
Linux
Mac Linux Windows
Mac
Makefile
Mobile App
Notifier Events
Notifier Example
Notifiers
PGP Signature
Paid Hosting
Prometheus Exporter
SMTP Emailing
SSL
Sponsor Goal
Static Export
Static HTML Exporter
Terraform
Testing
Types of Monitoring
Windows
config.yml
services.yml
12
Notifier Example
Hunter Long edited this page 2020-05-01 05:42:35 -07:00
Table of Contents
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)
type example struct {
*notifications.Notification
}
func (t *example) Select() *notifications.Notification {
return t.Notification
}
var Example = &example{¬ifications.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 service
func (t *example) OnFailure(s *services.Service, f *failures.Failure) error {
msg := fmt.Sprintf("Your service '%v' is currently offline!", s.Name)
fmt.Println(msg)
return nil
}
// OnSuccess will trigger successful service
func (t *example) OnSuccess(s *services.Service) error {
msg := fmt.Sprintf("Your service '%v' is currently online!", s.Name)
fmt.Println(msg)
return nil
}
// OnTest will test the example notifier
func (t *example) OnTest() (string, error) {
msg := fmt.Sprintf("Testing the Pushover Notifier")
fmt.Println(msg)
return msg, nil
}
Overview
Installation
Extras
Contact
Email: info@statping.com
Badges
Statping.com | Demo | Docker | Notifiers | API