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
- Variables
- func CopyFile(src, dest string) (n int64, err error)
- func DeleteV2TopicStore(topicsStore storage.Interface) error
- func LoadTopicBucket(tx storage.ReadOnlyTx, topic []byte) (map[string]EventState, error)
- func MigrateTopicStoreV2V1(storageService StorageService) error
- func NewAggregateHandler(c AggregateHandlerConfig, d HandlerDiagnostic) (alert.Handler, error)
- func NewExecHandler(c ExecHandlerConfig, d HandlerDiagnostic) alert.Handler
- func NewLogHandler(c LogHandlerConfig, d HandlerDiagnostic) (alert.Handler, error)
- func NewPublishHandler(c PublishHandlerConfig, d HandlerDiagnostic) alert.Handler
- func NewTCPHandler(c TCPHandlerConfig, d HandlerDiagnostic) alert.Handler
- func NewTopicStateKV(store storage.Interface) (*topicStateKV, error)
- func WalkTopicBuckets(topicsStore storage.Interface, ...) error
- type AggregateHandlerConfig
- type AnonHandlerRegistrar
- type Config
- type Diagnostic
- type EventCollector
- type EventState
- func (e *EventState) AlertEventState(id string) *alert.EventState
- func (v EventState) MarshalEasyJSON(w *jwriter.Writer)
- func (v EventState) MarshalJSON() ([]byte, error)
- func (e *EventState) Reset()
- func (v *EventState) UnmarshalEasyJSON(l *jlexer.Lexer)
- func (v *EventState) UnmarshalJSON(data []byte) error
- type Events
- type ExecHandlerConfig
- type HandlerDiagnostic
- type HandlerSpec
- type HandlerSpecDAO
- type HandlerSpecRegistrar
- type InhibitorLookup
- type LogHandlerConfig
- type PublishHandlerConfig
- type Service
- func (s *Service) AddInhibitor(in *alert.Inhibitor)
- func (s *Service) Close() error
- func (s *Service) CloseTopic(topic string) error
- func (s *Service) Collect(event alert.Event) error
- func (s *Service) DeleteTopic(topic string) error
- func (s *Service) DeregisterAnonHandler(topic string, h alert.Handler)
- func (s *Service) DeregisterHandlerSpec(topic, handler string) error
- func (s *Service) EventState(topic, event string) (alert.EventState, bool, error)
- func (s *Service) EventStates(topic string, minLevel alert.Level) (map[string]alert.EventState, error)
- func (s *Service) HandlerSpec(topic, handler string) (HandlerSpec, bool, error)
- func (s *Service) HandlerSpecs(topic, pattern string) ([]HandlerSpec, error)
- func (s *Service) IsInhibited(name string, tags models.Tags) bool
- func (s *Service) MigrateTopicStoreV1V2() (rErr error)
- func (s *Service) Open() error
- func (s *Service) RegisterAnonHandler(topic string, h alert.Handler)
- func (s *Service) RegisterHandlerSpec(spec HandlerSpec) error
- func (s *Service) RemoveInhibitor(in *alert.Inhibitor)
- func (s *Service) RestoreTopic(topic string) error
- func (s *Service) TopicState(topic string) (alert.TopicState, bool, error)
- func (s *Service) TopicStates(pattern string, minLevel alert.Level) (map[string]alert.TopicState, error)
- func (s *Service) UpdateEvent(topic string, event alert.EventState) error
- func (s *Service) UpdateHandlerSpec(oldSpec, newSpec HandlerSpec) error
- type StorageService
- type TCPHandlerConfig
- type TopicPersister
- type TopicState
- func (t TopicState) MarshalBinary() ([]byte, error)
- func (v TopicState) MarshalEasyJSON(w *jwriter.Writer)
- func (v TopicState) MarshalJSON() ([]byte, error)
- func (t TopicState) ObjectID() string
- func (t *TopicState) UnmarshalBinary(data []byte) error
- func (v *TopicState) UnmarshalEasyJSON(l *jlexer.Lexer)
- func (v *TopicState) UnmarshalJSON(data []byte) error
- type TopicStateDAO
- type Topics
Constants ¶
const ( TopicStoreVersionKey = "topic_store_version" TopicStoreVersion2 = "2" TopicStoreBackupSuffix = ".v1.bak" )
const ( // The storage namespace V1 topic store and task data. // In V2, still stores handlers AlertNameSpace = "alert_store" // TopicStatesNameSpace - The storage namespace for the V2 topic store and nothing else TopicStatesNameSpace = "topic_states_store" )
const (
DefaultShutdownTimeout = toml.Duration(time.Second * 10)
)
Variables ¶
var ( ErrHandlerSpecExists = errors.New("handler spec already exists") ErrNoHandlerSpecExists = errors.New("no handler spec exists") )
var ErrHandlerDIsabled = errors.New("handler disabled")
var (
ErrNoTopicStateExists = errors.New("no topic state exists")
)
Functions ¶
func DeleteV2TopicStore ¶ added in v1.7.0
func LoadTopicBucket ¶ added in v1.7.0
func LoadTopicBucket(tx storage.ReadOnlyTx, topic []byte) (map[string]EventState, error)
func MigrateTopicStoreV2V1 ¶ added in v1.7.0
func MigrateTopicStoreV2V1(storageService StorageService) error
func NewAggregateHandler ¶
func NewAggregateHandler(c AggregateHandlerConfig, d HandlerDiagnostic) (alert.Handler, error)
func NewExecHandler ¶
func NewExecHandler(c ExecHandlerConfig, d HandlerDiagnostic) alert.Handler
func NewLogHandler ¶
func NewLogHandler(c LogHandlerConfig, d HandlerDiagnostic) (alert.Handler, error)
func NewPublishHandler ¶
func NewPublishHandler(c PublishHandlerConfig, d HandlerDiagnostic) alert.Handler
func NewTCPHandler ¶
func NewTCPHandler(c TCPHandlerConfig, d HandlerDiagnostic) alert.Handler
func NewTopicStateKV ¶ added in v1.7.0
func WalkTopicBuckets ¶ added in v1.7.0
Types ¶
type AggregateHandlerConfig ¶
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 Config ¶
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) Info(msg string, ctx ...keyvalue.T) }
type EventCollector ¶ added in v1.3.0
type EventState ¶
type EventState struct { Message string `json:"message,omitempty"` Details string `json:"details,omitempty"` Time time.Time `json:"time,omitempty"` Duration time.Duration `json:"duration,omitempty"` Level alert.Level `json:"level"` }
func (*EventState) AlertEventState ¶ added in v1.7.0
func (e *EventState) AlertEventState(id string) *alert.EventState
func (EventState) MarshalEasyJSON ¶ added in v1.5.1
func (v EventState) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (EventState) MarshalJSON ¶ added in v1.5.1
func (v EventState) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*EventState) Reset ¶ added in v1.7.0
func (e *EventState) Reset()
func (*EventState) UnmarshalEasyJSON ¶ added in v1.5.1
func (v *EventState) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*EventState) UnmarshalJSON ¶ added in v1.5.1
func (v *EventState) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
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 HandlerDiagnostic ¶ added in v1.4.0
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.ReadOperator, 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.ReadOperator, 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 { PersistTopics bool APIServer *apiServer EventCollector EventCollector HTTPDService interface { AddRoutes([]httpd.Route) error DelRoutes([]httpd.Route) } StorageService StorageService Commander command.Commander AlertaService interface { DefaultHandlerConfig() alerta.HandlerConfig Handler(alerta.HandlerConfig, ...keyvalue.T) (alert.Handler, error) } BigPandaService interface { Handler(bigpanda.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, error) } 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, error) } PushoverService interface { Handler(pushover.HandlerConfig, ...keyvalue.T) alert.Handler } HTTPPostService interface { Handler(httppost.HandlerConfig, ...keyvalue.T) (alert.Handler, error) } SensuService interface { Handler(sensu.HandlerConfig, ...keyvalue.T) (alert.Handler, error) } SlackService interface { Handler(slack.HandlerConfig, ...keyvalue.T) alert.Handler } DiscordService interface { Handler(discord.HandlerConfig, ...keyvalue.T) (alert.Handler, error) } 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 } TeamsService interface { Handler(teams.HandlerConfig, ...keyvalue.T) alert.Handler } ServiceNowService interface { Handler(servicenow.HandlerConfig, ...keyvalue.T) alert.Handler } ZenossService interface { Handler(zenoss.HandlerConfig, ...keyvalue.T) alert.Handler } // contains filtered or unexported fields }
func NewService ¶
func NewService(d Diagnostic, disabled map[string]struct{}, topicBufLen int) *Service
func (*Service) AddInhibitor ¶ added in v1.5.0
func (*Service) CloseTopic ¶
func (*Service) DeleteTopic ¶
func (*Service) DeregisterAnonHandler ¶ added in v1.3.0
func (*Service) DeregisterHandlerSpec ¶
func (*Service) EventState ¶
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 (*Service) MigrateTopicStoreV1V2 ¶ added in v1.7.0
MigrateTopicStoreV1V2 - Convert a V1 to a V2 topic store. Also ensures that a topic store has a V2 version number set.
func (*Service) RegisterAnonHandler ¶ added in v1.3.0
func (*Service) RegisterHandlerSpec ¶
func (s *Service) RegisterHandlerSpec(spec HandlerSpec) error
func (*Service) RemoveInhibitor ¶ added in v1.5.0
func (*Service) RestoreTopic ¶
func (*Service) TopicState ¶ added in v1.3.0
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 StorageService ¶ added in v1.7.0
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) MarshalEasyJSON ¶ added in v1.5.1
func (v TopicState) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (TopicState) MarshalJSON ¶ added in v1.5.1
func (v TopicState) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (TopicState) ObjectID ¶
func (t TopicState) ObjectID() string
func (*TopicState) UnmarshalBinary ¶
func (t *TopicState) UnmarshalBinary(data []byte) error
func (*TopicState) UnmarshalEasyJSON ¶ added in v1.5.1
func (v *TopicState) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*TopicState) UnmarshalJSON ¶ added in v1.5.1
func (v *TopicState) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type TopicStateDAO ¶
type TopicStateDAO interface { Get(id string) (TopicState error) Put(t TopicState) error Replace(t TopicState) error Delete(id string) error List(pattern string, offset, limit int) ([]TopicState, error) Rebuild() error DeleteMultiple(keys []string) error }
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.