icingadb

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: 40 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

View Source
var ErrSchemaMismatch = stderrors.New("unexpected database schema version")

ErrSchemaMismatch implies an unexpected schema version, most likely after Icinga DB was updated but the database missed the schema upgrade.

View Source
var ErrSchemaNotExists = stderrors.New("no database schema exists")

ErrSchemaNotExists implies that no Icinga DB schema has been imported.

Functions

func CheckSchema added in v1.2.1

func CheckSchema(ctx context.Context, db *database.DB) error

CheckSchema verifies the correct database schema is present.

This function returns the following error types, possibly wrapped:

  • If no schema exists, the error returned is ErrSchemaNotExists.
  • If the schema version does not match the expected version, the error returned is ErrSchemaMismatch.
  • Otherwise, the original error is returned, for example in case of general database problems.

func ImportSchema added in v1.3.0

func ImportSchema(
	ctx context.Context,
	db *database.DB,
	databaseSchemaDir string,
) error

ImportSchema performs an initial schema import in the db.

This function assumes that no schema exists. So it should only be called after a prior CheckSchema call.

Note: Running a schema file may have side effects, such as altering SQL system variables. Unless you are certain that the schema update will not interfere with future queries, consider using a dedicated database connection.

Types

type CleanupStmt

type CleanupStmt struct {
	Table  string
	PK     string
	Column string
}

CleanupStmt defines information needed to compose cleanup statements.

func (*CleanupStmt) CleanupOlderThan added in v1.2.1

func (stmt *CleanupStmt) CleanupOlderThan(
	ctx context.Context, db *database.DB, envId types.Binary,
	count uint64, olderThan time.Time, onSuccess ...database.OnSuccess[struct{}],
) (uint64, error)

CleanupOlderThan deletes all rows with the specified statement that are older than the given time. Deletes a maximum of as many rows per round as defined in count. Actually deleted rows will be passed to onSuccess. Returns the total number of rows deleted.

type Delta

type Delta struct {
	Create  EntitiesById
	Update  EntitiesById
	Delete  EntitiesById
	Subject *common.SyncSubject
	// contains filtered or unexported fields
}

Delta calculates the delta of actual and desired entities, and stores which entities need to be created, updated, and deleted.

func NewDelta

func NewDelta(ctx context.Context, actual, desired <-chan database.Entity, subject *common.SyncSubject, logger *logging.Logger) *Delta

NewDelta creates a new Delta and starts calculating it. The caller must ensure that no duplicate entities are sent to the same stream.

func (*Delta) Wait

func (delta *Delta) Wait() error

Wait waits for the delta calculation to complete and returns an error, if any.

type DumpSignals

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

DumpSignals reads dump signals from a Redis stream via Listen. Dump-done signals are passed on via Done channels, while InProgress must be checked for dump-wip signals.

func NewDumpSignals

func NewDumpSignals(redis *redis.Client, logger *logging.Logger) *DumpSignals

NewDumpSignals returns new DumpSignals.

func (*DumpSignals) Done

func (s *DumpSignals) Done(key string) <-chan struct{}

Done returns a channel that is closed when the given key receives a done dump signal.

func (*DumpSignals) InProgress

func (s *DumpSignals) InProgress() <-chan struct{}

InProgress returns a channel that is closed when a new dump is in progress after done signals were sent to channels returned by Done.

func (*DumpSignals) Listen

func (s *DumpSignals) Listen(ctx context.Context) error

Listen starts listening for dump signals in the icinga:dump Redis stream. When a done signal is received, this is signaled via the channels returned from the Done function.

If a wip signal is received after a done signal was passed on via the Done function, this is signaled via the InProgress function and this function returns with err == nil. In this case, all other signals are invalidated. It is up to the caller to pass on this information, for example by cancelling derived contexts.

This function may only be called once for each DumpSignals object. To listen for a new iteration of dump signals, a new DumpSignals instance must be created.

type EntitiesById

type EntitiesById map[string]database.Entity

EntitiesById is a map of key-contracts.Entity pairs.

func (EntitiesById) Entities

func (ebi EntitiesById) Entities(ctx context.Context) <-chan database.Entity

Entities streams the entities on a returned channel.

