channel

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

This section is empty.

Variables

View Source
var (
	// ErrChannelDeleted is used as a cancellation cause when the channel is deleted, allowing the
	// plugin control loop to clean up its state in the database before exiting.
	ErrChannelDeleted = errors.New("channel deleted")
)

Functions

func DeleteStateByIncidentID added in v1.0.0

func DeleteStateByIncidentID(ctx context.Context, db *database.DB, incidentID int64) error

DeleteStateByIncidentID deletes all states associated with a specific incident ID from the database.

func UpsertPlugins

func UpsertPlugins(ctx context.Context, channelPluginDir string, logger *logging.Logger, db *database.DB)

UpsertPlugins upsert the available_channel_type table with working plugins

func ValidateType

func ValidateType(t string) error

ValidateType returns an error if non-allowed chars are detected, nil otherwise.

Types

type Channel

type Channel struct {
	baseconf.IncrementalPkDbEntry[int64] `db:",inline"`

	ExternalUUID types.UUID `db:"external_uuid"`
	Name         string     `db:"name"`
	Type         string     `db:"type"`
	Config       string     `db:"config" json:"-"` // excluded from JSON config dump as this may contain sensitive information

	ValidationResult types.String `db:"validation_result" json:"-"` // excluded from JSON dump for the same reason as Config.

	Logger *zap.SugaredLogger `db:"-"`
	// contains filtered or unexported fields
}

func (*Channel) IncrementalInitAndValidate

func (c *Channel) IncrementalInitAndValidate() error

IncrementalInitAndValidate implements the config.IncrementalConfigurableInitAndValidatable interface.

func (*Channel) MarshalLogObject

func (c *Channel) MarshalLogObject(encoder zapcore.ObjectEncoder) error

MarshalLogObject implements the zapcore.ObjectMarshaler interface.

func (*Channel) Notify

func (c *Channel) Notify(
	ctx context.Context,
	contact *recipient.Contact,
	i *plugin.Incident,
	o *object.Object,
	ev *event.Event,
	summary string,
	body string,
	incidentID int64,
) (*plugin.DeliveryResult, error)

Notify sends a notification about the given incident, object and event to the contact via this channel's plugin.

Only the contact's addresses matching the plugin type are passed to the plugin. If an incident is given and the contact has at least one such address, the channel state for this channel, incident and contact is looked up and included in the request, so the plugin can e.g. reply to a previously sent message.

If the plugin returns a valid state for a non-recovered incident, it is persisted for subsequent notifications. Failures in any of these state operations are logged but don't fail the notification, unless ctx or the plugin context has been canceled.

The provided ctx bounds the whole operation. Canceling it aborts any pending database operation and the RPC call.

It returns the plugin's delivery result (maybe nil) on success, or an error if the notification couldn't be sent.

func (*Channel) Restart

func (c *Channel) Restart(logger *zap.SugaredLogger)

Restart signals to restart the channel plugin with the updated channel config.

func (*Channel) Start

func (c *Channel) Start(ctx context.Context, db *database.DB, logger *zap.SugaredLogger)

Start initializes the channel and starts the plugin control loop in a separate goroutine.

It should be called after the channel has been created and its properties have been set. The provided context is used to manage the lifecycle of the plugin control loop, and the logger is used for logging messages related to the channel and its plugin.

func (*Channel) Stop

func (c *Channel) Stop(chDeleted bool)

Stop cancels the plugin context, which will cause the plugin control loop to exit.

If chDeleted is true, the cancellation cause will be set to ErrChannelDeleted, which signals to the plugin control loop that the channel has been deleted, and it should clean up its state in the database before exiting.

type State added in v1.0.0

type State struct {
	ChannelID    int64 `db:"channel_id" json:"-"`
	IncidentID   int64 `db:"incident_id" json:"-"`
	plugin.State `db:",inline"`
}

State represents a key-value pair associated with a channel, incident and contact in the database.

The plugin will only receive the Key and Value fields, while the other fields are fully managed by the plugin supervisor of that specific channel. Thus, the plugins won't be able to see or modify the ChannelID field, which prevents accidental or malicious tampering with the state of other channels.

func (*State) TableName added in v1.0.0

func (s *State) TableName() string

TableName implements the database.TableNamer interface.

func (*State) Upsert added in v1.0.0

func (s *State) Upsert() any

Upsert implements the database.Upserter interface.

Jump to

Keyboard shortcuts

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