notifications

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: GPL-2.0 Imports: 48 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

func CheckIcinga2Version added in v1.6.0

func CheckIcinga2Version(version string) error

CheckIcinga2Version returns an error if the given Icinga 2 version is too old to be used with Icinga Notifications.

Older versions don't write all the state metadata to Redis that is required to reconstruct the history event IDs, so Icinga DB can't submit correct events with them. This is provided since v2.16.6.

func DeriveDeterministicEventUUID added in v1.6.0

func DeriveDeterministicEventUUID(envId types.Binary, eventType, objectName string, ts types.UnixMilli) (types.UUID, types.Binary, error)

DeriveDeterministicEventUUID generates a UUID based on the given environment ID, object name, event type, and timestamp.

The generated UUID is deterministic and can be used to uniquely identify events in Icinga Notifications. It also returns the SHA1 hash of the input data, which can be used for other purposes if needed.

func DeriveDeterministicHistoryEventUUID added in v1.6.0

func DeriveDeterministicHistoryEventUUID(historyId types.Binary) types.UUID

DeriveDeterministicHistoryEventUUID creates a unique event ID for history entries.

In an HA setup, both Icinga DB nodes process the history streams. When Icinga Notifications receives an event with an already known Event.ID, it does not process it twice. So, include a deterministic event ID for history events.

The UUID is seeded by a static and randomly chosen UUID to ensure it can be differentiated from other event types.

func GenSHA1 added in v1.6.0

func GenSHA1(envId types.Binary, host, service string) (types.Binary, error)

GenSHA1 generates a SHA1 hash based on the given environment ID, host name, and service name.

This implementation mimics the Icinga 2 ID generation behavior^1 used to generate all Icinga DB related object IDs, so make sure to keep it in sync with the Icinga 2 implementation.

func HaveSameState added in v1.6.0

func HaveSameState(incident source.Incident, s *v1.State, isService bool) (bool, error)

HaveSameState checks if the given incident and the corresponding database.Entity have the same state.

This function is used to determine if an incident in Icinga Notifications corresponds to the current state of a checkable in Icinga DB. It compares the severity and muted status of the incident with the state of the entity and returns true if they match, false otherwise. If the entity type is unsupported, an error is returned.

func StateToSeverity added in v1.6.0

func StateToSeverity(s *v1.State, isService bool) (event.Severity, error)

StateToSeverity converts a state integer to an event.Severity value.

func Ternary added in v1.6.0

func Ternary[T any](condition bool, trueVal, falseVal T) T

Ternary returns the first argument if the condition is true, otherwise it returns the second argument.

Types

type AlertHistory added in v1.6.0

type AlertHistory struct {
	v1.IdMeta
	v1.EnvironmentMeta
	HistoryID        types.Binary    `db:"history_id"`
	ContactName      types.String    `db:"contact_name"`
	ContactgroupName types.String    `db:"contactgroup_name"`
	ScheduleName     types.String    `db:"schedule_name"`
	ChannelName      string          `db:"channel_name"`
	TriggeredAt      types.UnixMilli `db:"triggered_at"`
	EventMessage     string          `db:"event_message"`
	EventSummary     string          `db:"event_summary"`
}

AlertHistory represents a single notification alert triggered by Icinga Notifications.

type AlertHistoryRef added in v1.6.0

type AlertHistoryRef struct {
	HistoryID     types.Binary    `db:"history_id"`
	HistoryIDUUID types.UUID      `db:"history_id_uuid"`
	HostID        types.Binary    `db:"host_id"`
	ServiceID     types.Binary    `db:"service_id"`
	LastUpdate    types.UnixMilli `db:"last_update"`
}

AlertHistoryRef maps a history.id to the deterministic event UUID submitted to Icinga Notifications.

It's written by Client.Submit after an event is processed and read by Client.SyncAlertHistories to find the history row that a notification history belongs to.

func (*AlertHistoryRef) Upsert added in v1.6.0

func (ahr *AlertHistoryRef) Upsert() any

Upsert implements the database.Upserter interface.

type Client

type Client struct {
	// 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(
	db *database.DB,
	rc *redis.Client,
	logger *logging.Logger,
	cfg config.NotificationsConfig,
	ha *icingadb.HA,
) (*Client, error)

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

