agent

package
v1.0.78 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2025 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Overview

Package agent pkg/agent/checker.go

Package agent pkg/agent/mapper_checker.go

Package agent is a generated GoMock package.

Package agent pkg/agent/registry.go

Package agent pkg/agent/server.go

Package agent pkg/agent/types.go

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAgentIDRequired indicates agent_id is required in configuration
	ErrAgentIDRequired = errors.New("agent_id is required in configuration")
	// ErrInvalidJSONResponse indicates invalid JSON response from checker
	ErrInvalidJSONResponse = errors.New("invalid JSON response from checker")
	// ErrDataServiceClientInit indicates the DataService client could not be created.
	ErrDataServiceClientInit = errors.New("failed to initialize DataService client")
	// ErrInvalidSweepMetadata signals that stored sweep metadata is malformed.
	ErrInvalidSweepMetadata = errors.New("invalid sweep metadata")
	// ErrObjectStoreUnavailable is returned when the object store client is not available.
	ErrObjectStoreUnavailable = errors.New("object store unavailable")
)
View Source
var (
	// ErrDetailsRequiredMapperDiscovery indicates details field is required for mapper_discovery checks
	ErrDetailsRequiredMapperDiscovery = errors.New("details field is required for mapper_discovery checks")
)
View Source
var (
	// ErrMapperAddressEmpty indicates mapper address configuration is missing
	ErrMapperAddressEmpty = errors.New("mapper address cannot be empty")
)

Functions

func NewSNMPChecker

func NewSNMPChecker(ctx context.Context, address string, security *models.SecurityConfig, log logger.Logger) (checker.Checker, error)

func ResolveAgentID added in v1.0.55

func ResolveAgentID(configPath, current string) (string, error)

ResolveAgentID determines the canonical agent_id by checking current config, env vars, and config files.

func SeedCheckerConfigsFromDisk added in v1.0.55

func SeedCheckerConfigsFromDisk(
	ctx context.Context,
	kvMgr *config.KVManager,
	cfg *ServerConfig,
	configPath string,
	log logger.Logger,
) error

SeedCheckerConfigsFromDisk pushes checker definitions from the filesystem into KV if they are missing.

Types

type CheckerConfig

type CheckerConfig struct {
	Name       string                 `json:"name"`
	Type       string                 `json:"type"`
	Address    string                 `json:"address,omitempty"`
	Port       int                    `json:"port,omitempty"`
	Timeout    Duration               `json:"timeout,omitempty"`
	ListenAddr string                 `json:"listen_addr,omitempty"`
	Additional json.RawMessage        `json:"additional,omitempty"`
	Details    json.RawMessage        `json:"details,omitempty"`
	Security   *models.SecurityConfig `json:"security,omitempty"`
}

CheckerConfig defines the configuration for individual checker services.

type CheckerConnection

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

CheckerConnection represents a connection to an external checker service.

func (*CheckerConnection) EnsureConnected

func (c *CheckerConnection) EnsureConnected(ctx context.Context) (*grpc.Client, error)

EnsureConnected ensures the connection is healthy and returns the gRPC client.

type Duration

type Duration time.Duration

Duration represents a time duration that can be unmarshaled from JSON.

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface to allow parsing of a Duration from a JSON string or number.

type ExternalChecker

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

func NewExternalChecker

func NewExternalChecker(
	ctx context.Context,
	serviceName, serviceType, address, grpcServiceCheckName string,
	security *models.SecurityConfig,
	log logger.Logger,
) (*ExternalChecker, error)

func (*ExternalChecker) Check

func (e *ExternalChecker) Check(ctx context.Context, req *proto.StatusRequest) (healthy bool, details json.RawMessage)

func (*ExternalChecker) Close

func (e *ExternalChecker) Close() error

type ICMPChecker

type ICMPChecker struct {
	Host     string
	DeviceID string
	// contains filtered or unexported fields
}

ICMPChecker performs ICMP checks using a pre-configured scanner.

func NewICMPChecker

func NewICMPChecker(host string, log logger.Logger) (*ICMPChecker, error)

