event

package
v1.0.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: 27 Imported by: 0 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

View Source
const (
	// EnvelopeEventVersion defines the version of the event envelope format supported by this node.
	//
	// It is used to ensure compatibility between different versions of the event queue and the event processing logic.
	// Nodes with newer envelope versions are guaranteed to be compatible with older versions, but nodes with older
	// envelope versions may not be able to process events from newer versions.
	EnvelopeEventVersion = 1

	// EnvelopeQAVersion defines the version of the quick action envelope format supported by this node.
	//
	// The comments for EnvelopeEventVersion apply here as well.
	EnvelopeQAVersion = 1
)
View Source
const (

	// QueueStatePending is the initial state for submitting events.
	QueueStatePending int16 = 0
	// QueueStateProcessing is assigned when the ProcessQueue picked this up for processing.
	QueueStateProcessing int16 = 1
	// QueueStateDone is set after ProcessQueue successfully processed the entry.
	QueueStateDone int16 = 2
	// QueueStateError is assigned to invalid events for further processing.
	QueueStateError int16 = 64
)

Variables

This section is empty.

Functions

func Enqueue added in v1.0.0

func Enqueue(ctx context.Context, db *database.DB, ev *Event) error

Enqueue enqueues an event.Event into the job queue.

The internally used database transaction is bound to the provided context. When calling this function from an HTTP handler, pass the request's context to terminate the transaction if the client disconnects prematurely.

func ProcessQueue added in v1.0.0

func ProcessQueue(ctx context.Context, db *database.DB, logger *logging.Logger, cbs QueueCallbacks) error

ProcessQueue processes events from the job queue in the database and invokes the provided callbacks for each event.

This function blocks until either the provided context is canceled, or an unrecoverable error occurs. In either case, a non-nil error is returned.

The callbacks are invoked with a context limited to one minute, and must honor that context.

Types

type Action added in v1.0.0

type Action uint8

Action represents the kind of quick action that can be performed on an incident in Icinga Notifications Web.

const (
	ActionInvalid Action = iota // invalid

	ActionManage      // manage
	ActionUnmanage    // unmanage
	ActionSubscribe   // subscribe
	ActionUnsubscribe // unsubscribe

)

func (Action) String added in v1.0.0

func (i Action) String() string

func (*Action) UnmarshalJSON added in v1.0.0

func (a *Action) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type Envelope added in v1.0.0

type Envelope struct {
	Version uint8       `json:"version"`
	Format  EnvelopeFmt `json:"format"`
	// Time represents the time when this envelope was generated and enqueued into the job queue.
	//
	// It is not part of the Payload so that the SHA256 hash used for deduplication is not affected by the time
	// the event was enqueued. For instance, for every event enqueued by the listener, Time represents the time
	// when the listener received the event, not when the event was generated by the source. So, if the same event
	// is enqueued multiple times, Time will be different, but the SHA256 hash will be the same, allowing the
	// deduplication logic to work correctly.
	Time    types.UnixMilli `json:"time,omitzero"`
	Payload json.RawMessage `json:"payload,omitempty"`
}

Envelope stores metadata about the payload it embodies, such as its version and format.

func (*Envelope) Scan added in v1.0.0

func (e *Envelope) Scan(src any) error

Scan implements the sql.Scanner interface for Envelope.

func (Envelope) Value added in v1.0.0

func (e Envelope) Value() (driver.Value, error)

Value implements the driver.Valuer interface for Envelope.

type EnvelopeFmt added in v1.0.0

type EnvelopeFmt uint8

EnvelopeFmt describes the format of the payload stored in the event queue.

const (
	EnvelopeFmtNone EnvelopeFmt = iota // none

	// EnvelopeFmtEvent indicates that the payload is a JSON representation of an event.Event.
	EnvelopeFmtEvent // event

	// EnvelopeFmtQA indicates that the payload is a JSON representation of an event.QuickAction.
	EnvelopeFmtQA // quick_action

)

func (EnvelopeFmt) MarshalJSON added in v1.0.0

func (f EnvelopeFmt) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (EnvelopeFmt) String added in v1.0.0

func (i EnvelopeFmt) String() string

func (*EnvelopeFmt) UnmarshalJSON added in v1.0.0

func (f *EnvelopeFmt) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type Event

type Event struct {
	Time     time.Time `json:"-"`
	SourceId int64     `json:"source_id"`

	baseEv.Event `json:",inline"`
	// contains filtered or unexported fields
}

