alert

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2017 License: MIT Imports: 40 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) (alert.Handler, error)

func NewExecHandler

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

func NewLogHandler

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

func NewPublishHandler

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

func NewTCPHandler

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

Types

type AggregateHandlerConfig

type AggregateHandlerConfig struct {
	ID       string        `mapstructure:"id"`
	Interval time.Duration `mapstructure:"interval"`
	Topic    string        `mapstructure:"topic"`
	Message  string        `mapstructure:"message"`
	// contains filtered or unexported fields
}

type AnonHandlerRegistrar added in v1.3.0

type AnonHandlerRegistrar interface {
	// RegisterHandler registers the handler instance for the listed topics.
	RegisterAnonHandler(topic string, h alert.Handler)
	// DeregisterHandler removes the handler from the listed topics.
	DeregisterAnonHandler(topic string, h alert.Handler)
}

AnonHandlerRegistrar is responsible for directly registering handlers for anonymous topics. This is to be used only when the origin of the handler is not defined by a handler spec.

type EventCollector added in v1.3.0

type EventCollector interface {
	// Collect accepts a new event for processing.
	Collect(event alert.Event) error
}

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 Events added in v1.3.0

type Events interface {
	EventCollector
	// UpdateEvent updates an existing event with a previously known state.
	UpdateEvent(topic string, event alert.EventState) error
	// EventState returns the current events state.
	EventState(topic, event string) (alert.EventState, bool, error)
}

Events is responsible for accepting events for processing and reporting on the state of events.

type ExecHandlerConfig

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

type HandlerSpec

type HandlerSpec struct {
	ID      string                 `json:"id"`
	Topic   string                 `json:"topic"`
	Kind    string                 `json:"kind"`
	Options map[string]interface{} `json:"options"`
	Match   string                 `json:"match"`
}

HandlerSpec provides all the necessary information to create a handler.

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(topic, id string) (HandlerSpec, error)
	GetTx(tx storage.ReadOnlyTx, topic, id string) (HandlerSpec, error)

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

	// Replace an existing handler.
	// ErrNoHandlerSpecExists is returned if the handler does not exist.
	Replace(h HandlerSpec) error
	ReplaceTx(tx storage.Tx, h HandlerSpec) error

	// Delete a handler.
	// It is not an error to delete an non-existent handler.
	Delete(topic, id string) error
	DeleteTx(tx storage.Tx, topic, 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(topic, pattern string, offset, limit int) ([]HandlerSpec, error)
	ListTx(tx storage.ReadOnlyTx, topic, pattern string, offset, limit int) ([]HandlerSpec, error)

	Rebuild() error
}

Data access object for HandlerSpec data.

type HandlerSpecRegistrar added in v1.3.0

type HandlerSpecRegistrar interface {
	// RegisterHandlerSpec saves the handler spec and registers a handler defined by the spec
	RegisterHandlerSpec(spec HandlerSpec) error
	// DeregisterHandlerSpec deletes the handler spec and deregisters the defined handler.
	DeregisterHandlerSpec(topic, id string) error
	// UpdateHandlerSpec updates the old spec with the new spec and takes care of registering new handlers based on the new spec.
	UpdateHandlerSpec(oldSpec, newSpec HandlerSpec) error
	// HandlerSpec returns a handler spec
	HandlerSpec(topic, id string) (HandlerSpec, bool, error)
	// Handlers returns a list of handler specs that match the pattern.
	HandlerSpecs(topic, pattern string) ([]HandlerSpec, error)
}

HandlerSpecRegistrar is responsible for registering and persisting handler spec definitions.

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 PublishHandlerConfig

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

type Service

type Service struct {
	APIServer *apiServer

	EventCollector EventCollector

	HTTPDService interface {
		AddPreviewRoutes([]httpd.Route) error
		DelRoutes([]httpd.Route)
	}

	StorageService interface {
		Store(namespace string) storage.Interface
		Register(name string, store storage.StoreActioner)
		Versions() storage.Versions
	}

	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
	}
	PushoverService interface {
		Handler(pushover.HandlerConfig, *log.Logger) alert.Handler
	}
	HTTPPostService interface {
		Handler(httppost.HandlerConfig, *log.Logger) alert.Handler
	}
	SensuService interface {
		Handler(sensu.HandlerConfig, *log.Logger) (alert.Handler, error)
	}
	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(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) DeregisterAnonHandler added in v1.3.0

func (s *Service) DeregisterAnonHandler(topic string, h alert.Handler)

func (*Service) DeregisterHandlerSpec

func (s *Service) DeregisterHandlerSpec(topic, handler string) error

func (*Service) EventState

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

EventState returns the current state of the event.

func (*Service) EventStates added in v1.3.0

func (s *Service) EventStates(topic string, minLevel alert.Level) (map[string]alert.EventState, error)

EventStates returns the current state of events for the specified topic. Only events greater or equal to minLevel will be returned

func (*Service) HandlerSpec added in v1.3.0

func (s *Service) HandlerSpec(topic, handler string) (HandlerSpec, bool, error)

func (*Service) HandlerSpecs added in v1.3.0

func (s *Service) HandlerSpecs(topic, pattern string) ([]HandlerSpec, error)

func (*Service) Open

func (s *Service) Open() error

func (*Service) RegisterAnonHandler added in v1.3.0

func (s *Service) RegisterAnonHandler(topic string, h alert.Handler)

func (*Service) RegisterHandlerSpec

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

func (*Service) RestoreTopic

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

func (*Service) TopicState added in v1.3.0

func (s *Service) TopicState(topic string) (alert.TopicState, bool, error)

TopicState returns the state for the specified topic.

func (*Service) TopicStates added in v1.3.0

func (s *Service) TopicStates(pattern string, minLevel alert.Level) (map[string]alert.TopicState, error)

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

func (*Service) UpdateEvent

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

func (*Service) UpdateHandlerSpec added in v1.3.0

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

type TCPHandlerConfig

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

type TopicPersister added in v1.3.0

type TopicPersister interface {
	// CloseTopic closes a topic but does not delete its state.
	CloseTopic(topic string) error
	// DeleteTopic closes a topic and deletes all state associated with the topic.
	DeleteTopic(topic string) error
	// RestoreTopic signals that a topic should be restored from persisted state.
	RestoreTopic(topic string) error
}

TopicPersister is responsible for controlling the persistence of topic state.

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)

	Rebuild() error
}

Data access object for TopicState data.

type Topics added in v1.3.0

type Topics interface {
	// TopicState returns the state of the specified topic,
	TopicState(topic string) (alert.TopicState, bool, error)
	// TopicStates returns the state of all topics that match the pattern and have at least minLevel.
	TopicStates(pattern string, minLevel alert.Level) (map[string]alert.TopicState, error)

	// EventState returns the current state of the event.
	EventState(topic, event string) (alert.EventState, bool, error)
	// EventStates returns the current state of events for the specified topic.
	// Only events greater or equal to minLevel will be returned
	EventStates(topic string, minLevel alert.Level) (map[string]alert.EventState, error)
}

Topics is responsible for querying the state of topics and their events.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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