func NewICMPCheckerWithDeviceID

func NewICMPCheckerWithDeviceID(host, deviceID string, log logger.Logger) (*ICMPChecker, error)

func (*ICMPChecker) Check

func (p *ICMPChecker) Check(ctx context.Context, req *proto.StatusRequest) (isAccessible bool, statusMsg json.RawMessage)

func (*ICMPChecker) Close

func (p *ICMPChecker) Close(_ context.Context) error

type ICMPResponse

type ICMPResponse struct {
	Host         string  `json:"host"`
	ResponseTime int64   `json:"response_time"` // in nanoseconds
	PacketLoss   float64 `json:"packet_loss"`
	Available    bool    `json:"available"`
	AgentID      string  `json:"agent_id,omitempty"`  // Optional agent ID for context
	PollerID     string  `json:"poller_id,omitempty"` // Optional poller ID for context
	DeviceID     string  `json:"device_id,omitempty"` // Device ID for proper correlation (partition:host_ip)
}

ICMPResponse defines the structure of the ICMP check result.

type IPSorter

type IPSorter []string

IPSorter is a type for sorting IP addresses.

func (IPSorter) Len

func (s IPSorter) Len() int

func (IPSorter) Less

func (s IPSorter) Less(i, j int) bool

Less implements sort.Interface.

func (IPSorter) Swap

func (s IPSorter) Swap(i, j int)

type KVStore

type KVStore interface {
	kv.KVStore
}

KVStore defines the interface for key-value store operations. It embeds the shared configuration KV interface so agent stores remain compatible with the config loader while allowing optional extensions (e.g. PutIfAbsent).

type MapperConfig

type MapperConfig struct {
	Address string `json:"address"` // Address of the mapper service
}

MapperConfig represents the configuration for the mapper service

type MapperDiscoveryChecker

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

MapperDiscoveryChecker implements checker.Checker for initiating and monitoring mapper discovery jobs.

func NewMapperDiscoveryChecker

func NewMapperDiscoveryChecker(
	ctx context.Context,
	details string,
	security *models.SecurityConfig,
	log logger.Logger,
) (*MapperDiscoveryChecker, error)

NewMapperDiscoveryChecker creates a new instance of MapperDiscoveryChecker.

func (*MapperDiscoveryChecker) Check

Check parses the discovery parameters, optionally initiates a job, and returns the status/results

func (*MapperDiscoveryChecker) Close

func (mdc *MapperDiscoveryChecker) Close() error

Close gracefully closes the gRPC client connection to the mapper.

type MapperDiscoveryDetails

type MapperDiscoveryDetails struct {
	IncludeRawData bool `json:"include_raw_data,omitempty"`
}

type MockKVStore

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

MockKVStore is a mock of KVStore interface.

func NewMockKVStore

func NewMockKVStore(ctrl *gomock.Controller) *MockKVStore

NewMockKVStore creates a new mock instance.

func (*MockKVStore) Close

func (m *MockKVStore) Close() error

Close mocks base method.

func (*MockKVStore) Create added in v1.0.55

func (m *MockKVStore) Create(arg0 context.Context, arg1 string, arg2 []byte, arg3 time.Duration) error

Create mocks base method.

func (*MockKVStore) Delete

func (m *MockKVStore) Delete(arg0 context.Context, arg1 string) error

Delete mocks base method.

func (*MockKVStore) EXPECT

func (m *MockKVStore) EXPECT() *MockKVStoreMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockKVStore) Get

func (m *MockKVStore) Get(arg0 context.Context, arg1 string) ([]byte, bool, error)

DownloadObject mocks base method. Get mocks base method.

func (*MockKVStore) Put

func (m *MockKVStore) Put(arg0 context.Context, arg1 string, arg2 []byte, arg3 time.Duration) error

Put mocks base method.

func (*MockKVStore) Watch

func (m *MockKVStore) Watch(arg0 context.Context, arg1 string) (<-chan []byte, error)

Watch mocks base method.

type MockKVStoreMockRecorder

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