Event received of a specified Type for internal processing.

This is a representation of an event received from an external source with additional metadata with sole purpose of being used for internal processing. All the JSON serializable fields are these inherited from the base event type, and are used to decode the request body. Currently, there is no Event being marshalled into its JSON representation.

func (*Event) EvalEqual added in v1.0.0

func (e *Event) EvalEqual(attrs []string, value any) (bool, error)

func (*Event) EvalExists added in v1.0.0

func (e *Event) EvalExists(attrs []string) bool

func (*Event) EvalLess added in v1.0.0

func (e *Event) EvalLess(attrs []string, value any) (bool, error)

func (*Event) EvalLessOrEqual added in v1.0.0

func (e *Event) EvalLessOrEqual(attrs []string, value any) (bool, error)

func (*Event) EvalLike added in v1.0.0

func (e *Event) EvalLike(attrs []string, value any) (bool, error)

func (*Event) ExtractMissingRelations added in v1.0.0

func (e *Event) ExtractMissingRelations(filterColumns ...[]string) []string

ExtractMissingRelations determines which of the given filter columns are missing in the Relations field of this event.

It evaluates the filter columns as JSONPath expressions against the Relations field and returns a list of filter columns as valid JSONPaths that do not have any matching nodes in the Relations field and are not part of the CompleteRelations field. For filter columns that do have matching nodes, it caches the evaluated nodes for potential later use during rules evaluation.

func (*Event) MarshalLogObject added in v1.0.0

func (e *Event) MarshalLogObject(encoder zapcore.ObjectEncoder) error

MarshalLogObject implements the zapcore.ObjectMarshaler interface to allow logging the event as a structured object.

func (*Event) Validate

func (e *Event) Validate() error

Validate validates the current event state. Returns an error if it detects a misconfigured field.

type Queue added in v1.0.0

type Queue struct {
	// ID is the event.Event ID, which is a UUID provided by the source or generated by the listener.
	// It is used to deduplicate events and ensure that the same event is not processed multiple times.
	ID types.UUID `db:"id"`

	// LastUpdate tracks the last modification, used for both processing and retention.
	LastUpdate types.UnixMilli `db:"last_update"`

	// State of the event. Check "QueueState*" consts above.
	State int16 `db:"state"`

	// Envelope is a wrapper around the JSON representation of any processable entity.
	//
	// The Envelope contains the version and format of the payload it embodies. The format denotes the
	// type of the processable entity, while the version is used to determine if the payload needs a
	// migration step before it can be deserialized into a newer version of the processable entity of
	// the same format.
	Envelope Envelope `db:"envelope"`
}

Queue describes an event.Event enqueued for processing in the relational database.

func (*Queue) TableName added in v1.0.0

func (q *Queue) TableName() string

TableName implements database.TableNamer.

type QueueCallbacks added in v1.0.0

type QueueCallbacks struct {
	// GenObjectID is invoked whenever the queue processor needs to determine the object ID for a given event.Event.
	//
	// This should return a unique object ID from the given tags. This function is needed due to import cycles
	// between the event and object packages.
	GenObjectID func(map[string]string) types.Binary

	// ProcessEvent is invoked for each event.Event fetched from the database job queue.
	//
	// The callback must honor the provided context and return an error if the processing failed.
	ProcessEvent func(context.Context, *Event) error

	// QuickAction is the callback function type used by [ProcessQueue] to process a quick action.
	//
	// The callback is invoked with a context limited to one minute, and it must honor this context.
	QuickAction func(context.Context, *QuickAction) error
}

QueueCallbacks describes the callbacks used by ProcessQueue to process events from the database job queue.

type QuickAction added in v1.0.0

type QuickAction struct {
	ID         types.UUID        `json:"-"`
	Time       time.Time         `json:"-"`
	Kind       Action            `json:"action"`
	ContactID  int64             `json:"contact_id"`
	ObjectTags map[string]string `json:"object_tags"`
	EventTypes types.StringList  `json:"event_types"`
}

QuickAction represents a quick action that can be performed on an incident in Icinga Notifications Web.

func (*QuickAction) MarshalLogObject added in v1.0.0

func (qa *QuickAction) MarshalLogObject(enc zapcore.ObjectEncoder) error

MarshalLogObject implements the zapcore.ObjectMarshaler interface.

Jump to

Keyboard shortcuts

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