func (EntitiesById) IDs

func (ebi EntitiesById) IDs() []any

IDs returns the contracts.ID of the entities.

func (EntitiesById) Keys

func (ebi EntitiesById) Keys() []string

Keys returns the keys.

type HA

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

HA provides high availability and indicates whether a Takeover or Handover must be made.

func NewHA

func NewHA(ctx context.Context, db *database.DB, heartbeat *icingaredis.Heartbeat, logger *logging.Logger) *HA

NewHA returns a new HA and starts the controller loop.

func (*HA) Close

func (h *HA) Close(ctx context.Context) error

Close shuts h down.

func (*HA) Done

func (h *HA) Done() <-chan struct{}

Done returns a channel that's closed when the HA controller loop ended.

func (*HA) Environment

func (h *HA) Environment() *v1.Environment

Environment returns the current environment.

func (*HA) Err

func (h *HA) Err() error

Err returns an error if Done has been closed and there is an error. Otherwise returns nil.

func (*HA) Handover

func (h *HA) Handover() chan string

Handover returns a channel with which handovers and their reasons are signaled.

func (*HA) State

func (h *HA) State() (responsibleTsMilli int64, responsible, otherResponsible bool)

State returns the status quo.

func (*HA) Takeover

func (h *HA) Takeover() chan string

Takeover returns a channel with which takeovers and their reasons are signaled.

type RuntimeUpdates

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

RuntimeUpdates specifies the source and destination of runtime updates.

func NewRuntimeUpdates

func NewRuntimeUpdates(db *database.DB, redis *redis.Client, logger *logging.Logger) *RuntimeUpdates

NewRuntimeUpdates creates a new RuntimeUpdates.

func (*RuntimeUpdates) ClearStreams

func (r *RuntimeUpdates) ClearStreams(ctx context.Context) (config, state redis.Streams, err error)

ClearStreams returns the stream key to ID mapping of the runtime update streams for later use in Sync and clears the streams themselves.

func (*RuntimeUpdates) Sync

func (r *RuntimeUpdates) Sync(
	ctx context.Context, factoryFuncs []database.EntityFactoryFunc, streams redis.Streams, allowParallel bool,
) error

Sync synchronizes runtime update streams from s.redis to s.db and deletes the original data on success. Note that Sync must be only be called configuration synchronization has been completed. allowParallel allows synchronizing out of order (not FIFO).

type ScopedEntity

type ScopedEntity struct {
	database.Entity
	// contains filtered or unexported fields
}

ScopedEntity combines an entity and a scope that specifies the WHERE conditions that entities of the enclosed entity type must satisfy in order to be SELECTed.

func NewScopedEntity

func NewScopedEntity(entity database.Entity, scope any) *ScopedEntity

NewScopedEntity returns a new ScopedEntity.

func (ScopedEntity) Scope

func (e ScopedEntity) Scope() any

Scope implements the contracts.Scoper interface.

func (ScopedEntity) TableName

func (e ScopedEntity) TableName() string

TableName implements the contracts.TableNamer interface.

type Sync

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

Sync implements a rendezvous point for Icinga DB and Redis to synchronize their entities.

func NewSync

func NewSync(db *database.DB, redis *redis.Client, logger *logging.Logger) *Sync

NewSync returns a new Sync.

func (Sync) ApplyDelta

func (s Sync) ApplyDelta(ctx context.Context, delta *Delta) error

ApplyDelta applies all changes from Delta to the database.

func (Sync) Sync

func (s Sync) Sync(ctx context.Context, subject *common.SyncSubject) error

Sync synchronizes entities between Icinga DB and Redis created with the specified sync subject. This function does not respect dump signals. For this, use SyncAfterDump.

func (Sync) SyncAfterDump

func (s Sync) SyncAfterDump(ctx context.Context, subject *common.SyncSubject, dump *DumpSignals) error

SyncAfterDump waits for a config dump to finish (using the dump parameter) and then starts a sync for the given sync subject using the Sync function.

func (Sync) SyncCustomvars

func (s Sync) SyncCustomvars(ctx context.Context) error

SyncCustomvars synchronizes customvar and customvar_flat.

Directories

Path Synopsis
v1

Jump to

Keyboard shortcuts

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