MockKVStoreMockRecorder is the mock recorder for MockKVStore.

func (*MockKVStoreMockRecorder) Close

func (mr *MockKVStoreMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close.

func (*MockKVStoreMockRecorder) Create added in v1.0.55

func (mr *MockKVStoreMockRecorder) Create(arg0, arg1, arg2, arg3 any) *gomock.Call

Create indicates an expected call of Create.

func (*MockKVStoreMockRecorder) Delete

func (mr *MockKVStoreMockRecorder) Delete(arg0, arg1 any) *gomock.Call

Delete indicates an expected call of Delete.

func (*MockKVStoreMockRecorder) Get

func (mr *MockKVStoreMockRecorder) Get(arg0, arg1 any) *gomock.Call

Get indicates an expected call of Get.

func (*MockKVStoreMockRecorder) Put

func (mr *MockKVStoreMockRecorder) Put(arg0, arg1, arg2, arg3 any) *gomock.Call

Put indicates an expected call of Put.

func (*MockKVStoreMockRecorder) Watch

func (mr *MockKVStoreMockRecorder) Watch(arg0, arg1 any) *gomock.Call

Watch indicates an expected call of Watch.

type MockObjectStore added in v1.0.55

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

MockObjectStore is a mock of ObjectStore interface.

func NewMockObjectStore added in v1.0.55

func NewMockObjectStore(ctrl *gomock.Controller) *MockObjectStore

NewMockObjectStore creates a new mock instance.

func (*MockObjectStore) DownloadObject added in v1.0.55

func (m *MockObjectStore) DownloadObject(arg0 context.Context, arg1 string) ([]byte, error)

DownloadObject mocks base method.

func (*MockObjectStore) EXPECT added in v1.0.55

EXPECT returns an object that allows the caller to indicate expected use.

type MockObjectStoreMockRecorder added in v1.0.55

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

MockObjectStoreMockRecorder is the mock recorder for MockObjectStore.

func (*MockObjectStoreMockRecorder) DownloadObject added in v1.0.55

func (mr *MockObjectStoreMockRecorder) DownloadObject(arg0, arg1 any) *gomock.Call

DownloadObject indicates an expected call of DownloadObject.

type MockService

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

MockService is a mock of Service interface.

func NewMockService

func NewMockService(ctrl *gomock.Controller) *MockService

NewMockService creates a new mock instance.

func (*MockService) EXPECT

func (m *MockService) EXPECT() *MockServiceMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockService) Name

func (m *MockService) Name() string

Name mocks base method.

func (*MockService) Start

func (m *MockService) Start(arg0 context.Context) error

Start mocks base method.

func (*MockService) Stop

func (m *MockService) Stop(arg0 context.Context) error

Stop mocks base method.

func (*MockService) UpdateConfig

func (m *MockService) UpdateConfig(arg0 *models.Config) error

UpdateConfig mocks base method.

type MockServiceMockRecorder

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

MockServiceMockRecorder is the mock recorder for MockService.

func (*MockServiceMockRecorder) Name

func (mr *MockServiceMockRecorder) Name() *gomock.Call

Name indicates an expected call of Name.

func (*MockServiceMockRecorder) Start

func (mr *MockServiceMockRecorder) Start(arg0 any) *gomock.Call

Start indicates an expected call of Start.

func (*MockServiceMockRecorder) Stop

func (mr *MockServiceMockRecorder) Stop(arg0 any) *gomock.Call

Stop indicates an expected call of Stop.

func (*MockServiceMockRecorder) UpdateConfig

func (mr *MockServiceMockRecorder) UpdateConfig(arg0 any) *gomock.Call

UpdateConfig indicates an expected call of UpdateConfig.

type MockSweepStatusProvider

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

MockSweepStatusProvider is a mock of SweepStatusProvider interface.

func NewMockSweepStatusProvider

func NewMockSweepStatusProvider(ctrl *gomock.Controller) *MockSweepStatusProvider

NewMockSweepStatusProvider creates a new mock instance.

func (*MockSweepStatusProvider) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockSweepStatusProvider) GetStatus

