alert

package
v0.1.65 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	// ID is a unique UUID string identifying this alert
	ID string

	// RuleName is the name of the rule that generated
	// this alert
	RuleName string

	// Method is a set of alert.AlertMethod instances
	// which that the AlertHAndler will use to send
	// alerts
	Methods []Method

	// Records are the processed response data from an
	// Elasticsearch query
	Records []*Record
}

Alert represents a unique set of results from an Elasticsearch query that the AlertHandler sends to the specified outputs.

type Field

type Field struct {
	// Key is a concatenation of any 'key' fields match a filter.
	// See github.com/morningconsult/go-elasticsearch-alerts/internal/jsonpath.GetAll()
	// for more information on how this key is created
	Key string `json:"key" mapstructure:"key"`

	// Count is the number of fields which match a filter
	Count int `json:"doc_count" mapstructure:"doc_count"`
}

Field represents a summary of the query results that match one of the filters specified in the 'filters' field of a rule configuration file.

type Handler added in v0.1.55

type Handler struct {

	// StopCh is used to terminate the Run() loop
	StopCh chan struct{}

	// DoneCh is closed when Run() returns. Once closed,
	// Run() should not be called again
	DoneCh chan struct{}
	// contains filtered or unexported fields
}

Handler is used to send alerts to various outputs.

func NewHandler added in v0.1.55

func NewHandler(config *HandlerConfig) *Handler

NewHandler creates a new *Handler instance.

func (*Handler) Run added in v0.1.55

func (a *Handler) Run(ctx context.Context, outputCh <-chan *Alert)

Run starts the *AlertHandler running. Once started, it waits to receive a new *Alert from outputCh. When it receives the alert, it will attempt to send the alert with the AlertMethods included in the alert. If it fails, it will backoff for a few seconds before trying to send the alert twice more. If it fails all three attempts, it will quit trying to send the alert. Run will return if ctx.Done() or StopCh becomes unblocked. Before returning, it will close the DoneCh. Once DoneCh is closed, Run should not be called again.

type HandlerConfig added in v0.1.55

type HandlerConfig struct {
	Logger hclog.Logger
}

HandlerConfig is used to provide the logger with which the alert handlers will log messages.

type Method added in v0.1.55

type Method interface {
	Write(context.Context, string, []*Record) error
}

Method is used to send alerts to some output.

type Record

type Record struct {
	// Filter is the filter (either one of the elements of
	// the 'filter' array field or the 'body_field' field
	// of a rule configuration file) on which the results
	// of an Elasticsearch query is grouped
	Filter string `json:"filter,omitempty"`

	// Text is any text to be included with this record.
	// This will generally only be non-empty if the Filter
	// is the body field (e.g. 'hits.hits._source'). It is
	// generally just the JSON objects stringified and
	// concatenated
	Text string `json:"text,omitempty"`

	// BodyField is whether this record used the 'body_field'
	// index (per the rule configuration file) to group the
	// Elasticsearch response JSON
	BodyField bool `json:"-"`

	// Fields is the collection of elements of the
	// Elasticsearch response JSON that match the filter.
	// This will be non-empty only when the Filter is not
	// the body field
	Fields []*Field `json:"fields,omitempty"`
}

Record is used to send the results of an Elasticsearch query to the *alert.AlertHandler.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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