alert

package
v1.2.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2017 License: MIT Imports: 35 Imported by: 0

Documentation

Overview

Alert provides an implementation of the HTTP API for managing alert topics, handlers and events.

Responsibilities of this package include:

* Providing and HTTP API for the management of handlers * Storing handler definitions * Providing implementations of several simple handlers * Mapping external handler implementations to handler definitions

The last item needs some more clarification. Handlers can be implemented in external packages. In order for the HTTP API to consume those implementations a mapping needs to be defined from the HandlerAction definition to the expected configuration of the handler implementation. This package provides that mapping.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrHandlerSpecExists   = errors.New("handler spec already exists")
	ErrNoHandlerSpecExists = errors.New("no handler spec exists")
)
View Source
var (
	ErrNoTopicStateExists = errors.New("no topic state exists")
)

Functions

func NewAggregateHandler

func NewAggregateHandler(c AggregateHandlerConfig, l *log.Logger) handlerAction

func NewExecHandler

func NewExecHandler(c ExecHandlerConfig, l *log.Logger) alert.Handler

func NewLogHandler

func NewLogHandler(c LogHandlerConfig, l *log.Logger) (alert.Handler, error)

func NewPostHandler

func NewPostHandler(c PostHandlerConfig, l *log.Logger) alert.Handler

func NewPublishHandler

func NewPublishHandler(c PublishHandlerConfig, l *log.Logger) alert.Handler

func NewStateChangesOnlyHandler

func NewStateChangesOnlyHandler(c StateChangesOnlyHandlerConfig, l *log.Logger) handlerAction

func NewTCPHandler

func NewTCPHandler(c TCPHandlerConfig, l *log.Logger) alert.Handler

Types

type AggregateHandlerConfig

type AggregateHandlerConfig struct {
	Interval time.Duration `mapstructure:"interval"`
}

type AlertData

type AlertData struct {
	ID       string          `json:"id"`
	Message  string          `json:"message"`
	Details  string          `json:"details"`
	Time     time.Time       `json:"time"`
	Duration time.Duration   `json:"duration"`
	Level    alert.Level     `json:"level"`
	Data     influxql.Result `json:"data"`
}

AlertData is a structure that contains relevant data about an alert event. The structure is intended to be JSON encoded, providing a consistent data format.

type Config

type Config struct {
}

func NewConfig

func NewConfig() Config

type EventState

type EventState struct {
	Message  string        `json:"message"`
	Details  string        `json:"details"`
	Time     time.Time     `json:"time"`
	Duration time.Duration `json:"duration"`
	Level    alert.Level   `json:"level"`
}

type ExecHandlerConfig

type ExecHandlerConfig struct {
	Prog      string            `mapstructure:"prog"`
	Args      []string          `mapstructure:"args"`
	Commander command.Commander `mapstructure:"-"`
}

type HandlerActionSpec

type HandlerActionSpec struct {
	Kind    string                 `json:"kind"`
	Options map[string]interface{} `json:"options"`
}

HandlerActionSpec defines an action an handler can take.

type HandlerSpec

type HandlerSpec struct {
	ID      string              `json:"id"`
	Topics  []string            `json:"topics"`
	Actions []HandlerActionSpec `json:"actions"`
}

HandlerSpec provides all the necessary information to create a handler.

func (HandlerSpec) HasTopic

func (h HandlerSpec) HasTopic(topic string) bool

func (HandlerSpec) MarshalBinary

func (h HandlerSpec) MarshalBinary() ([]byte, error)

func (HandlerSpec) ObjectID

func (h HandlerSpec) ObjectID() string

func (*HandlerSpec) UnmarshalBinary

func (h *HandlerSpec) UnmarshalBinary(data []byte) error

func (HandlerSpec) Validate

func (h HandlerSpec) Validate() error

type HandlerSpecDAO

type HandlerSpecDAO interface {
	// Retrieve a handler
	Get(id string) (HandlerSpec, error)

	// Create a handler.
	// ErrHandlerSpecExists is returned if a handler already exists with the same ID.
	Create(h HandlerSpec) error

	// Replace an existing handler.
	// ErrNoHandlerSpecExists is returned if the handler does not exist.
	Replace(h HandlerSpec) error

	// Delete a handler.
	// It is not an error to delete an non-existent handler.
	Delete(id string) error

	// List handlers matching a pattern.
	// The pattern is shell/glob matching see https://golang.org/pkg/path/#Match
	// Offset and limit are pagination bounds. Offset is inclusive starting at index 0.
	// More results may exist while the number of returned items is equal to limit.
	List(pattern string, offset, limit int) ([]HandlerSpec, error)
}

Data access object for HandlerSpec data.

type LogHandlerConfig

type LogHandlerConfig struct {
	Path string      `mapstructure:"path"`
	Mode os.FileMode `mapstructure:"mode"`
}

func DefaultLogHandlerConfig

func DefaultLogHandlerConfig() LogHandlerConfig

func (LogHandlerConfig) Validate

func (c LogHandlerConfig) Validate() error

type PostHandlerConfig

