notifications

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: GPL-2.0 Imports: 29 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	source.Config
	// contains filtered or unexported fields
}

Client is an Icinga Notifications compatible client implementation to push events to Icinga Notifications.

A new Client should be created by the NewNotificationsClient function. New history entries can be submitted by calling the Client.Submit method.

func NewNotificationsClient

func NewNotificationsClient(
	ctx context.Context,
	db *database.DB,
	rc *redis.Client,
	logger *logging.Logger,
	cfg source.Config,
) (*Client, error)

NewNotificationsClient creates a new Client connected to an existing database and logger.

func (*Client) Submit

func (client *Client) Submit(entity database.Entity) bool

Submit this database.Entity to the Icinga Notifications API.

Based on the entity's type, a different kind of event will be constructed. The event will be sent to the API in a blocking fashion.

Returns true if this entity was processed or cannot be processed any further. Returns false if this entity should be retried later.

This method usees the Client's logger.

func (*Client) SyncExtraStages

func (client *Client) SyncExtraStages() map[string]history.StageFunc

SyncExtraStages returns a map of history sync keys to history.StageFunc to be used for history.Sync.

Passing the return value of this method as the extraStages parameter to history.Sync results in forwarding events from the Icinga DB history stream to Icinga Notifications after being resorted via the StreamSorter.

type StreamSorter

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

StreamSorter is a helper that can used to intercept messages from different history sync pipelines and passes them to a callback in the order given by their Redis Stream ID (sorted across all involved streams).

After a message is received, it is kept in a priority queue for three seconds to wait for possible messages from another stream with a smaller ID. Thus, if a message is received delayed for more than three seconds, it will be relayed out of order. The StreamSorter is only able to ensure order to a certain degree of chaos.

The callback function receives the redis.XMessage together with the Redis stream name (key) for additional context. The callback function is supposed to return true on success. Otherwise, the callback will be retried until it succeeds.

func NewStreamSorter

func NewStreamSorter(
	ctx context.Context,
	logger *logging.Logger,
	callbackFn func(msg redis.XMessage, key string) bool,
) *StreamSorter

NewStreamSorter creates a StreamSorter honoring the given context and returning elements to the callback function.

func (*StreamSorter) PipelineFunc

func (sorter *StreamSorter) PipelineFunc(
	ctx context.Context,
	_ history.Sync,
	key string,
	in <-chan redis.XMessage,
	out chan<- redis.XMessage,
) error

PipelineFunc implements the history.StageFunc type expected for a history sync pipeline stage.

This method of a single StreamSorter can be inserted into multiple history sync pipelines and will forward all messages from in to out as expected from a pipeline stage. In between, all messages are processed by the StreamSorter, which correlates the messages from different pipelines and additionally passes them to a callback according to its specification (see the comment on the StreamSorter type).

Jump to

Keyboard shortcuts

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