GetStatus mocks base method.

type MockSweepStatusProviderMockRecorder

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

MockSweepStatusProviderMockRecorder is the mock recorder for MockSweepStatusProvider.

func (*MockSweepStatusProviderMockRecorder) GetStatus

func (mr *MockSweepStatusProviderMockRecorder) GetStatus(arg0 any) *gomock.Call

GetStatus indicates an expected call of GetStatus.

type ObjectStore added in v1.0.55

type ObjectStore interface {
	DownloadObject(ctx context.Context, key string) ([]byte, error)
}

ObjectStore defines read access to the JetStream-backed object store.

type PortChecker

type PortChecker struct {
	Host string
	Port int
	// contains filtered or unexported fields
}

func NewPortChecker

func NewPortChecker(details string, log logger.Logger) (*PortChecker, error)

func (*PortChecker) Check

func (p *PortChecker) Check(ctx context.Context, _ *proto.StatusRequest) (isAccessible bool, statusMsg json.RawMessage)

Check validates if a port is accessible.

func (*PortChecker) Close

func (*PortChecker) Close() error

type ProcessChecker

type ProcessChecker struct {
	ProcessName string
	// contains filtered or unexported fields
}

func (*ProcessChecker) Check

func (p *ProcessChecker) Check(ctx context.Context, req *proto.StatusRequest) (isActive bool, statusMsg json.RawMessage)

Check validates if a process is running.

func (*ProcessChecker) Close

func (*ProcessChecker) Close() error

type SNMPChecker

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

func (*SNMPChecker) Check

func (c *SNMPChecker) Check(ctx context.Context, req *proto.StatusRequest) (available bool, msg json.RawMessage)

func (*SNMPChecker) Start

func (c *SNMPChecker) Start(ctx context.Context) error

func (*SNMPChecker) Stop

func (c *SNMPChecker) Stop(ctx context.Context) error

type ScanStats

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

ScanStats tracks scanning statistics.

type Server

type Server struct {
	proto.UnimplementedAgentServiceServer
	// contains filtered or unexported fields
}

Server represents the main agent server that handles checker coordination and service management.

func NewServer

func NewServer(ctx context.Context, configDir string, cfg *ServerConfig, log logger.Logger) (*Server, error)

NewServer initializes a new Server instance.

func (*Server) Close

func (s *Server) Close(ctx context.Context) error

Close gracefully shuts down the server and releases resources.

func (*Server) GetResults

func (s *Server) GetResults(ctx context.Context, req *proto.ResultsRequest) (*proto.ResultsResponse, error)

GetResults implements the AgentService GetResults method. For grpc services, this forwards the call to the actual service. For sweep services, this calls the local sweep service. For other services, this returns a "not supported" response. GetResults handles results requests for various service types.

func (*Server) GetStatus

func (s *Server) GetStatus(ctx context.Context, req *proto.StatusRequest) (*proto.StatusResponse, error)

GetStatus handles status requests for various service types.

func (*Server) ListServices

func (s *Server) ListServices() []string

ListServices returns a list of all configured service names.

func (*Server) ListenAddr

func (s *Server) ListenAddr() string

ListenAddr returns the server's listening address.

func (*Server) RestartServices added in v1.0.55

func (s *Server) RestartServices(ctx context.Context)

RestartServices stops and starts all managed services using the current configuration.

func (*Server) SecurityConfig

func (s *Server) SecurityConfig() *models.SecurityConfig

SecurityConfig returns the server's security configuration.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start initializes and starts all agent services.

func (*Server) Stop

func (s *Server) Stop(_ context.Context) error

Stop gracefully shuts down all agent services.

func (*Server) StreamResults

func (s *Server) StreamResults(req *proto.ResultsRequest, stream proto.AgentService_StreamResultsServer) error

StreamResults implements the AgentService StreamResults method for large datasets. For sweep services, this calls the local sweep service and streams the results. For grpc services, this forwards the streaming call to the actual service. For other services, this returns a "not supported" response. StreamResults handles streaming results requests for large datasets.

