alert

package
v1.5.0-rc3 Latest Latest
Warning

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

Go to latest
Published: May 10, 2018 License: MIT Imports: 47 Imported by: 50

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

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 Diagnostic added in v1.4.0

type Diagnostic interface {
	WithHandlerContext(ctx ...keyvalue.T) HandlerDiagnostic

	MigratingHandlerSpecs()
	FoundHandlerRows(length int)
	FoundNewHandler(key string)
	CreatingNewHandlers(length int)
	MigratingOldHandlerSpec(id string)

	Error(msg string, err error, ctx ...keyvalue.T)
}

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 HandlerDiagnostic added in v1.4.0

type HandlerDiagnostic interface {
	Error(msg string, err error, ctx ...keyvalue.T)
}

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 InhibitorLookup added in v1.5.0

type InhibitorLookup interface {
	IsInhibited(name string, tags models.Tags) bool
	AddInhibitor(*alert.Inhibitor)
	RemoveInhibitor(*alert.Inhibitor)
}

InhibitorLookup provides lookup access to inhibitors

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 {
		AddRoutes([]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, ...keyvalue.T) (alert.Handler, error)
	}
	HipChatService interface {
		Handler(hipchat.HandlerConfig, ...keyvalue.T) alert.Handler
	}
	KafkaService interface {
		Handler(kafka.HandlerConfig, ...keyvalue.T) (alert.Handler, error)
	}
	MQTTService interface {
		Handler(mqtt.HandlerConfig, ...keyvalue.T) alert.Handler
	}
	OpsGenieService interface {
		Handler(opsgenie.HandlerConfig, ...keyvalue.T) alert.Handler
	}
	OpsGenie2Service interface {
		Handler(opsgenie2.HandlerConfig, ...keyvalue.T) alert.Handler
	}
	PagerDutyService interface {
		Handler(pagerduty.HandlerConfig, ...keyvalue.T) alert.Handler
	}
	PagerDuty2Service interface {
		Handler(pagerduty2.HandlerConfig, ...keyvalue.T) alert.Handler
	}
	PushoverService interface {
		Handler(pushover.HandlerConfig, ...keyvalue.T) alert.Handler
	}
	HTTPPostService interface {
		Handler(httppost.HandlerConfig, ...keyvalue.T) alert.Handler
	}
	SensuService interface {
		Handler(sensu.HandlerConfig, ...keyvalue.T) (alert.Handler, error)
	}
	SlackService interface {
		Handler(slack.HandlerConfig, ...keyvalue.T) alert.Handler
	}
	SMTPService interface {
		Handler(smtp.HandlerConfig, ...keyvalue.T) alert.Handler
	}
	SNMPTrapService interface {
		Handler(snmptrap.HandlerConfig, ...keyvalue.T) (alert.Handler, error)
	}
	TalkService interface {
		Handler(...keyvalue.T) alert.Handler
	}
	TelegramService interface {
		Handler(telegram.HandlerConfig, ...keyvalue.T) alert.Handler
	}
	VictorOpsService interface {
		Handler(victorops.HandlerConfig, ...keyvalue.T) alert.Handler
	}
	// contains filtered or unexported fields
}

func NewService

func NewService(d Diagnostic) *Service

func (*Service) AddInhibitor added in v1.5.0

func (s *Service) AddInhibitor(in *alert.Inhibitor)

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) IsInhibited added in v1.5.0

func (s *Service) IsInhibited(name string, tags models.Tags) bool

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) RemoveInhibitor added in v1.5.0

func (s *Service) RemoveInhibitor(in *alert.Inhibitor)

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