natsutil

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDeviceLifecycleEventDataNil is returned when device lifecycle event data is nil.
	ErrDeviceLifecycleEventDataNil = errors.New("device lifecycle event data is nil")
	// ErrEventPayloadNil is returned when event payload is nil.
	ErrEventPayloadNil = errors.New("event payload is nil")
)
View Source
var (
	// ErrMTLSRequired is returned when mTLS security is required but not configured
	ErrMTLSRequired = errors.New("mtls security required")
	// ErrCAParsingFailed is returned when CA certificate cannot be parsed
	ErrCAParsingFailed = errors.New("failed to parse CA certificate")
)

Functions

func ConnectWithSecurity

func ConnectWithSecurity(
	_ context.Context, natsURL string, security *models.SecurityConfig, extraOpts ...nats.Option) (*nats.Conn, error)

ConnectWithSecurity creates a NATS connection with security configuration.

func TLSConfig

func TLSConfig(sec *models.SecurityConfig) (*tls.Config, error)

TLSConfig builds a tls.Config for connecting to NATS using mTLS.

Types

type EventPublisher

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

EventPublisher provides methods for publishing OCSF events to NATS JetStream.

func ConnectWithEventPublisher

func ConnectWithEventPublisher(
	ctx context.Context, natsURL, streamName string, opts ...nats.Option) (*EventPublisher, *nats.Conn, error)

ConnectWithEventPublisher creates a NATS connection with JetStream and returns an EventPublisher.

func CreateEventPublisher

func CreateEventPublisher(
	ctx context.Context, nc *nats.Conn, streamName string, subjects []string) (*EventPublisher, error)

CreateEventPublisher creates an EventPublisher for an existing NATS connection.

func CreateEventPublisherWithDomain

func CreateEventPublisherWithDomain(
	ctx context.Context, nc *nats.Conn, domain, streamName string, subjects []string) (*EventPublisher, error)

CreateEventPublisherWithDomain creates an EventPublisher with optional NATS domain support.

func NewEventPublisher

func NewEventPublisher(js jetstream.JetStream, streamName string, subjects []string) *EventPublisher

NewEventPublisher creates a new EventPublisher for the specified stream.

func (*EventPublisher) PublishDeviceLifecycleEvent added in v1.0.55

func (p *EventPublisher) PublishDeviceLifecycleEvent(ctx context.Context, data *models.DeviceLifecycleEventData) error

PublishDeviceLifecycleEvent publishes lifecycle changes (delete, restore, etc.) for a device.

func (*EventPublisher) PublishGatewayFirstSeenEvent added in v1.0.79

func (p *EventPublisher) PublishGatewayFirstSeenEvent(
	ctx context.Context, gatewayID, sourceIP, partition, remoteAddr string, timestamp time.Time) error

PublishGatewayFirstSeenEvent publishes an event when a gateway reports for the first time.

func (*EventPublisher) PublishGatewayHealthEvent added in v1.0.79

func (p *EventPublisher) PublishGatewayHealthEvent(
	ctx context.Context, gatewayID, previousState, currentState string, data *models.GatewayHealthEventData) error

PublishGatewayHealthEvent publishes a gateway health event to the events stream.

func (*EventPublisher) PublishGatewayOfflineEvent added in v1.0.79

func (p *EventPublisher) PublishGatewayOfflineEvent(
	ctx context.Context, gatewayID, sourceIP, partition string, lastSeen time.Time) error

PublishGatewayOfflineEvent publishes a gateway offline event.

func (*EventPublisher) PublishGatewayRecoveryEvent added in v1.0.79

func (p *EventPublisher) PublishGatewayRecoveryEvent(
	ctx context.Context, gatewayID, sourceIP, partition, remoteAddr string, lastSeen time.Time) error

PublishGatewayRecoveryEvent publishes a gateway recovery event.

Jump to

Keyboard shortcuts

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