func (*Server) UpdateConfig added in v1.0.55

func (s *Server) UpdateConfig(newCfg *ServerConfig)

UpdateConfig applies logging/security updates at runtime where possible. Security changes typically require a restart to fully apply to gRPC servers/clients.

type ServerConfig

type ServerConfig struct {
	AgentID     string                 `json:"agent_id"`             // Unique identifier for this agent
	AgentName   string                 `json:"agent_name,omitempty"` // Explicit name for KV namespacing
	HostIP      string                 `json:"host_ip,omitempty"`    // Host IP address for device correlation
	Partition   string                 `json:"partition,omitempty"`  // Partition for device correlation
	ListenAddr  string                 `json:"listen_addr"`
	Security    *models.SecurityConfig `json:"security" hot:"rebuild"`
	KVAddress   string                 `json:"kv_address,omitempty"`  // Optional KV store address
	KVSecurity  *models.SecurityConfig `json:"kv_security,omitempty"` // Separate security config for KV
	CheckersDir string                 `json:"checkers_dir"`
	Logging     *logger.Config         `json:"logging,omitempty" hot:"reload"`
}

ServerConfig holds the configuration for the agent server.

type Service

type Service interface {
	Start(context.Context) error
	Stop(ctx context.Context) error
	Name() string
	UpdateConfig(config *models.Config) error // Added for dynamic config updates
}

Service defines the interface for agent services that can be started, stopped, and configured.

func NewSweepService

func NewSweepService(
	ctx context.Context,
	config *models.Config,
	configStore KVStore,
	objectStore ObjectStore,
	configKey string,
	log logger.Logger,
) (Service, error)

NewSweepService creates a new SweepService.

type ServiceError

type ServiceError struct {
	ServiceName string
	Err         error
}

ServiceError represents an error that occurred in a specific service.

func (*ServiceError) Error

func (e *ServiceError) Error() string

Error implements the error interface for ServiceError.

type SweepConfig

type SweepConfig struct {
	MaxTargets    int
	MaxGoroutines int
	BatchSize     int
	MemoryLimit   int64
	Networks      []string              `json:"networks"`
	Ports         []int                 `json:"ports"`
	SweepModes    []models.SweepMode    `json:"sweep_modes"`
	DeviceTargets []models.DeviceTarget `json:"device_targets,omitempty"` // Per-device sweep configuration
	Interval      Duration              `json:"interval"`
	Concurrency   int                   `json:"concurrency"`
	Timeout       Duration              `json:"timeout"`
}

SweepConfig defines configuration parameters for network sweep operations.

type SweepService

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

SweepService implements Service for network scanning.

func (*SweepService) Check

func (*SweepService) CheckICMP

func (s *SweepService) CheckICMP(ctx context.Context, host string) (*models.Result, error)

CheckICMP performs a standalone ICMP check on the specified host.

func (*SweepService) Close

func (s *SweepService) Close() error

func (*SweepService) GetStatus

func (s *SweepService) GetStatus(ctx context.Context) (*proto.StatusResponse, error)

GetStatus returns the current status of the sweep service (lightweight version without hosts).

func (*SweepService) GetSweepResults

func (s *SweepService) GetSweepResults(ctx context.Context, lastSequence string) (*proto.ResultsResponse, error)

GetSweepResults returns sweep results with sequence tracking for change detection.

func (*SweepService) Name

func (*SweepService) Name() string

Name returns the service name.

func (*SweepService) Start

func (s *SweepService) Start(ctx context.Context) error

Start begins the sweep service.

func (*SweepService) Stop

func (s *SweepService) Stop(_ context.Context) error

Stop gracefully stops the sweep service.

func (*SweepService) UpdateConfig

func (s *SweepService) UpdateConfig(config *models.Config) error

UpdateConfig updates the service configuration.

type SweepStatusProvider

type SweepStatusProvider interface {
	GetStatus(context.Context) (*proto.StatusResponse, error)
}

SweepStatusProvider is an interface for services that can provide sweep status.

Jump to

Keyboard shortcuts

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