If cfg.SynchronizeWithDatabase is false, the Client can be directly used. Otherwise, one initial Client.PersistLockedConfigOnce call and a continuous Client.SynchronizeConfigWithDatabase call for each HA activation is necessary.

func (*Client) ApplyDelta added in v1.6.0

func (client *Client) ApplyDelta(ctx context.Context, delta *icingadb.Delta) error

ApplyDelta applies the given delta to the Icinga Notifications API.

This function is called by the initial config dump after the delta has been calculated. It fetches the current incidents from the Icinga Notifications API and compares them with the delta. If there are any changes, it submits the new or updated events to the API and closes any incidents for deleted objects.

Returns an error only when the provided context is canceled or Redis is unavailable. Otherwise, it will log any errors encountered during the submission of events to the Icinga Notifications API and continue processing the remaining events, but never returns an error for those.

func (*Client) ClearIncidents added in v1.6.0

func (client *Client) ClearIncidents()

ClearIncidents clears the cached incidents previously populated by the Client.ApplyDelta.

This serves two purposes: it allows to free up memory when the incidents are no longer needed, and it allows to force a re-fetch of the incidents from the Icinga Notifications API on the next config dump, e.g. due to HA take over or the like.

This function is safe to call concurrently with Client.ApplyDelta and with itself. A running ApplyDelta call keeps using the incidents it already obtained, but any later call fetches them again, so this should only be called once all ApplyDelta calls of the current config dump have completed.

func (*Client) IsConfigured added in v1.6.0

func (client *Client) IsConfigured() bool

IsConfigured reports whether the Icinga Notifications API client is available.

func (*Client) PersistLockedConfigOnce added in v1.6.0

func (client *Client) PersistLockedConfigOnce(ctx context.Context) error

PersistLockedConfigOnce writes the static Notifications configuration to the database.

This method must only be called once, as the static configuration is not expected to change; subsequent calls return an error without performing any work. If the Client config disabled SynchronizeConfigWithDatabase, the method immediately returns with a nil error.

func (*Client) ReconfiguredCh added in v1.6.0

func (client *Client) ReconfiguredCh() <-chan struct{}

ReconfiguredCh returns a channel that delivers a signal whenever the Icinga Notifications API client is reconfigured.

If DB synchronization is disabled, a nil channel is returned and waiters will block forever.

func (*Client) Submit

func (client *Client) Submit(ctx context.Context, entity database.Entity) error

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 and will be retried with an exponential backoff in case of retryable errors until a non-retryable error occurs (like ctx cancellation) or the deadline is exceeded. In other words, when this method returns an error, then it usually means that there's nothing it can do anymore to successfully submit the event, thus it should be treated as a fatal error.

Note that this function is used as icingadb.RUUpsertFunc for the runtime updates pipeline, so its signature must match the icingadb.RUUpsertFunc type.

func (*Client) SyncAlertHistories added in v1.6.0

func (client *Client) SyncAlertHistories(ctx context.Context) error

SyncAlertHistories periodically fetches notification histories from the API and syncs them with our DB.

It runs indefinitely until the provided context is canceled, at which point it will return the context's error.

func (*Client) SyncCheckOutputs added in v1.6.0

func (client *Client) SyncCheckOutputs(ctx context.Context) error

SyncCheckOutputs periodically syncs the check outputs of all hosts and services to the Icinga Notifications API.

This function fetches the current incidents from the Icinga Notifications API, computes the corresponding object IDs, retrieves all host and service states matching those IDs from Redis, and updates the check outputs in Icinga Notifications if they have changed since the last sync.

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 in parallel to the regular history sync pipeline.

func (*Client) SynchronizeConfigWithDatabase added in v1.6.0

func (client *Client) SynchronizeConfigWithDatabase(ctx context.Context) error

SynchronizeConfigWithDatabase checks the database-stored configuration periodically and applies changes.

This method blocks until the provided context is done. Runtime errors are only reported via the logging. If the Client config disabled SynchronizeConfigWithDatabase, the method immediately returns with a nil error.

At the moment, not all possible env_keys are being consumed, but only those listed on an internal allow list.

Jump to

Keyboard shortcuts

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