alert

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2017 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Alert provides a framework for tracking events in a publish subscribe system. Events are published to topics and handlers consume the events from the topics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Topic string
	State EventState
	Data  EventData
	// contains filtered or unexported fields
}

func (Event) PreviousState

func (e Event) PreviousState() EventState

func (Event) TemplateData

func (e Event) TemplateData() TemplateData

type EventData

type EventData struct {
	// Measurement name
	Name string

	// TaskName is the name of the task that generated this event.
	TaskName string

	// Concatenation of all group-by tags of the form [key=value,]+.
	// If not groupBy is performed equal to literal 'nil'
	Group string

	// Map of tags
	Tags map[string]string

	// Fields of alerting data point.
	Fields map[string]interface{}

	Result influxql.Result
}

type EventState

type EventState struct {
	ID       string
	Message  string
	Details  string
	Time     time.Time
	Duration time.Duration
	Level    Level
}

type Handler

type Handler interface {
	// Handle is responsible for taking action on the event.
	Handle(event Event)
}

type Level

type Level int
const (
	OK Level = iota
	Info
	Warning
	Critical
)

func ParseLevel

func ParseLevel(s string) (l Level, err error)

func (Level) MarshalText

func (l Level) MarshalText() ([]byte, error)

func (Level) String

func (l Level) String() string

func (*Level) UnmarshalText

func (l *Level) UnmarshalText(text []byte) error

type TemplateData

type TemplateData struct {
	// The ID of the alert.
	ID string

	// The Message of the Alert
	Message string

	// Alert Level, one of: INFO, WARNING, CRITICAL.
	Level string

	// Time the event occurred.
	Time time.Time

	// Duration of the event
	Duration time.Duration

	// Measurement name
	Name string

	// Task name
	TaskName string

	// Concatenation of all group-by tags of the form [key=value,]+.
	// If not groupBy is performed equal to literal 'nil'
	Group string

	// Map of tags
	Tags map[string]string

	// Fields of alerting data point.
	Fields map[string]interface{}
}

TemplateData is a structure containing all information available to use in templates for an Event.

type Topic

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

func (*Topic) Collected

func (t *Topic) Collected() int64

func (*Topic) EventState

func (t *Topic) EventState(event string) (EventState, bool)

func (*Topic) EventStates

func (t *Topic) EventStates(minLevel Level) map[string]EventState

func (*Topic) ID

func (t *Topic) ID() string

func (*Topic) MaxLevel

func (t *Topic) MaxLevel() Level

func (*Topic) Status

func (t *Topic) Status() TopicStatus

type TopicStatus

type TopicStatus struct {
	Level     Level
	Collected int64
}

type Topics

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

func NewTopics

func NewTopics(l *log.Logger) *Topics

func (*Topics) Close

func (s *Topics) Close() error

func (*Topics) Collect

func (s *Topics) Collect(event Event) error

func (*Topics) DeleteTopic

func (s *Topics) DeleteTopic(topic string)

func (*Topics) DeregisterHandler

func (s *Topics) DeregisterHandler(topics []string, h Handler)

func (*Topics) EventState

func (s *Topics) EventState(topic, event string) (EventState, bool)

func (*Topics) Open

func (s *Topics) Open() error

func (*Topics) RegisterHandler

func (s *Topics) RegisterHandler(topics []string, h Handler)

func (*Topics) ReplaceHandler

func (s *Topics) ReplaceHandler(oldTopics, newTopics []string, oldH, newH Handler)

func (*Topics) RestoreTopic

func (s *Topics) RestoreTopic(id string, eventStates map[string]EventState)

func (*Topics) Topic

func (s *Topics) Topic(id string) (*Topic, bool)

func (*Topics) TopicStatus

func (s *Topics) TopicStatus(pattern string, minLevel Level) map[string]TopicStatus

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

func (*Topics) TopicStatusEvents

func (s *Topics) TopicStatusEvents(pattern string, minLevel Level) map[string]map[string]EventState

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

func (*Topics) UpdateEvent

func (s *Topics) UpdateEvent(id string, event EventState)

Jump to

Keyboard shortcuts

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