alert

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2018 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

func PatternMatch added in v1.3.0

func PatternMatch(pattern, id string) bool

Types

type Data added in v1.3.0

type Data struct {
	ID            string        `json:"id"`
	Message       string        `json:"message"`
	Details       string        `json:"details"`
	Time          time.Time     `json:"time"`
	Duration      time.Duration `json:"duration"`
	Level         Level         `json:"level"`
	Data          models.Result `json:"data"`
	PreviousLevel Level         `json:"previousLevel"`
	Recoverable   bool          `json:"recoverable"`
}

Data 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 Event

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

func (Event) AlertData added in v1.3.0

func (e Event) AlertData() Data

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

	// Category is the category of the alert that generated this event.
	Category 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{}

	Recoverable bool

	Result models.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 Inhibitor added in v1.5.0

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

Inhibitor tracks whether an alert category + tag set have been inhibited

func NewInhibitor added in v1.5.0

func NewInhibitor(category string, tags models.Tags) *Inhibitor

func (*Inhibitor) IsInhibited added in v1.5.0

func (i *Inhibitor) IsInhibited(category string, tags models.Tags) bool

func (*Inhibitor) Set added in v1.5.0

func (i *Inhibitor) Set(inhibited bool)

type InhibitorLookup added in v1.5.0

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

func NewInhibitorLookup added in v1.5.0

func NewInhibitorLookup() *InhibitorLookup

func (*InhibitorLookup) AddInhibitor added in v1.5.0

func (l *InhibitorLookup) AddInhibitor(in *Inhibitor)

func (*InhibitorLookup) IsInhibited added in v1.5.0

func (l *InhibitorLookup) IsInhibited(category string, tags models.Tags) bool

func (*InhibitorLookup) RemoveInhibitor added in v1.5.0

func (l *InhibitorLookup) RemoveInhibitor(in *Inhibitor)

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

func (t *Topic) State() TopicState

type TopicState added in v1.3.0

type TopicState struct {
	Level     Level
	Collected int64
}

type Topics

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

func NewTopics

func NewTopics() *Topics

func (*Topics) Close

func (s *Topics) Close() error

func (*Topics) Collect

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

Collect collects an event and handles the event.

func (*Topics) DeleteTopic

func (s *Topics) DeleteTopic(topic string)

func (*Topics) DeregisterHandler

func (s *Topics) DeregisterHandler(topic 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(topic string, h Handler)

func (*Topics) ReplaceHandler

func (s *Topics) ReplaceHandler(topic 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) TopicState added in v1.3.0

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

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

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