type PostHandlerConfig struct {
	URL string `mapstructure:"url"`
}

type PublishHandlerConfig

type PublishHandlerConfig struct {
	Topics []string `mapstructure:"topics"`
	// contains filtered or unexported fields
}

type Service

type Service struct {
	HTTPDService interface {
		AddPreviewRoutes([]httpd.Route) error
		DelRoutes([]httpd.Route)
	}
	StorageService interface {
		Store(namespace string) storage.Interface
	}

	Commander command.Commander

	AlertaService interface {
		DefaultHandlerConfig() alerta.HandlerConfig
		Handler(alerta.HandlerConfig, *log.Logger) (alert.Handler, error)
	}
	HipChatService interface {
		Handler(hipchat.HandlerConfig, *log.Logger) alert.Handler
	}
	OpsGenieService interface {
		Handler(opsgenie.HandlerConfig, *log.Logger) alert.Handler
	}
	PagerDutyService interface {
		Handler(pagerduty.HandlerConfig, *log.Logger) alert.Handler
	}
	SensuService interface {
		Handler(*log.Logger) alert.Handler
	}
	SlackService interface {
		Handler(slack.HandlerConfig, *log.Logger) alert.Handler
	}
	SMTPService interface {
		Handler(smtp.HandlerConfig, *log.Logger) alert.Handler
	}
	SNMPTrapService interface {
		Handler(snmptrap.HandlerConfig, *log.Logger) (alert.Handler, error)
	}
	TalkService interface {
		Handler(*log.Logger) alert.Handler
	}
	TelegramService interface {
		Handler(telegram.HandlerConfig, *log.Logger) alert.Handler
	}
	VictorOpsService interface {
		Handler(victorops.HandlerConfig, *log.Logger) alert.Handler
	}
	// contains filtered or unexported fields
}

func NewService

func NewService(c Config, l *log.Logger) *Service

func (*Service) Close

func (s *Service) Close() error

func (*Service) CloseTopic

func (s *Service) CloseTopic(topic string) error

func (*Service) Collect

func (s *Service) Collect(event alert.Event) error

func (*Service) DeleteTopic

func (s *Service) DeleteTopic(topic string) error

func (*Service) DeregisterHandler

func (s *Service) DeregisterHandler(topics []string, h alert.Handler)

func (*Service) DeregisterHandlerSpec

func (s *Service) DeregisterHandlerSpec(id string) error

func (*Service) EventState

func (s *Service) EventState(topic, event string) (alert.EventState, bool)

func (*Service) Handlers

func (s *Service) Handlers(pattern string) []client.Handler

func (*Service) Open

func (s *Service) Open() error

func (*Service) RegisterHandler

func (s *Service) RegisterHandler(topics []string, h alert.Handler)

func (*Service) RegisterHandlerSpec

func (s *Service) RegisterHandlerSpec(spec HandlerSpec) error

func (*Service) ReplaceHandlerSpec

func (s *Service) ReplaceHandlerSpec(oldSpec, newSpec HandlerSpec) error

func (*Service) RestoreTopic

func (s *Service) RestoreTopic(topic string) error

func (*Service) TopicStatus

func (s *Service) TopicStatus(pattern string, minLevel alert.Level) []client.Topic

TopicStatus returns the max alert level for each topic matching 'pattern', not returning any topics with max alert levels less severe than 'minLevel'

func (*Service) TopicStatusEvents

func (s *Service) TopicStatusEvents(pattern string, minLevel alert.Level) map[string]map[string]alert.EventState

TopicStatusDetails is similar to TopicStatus, but will additionally return at least 'minLevel' severity

func (*Service) UpdateEvent

func (s *Service) UpdateEvent(topic string, event alert.EventState) error

type StateChangesOnlyHandlerConfig

type StateChangesOnlyHandlerConfig struct {
	// contains filtered or unexported fields
}

type TCPHandlerConfig

type TCPHandlerConfig struct {
	Address string `mapstructure:"address"`
}

type TopicState

type TopicState struct {
	Topic       string                `json:"topic"`
	EventStates map[string]EventState `json:"event-states"`
}

func (TopicState) MarshalBinary

func (t TopicState) MarshalBinary() ([]byte, error)

func (TopicState) ObjectID

func (t TopicState) ObjectID() string

func (*TopicState) UnmarshalBinary

func (t *TopicState) UnmarshalBinary(data []byte) error

type TopicStateDAO

type TopicStateDAO interface {
	// Retrieve a handler
	Get(id string) (TopicState, error)

	// Put a topic state, replaces any existing state.
	Put(h TopicState) error

	// Delete a handler.
	// It is not an error to delete an non-existent handler.
	Delete(id string) error

	// List handlers matching a pattern.
	// The pattern is shell/glob matching see https://golang.org/pkg/path/#Match
	// Offset and limit are pagination bounds. Offset is inclusive starting at index 0.
	// More results may exist while the number of returned items is equal to limit.
	List(pattern string, offset, limit int) ([]TopicState, error)
}

Data access object for TopicState data.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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