handlers

package
v0.0.0-...-72b410f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 11, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MsgTypeNew     = "new"
	MsgTypeResolve = "resolve"
)

Variables

This section is empty.

Functions

func RunCheck

func RunCheck(c *Check)

RunCheck runs a Check and fires an Event with the result for processing

Types

type Check

type Check struct {
	*CheckLoad     `bson:",inline"`
	Attempts       int        `json:"attempts"`
	Duration       float64    `json:"duration"`
	ExecutedAt     time.Time  `json:"executed_at" bson:"executed_at"`
	History        []int      `json:"history"`
	IssuedAt       time.Time  `json:"issued_at" bson:"issued_at"`
	PreviousOutput string     `json:"previous_output" bson:"previous_output"`
	Output         string     `json:"output"`
	Status         int        `json:"status"`
	Handlers       []*Handler `json:"-" bson:"-"`
}

Check represents a check

func NewCheck

func NewCheck() *Check

NewCheck creates a new Check

type CheckLoad

type CheckLoad struct {
	Name         string   `json:"name"`
	Command      string   `json:"command"`
	Interval     int      `json:"interval"`
	MaxAttempts  int      `json:"max_attempts" bson:"max_attempts"`
	HandlerNames []string `json:"handlers" bson:"handlers"`
	Renotify     bool     `json:"renotify"`
}

CheckLoad is used to load a check from a file, and then it gets converted to a Check

type Event

type Event struct {
	*Check
	ID        string    `json:"id" bson:"_id"`
	CreatedAt time.Time `json:"created_at" bson:"created_at"`
}

func NewEvent

func NewEvent(c *Check) *Event

func (*Event) Process

func (e *Event) Process()

type Handler

type Handler struct {
	Name    string        `json:"name"`
	Type    string        `json:"type"`
	Handler HandlerSender `json:"handler,omitempty" bson:"-"`
}

Handler represents a notification handler

func NewConsoleHandler

func NewConsoleHandler() *Handler

NewConsoleHandler creates a consoleHandler instance

func NewSendGridHandler

func NewSendGridHandler(apiKey, subjectPrefix, from, fromName, to, toName string, notifyOnResolve bool) *Handler

NewSendGridHandler creates a sendGridHandler instance

func NewSlackHandler

func NewSlackHandler(channel, token, botUsername, botIconUrl string) *Handler

NewSlackHandler creates a slackHandler instance

type HandlerSender

type HandlerSender interface {
	Send(msg *Message) error
}

HandlerSender is a common interface for all handlers

type Incident

type Incident struct {
	*Check
	ID            string    `json:"id" bson:"_id"`
	Message       *Message  `json:"-" bson:"-"`
	Name          string    `json:"name"`
	CreatedAt     time.Time `json:"created_at" bson:"created_at"`
	LastUpdatedAt time.Time `json:"last_updated_at" bson:"last_updated_at"`
}

func NewIncident

func NewIncident(c *Check) *Incident

func (*Incident) Update

func (i *Incident) Update(output string)

type Message

type Message struct {
	Body  string `json:"body"`
	Title string `json:"title"`
	Type  string `json:"type"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL