Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
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 ¶
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 ¶
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).