module

package
v1.0.27 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Descriptor

type Descriptor struct {
	Name         string   `json:"name"`         // Unique module identifier
	Version      string   `json:"version"`      // Module version
	Description  string   `json:"description"`  // Human-readable description
	Dependencies []string `json:"dependencies"` // Other modules this depends on
	Optional     bool     `json:"optional"`     // Whether module can be disabled
	ConfigFile   string   `json:"config_file"`  // Path to module's config file
}

Descriptor contains static metadata about a module

type ExtraInfo

type ExtraInfo map[string]any

ExtraInfo holds module-specific status information

type Module

type Module interface {
	// Name returns the unique module identifier
	// Examples: "login-monitor", "suricata-watcher", "feeds-sync"
	Name() string

	// Init initializes the module with the event bus
	// Called once before Start
	// Should set up internal state but NOT start background work
	Init(bus *eventbus.Bus) error

	// Start begins the module's background work
	// Called after Init
	// Should spawn goroutines for continuous work
	// The context is cancelled when the daemon shuts down
	Start(ctx context.Context) error

	// Stop gracefully shuts down the module
	// Called when daemon is stopping
	// Should clean up resources and wait for goroutines to finish
	Stop() error

	// Status returns the current module status
	// Called on demand for health checks and API responses
	Status() Status
}

Module is the interface all nftban modules must implement

type ModuleError

type ModuleError struct {
	Module string
	Op     string
	Err    error
}

ModuleError wraps errors with module context

func (*ModuleError) Error

func (e *ModuleError) Error() string

func (*ModuleError) Unwrap

func (e *ModuleError) Unwrap() error

type Registry

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

Registry manages all registered modules

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new module registry

func (*Registry) All

func (r *Registry) All() map[string]Module

All returns all registered modules

func (*Registry) Get

func (r *Registry) Get(name string) (Module, bool)

Get retrieves a module by name

func (*Registry) GetDescriptor

func (r *Registry) GetDescriptor(name string) (Descriptor, bool)

GetDescriptor retrieves a module descriptor by name

func (*Registry) InitAll

func (r *Registry) InitAll(bus *eventbus.Bus) error

InitAll initializes all modules with the event bus

func (*Registry) Names

func (r *Registry) Names() []string

Names returns all registered module names

func (*Registry) Register

func (r *Registry) Register(m Module, d Descriptor)

Register adds a module to the registry

func (*Registry) StartAll

func (r *Registry) StartAll(ctx context.Context) error

StartAll starts all modules

func (*Registry) StatusAll

func (r *Registry) StatusAll() map[string]Status

StatusAll returns status for all modules

func (*Registry) StopAll

func (r *Registry) StopAll() error

StopAll stops all modules

type Status

type Status struct {
	Name       string    `json:"name"`        // Module name
	Enabled    bool      `json:"enabled"`     // Whether module is enabled in config
	Running    bool      `json:"running"`     // Whether module is currently running
	Healthy    bool      `json:"healthy"`     // Whether module is functioning correctly
	LastRun    time.Time `json:"last_run"`    // Last time module performed its main task
	LastError  string    `json:"last_error"`  // Last error message (empty if none)
	ErrorCount int       `json:"error_count"` // Total errors since start
	EventCount int64     `json:"event_count"` // Total events processed
	StartTime  time.Time `json:"start_time"`  // When module was started
	Uptime     string    `json:"uptime"`      // Human-readable uptime
	Extra      ExtraInfo `json:"extra"`       // Module-specific status info
}

Status contains runtime status information for a module

func NewStatus

func NewStatus(name string) Status

NewStatus creates a new Status with defaults

func (*Status) ClearError

func (s *Status) ClearError()

ClearError clears the last error

func (*Status) MarkRunning

func (s *Status) MarkRunning()

MarkRunning updates status to indicate module is running

func (*Status) MarkStopped

func (s *Status) MarkStopped()

MarkStopped updates status to indicate module is stopped

func (*Status) RecordError

func (s *Status) RecordError(err error)

RecordError records an error

func (*Status) RecordEvent

func (s *Status) RecordEvent()

RecordEvent increments the event counter

func (*Status) UpdateUptime

func (s *Status) UpdateUptime()

UpdateUptime calculates and updates the uptime string

Jump to

Keyboard shortcuts

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