config

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AgentHostname

func AgentHostname() string

AgentHostname returns the hostname identity exposed to the server. It follows the resolved from_hostname label when present. For auto-detected values (no env var), results are cached for 1 minute.

func AgentIP

func AgentIP() string

AgentIP returns the IP identity exposed to the server. For auto-detected values (no env var), results are cached for 1 minute.

func AgentLabels

func AgentLabels() map[string]string

AgentLabels returns a snapshot of global labels with live from_hostip and from_hostname values (reflecting any auto-detected changes).

func DetectHostname

func DetectHostname() string

DetectHostname returns the current system hostname via os.Hostname.

func DetectIP

func DetectIP() string

DetectIP returns the preferred outbound IPv4 address. It first tries gateway-based detection via GetOutboundIP, then falls back to scanning network interfaces.

func ExpandWithBuiltins

func ExpandWithBuiltins(raw string, builtins map[string]string) string

ExpandWithBuiltins expands ${VAR} references in raw, checking builtins first and falling back to environment variables.

func GetOutboundIP

func GetOutboundIP() (net.IP, error)

Get preferred outbound ip of this machine

func HostBuiltins

func HostBuiltins() map[string]string

HostBuiltins computes host-level built-in variables once. Callers should compute this early and pass it to expandWithBuiltins.

func HostBuiltinsWithoutIP

func HostBuiltinsWithoutIP() map[string]string

HostBuiltinsWithoutIP returns built-in host variables that do not require network probing.

func InitConfig

func InitConfig(configDir string, interval int64, plugins, loglevel string) error

func LoadOrCreateAgentID added in v0.1.4

func LoadOrCreateAgentID() (uuid.UUID, error)

LoadOrCreateAgentID reads the agent_id from state.d/agent_id. If the file does not exist, a new UUIDv4 is generated and persisted.

Types

type AIConfig

type AIConfig struct {
	Enabled       bool                   `toml:"enabled"`
	ModelPriority []string               `toml:"model_priority"`
	Models        map[string]ModelConfig `toml:"models"`
	Gateway       GatewayConfig          `toml:"gateway"`

	MaxRounds      int      `toml:"max_rounds"`
	RequestTimeout Duration `toml:"request_timeout"`

	MaxRetries   int      `toml:"max_retries"`
	RetryBackoff Duration `toml:"retry_backoff"`

	MaxConcurrentDiagnoses int    `toml:"max_concurrent_diagnoses"`
	QueueFullPolicy        string `toml:"queue_full_policy"`
	DailyTokenLimit        int    `toml:"daily_token_limit"`

	ToolTimeout     Duration `toml:"tool_timeout"`
	AggregateWindow Duration `toml:"aggregate_window"`

	DiagnoseRetention Duration `toml:"diagnose_retention"`
	DiagnoseMaxCount  int      `toml:"diagnose_max_count"`

	Language string `toml:"language"`

	MCP MCPConfig `toml:"mcp"`
}

AIConfig holds the full AI subsystem configuration. ModelPriority defines the failover order; Models maps profile names to ModelConfig.

func (*AIConfig) ContextWindowLimit

func (c *AIConfig) ContextWindowLimit() int

ContextWindowLimit returns 80% of the primary model's context window size, used as the safe upper bound for message token budgeting. Returns 0 if no models are configured.

func (*AIConfig) PrimaryModel

func (c *AIConfig) PrimaryModel() ModelConfig

PrimaryModel returns the first configured local model in the priority list. Returns the zero value when no local model is configured.

func (*AIConfig) PrimaryModelName

func (c *AIConfig) PrimaryModelName() string

PrimaryModelName returns the name of the first model in the priority list.

func (*AIConfig) Validate

func (c *AIConfig) Validate() error

type Alerting

type Alerting struct {
	Disabled bool `toml:"disabled"`

	// like prometheus `for`
	ForDuration Duration `toml:"for_duration"`

	// repeat interval
	RepeatInterval Duration `toml:"repeat_interval"`

	// maximum number of notifications
	RepeatNumber int `toml:"repeat_number"`

	// set to true to suppress recovery notifications
	DisableRecoveryNotification bool `toml:"disable_recovery_notification"`
}

type ConfigType

type ConfigType struct {
	ConfigDir string `toml:"-"`
	StateDir  string `toml:"-"`
	Plugins   string `toml:"-"`
	Loglevel  string `toml:"-"`

	Global    Global       `toml:"global"`
	LogConfig LogConfig    `toml:"log"`
	Notify    NotifyConfig `toml:"notify"`
	AI        AIConfig     `toml:"ai"`
	Server    ServerConfig `toml:"server"`
}
var Config *ConfigType

type ConsoleConfig

type ConsoleConfig struct {
	Enabled bool `toml:"enabled"`
}

type DiagnoseConfig

type DiagnoseConfig struct {
	Enabled     bool     `toml:"enabled"`
	MinSeverity string   `toml:"min_severity"`
	Timeout     Duration `toml:"timeout"`
	Cooldown    Duration `toml:"cooldown"`
}

type Duration

type Duration time.Duration

Duration is a time.Duration

func (*Duration) HumanString

func (d *Duration) HumanString() string

func (*Duration) UnmarshalTOML

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

UnmarshalTOML parses the duration from the TOML config file

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

type FlashdutyConfig

type FlashdutyConfig struct {
	IntegrationKey string   `toml:"integration_key"`
	BaseUrl        string   `toml:"base_url"`
	Timeout        Duration `toml:"timeout"`
	MaxRetries     int      `toml:"max_retries"`
}

type GatewayConfig

type GatewayConfig struct {
	Enabled          bool     `toml:"enabled"`
	BaseURL          string   `toml:"base_url"`
	AgentToken       string   `toml:"agent_token"`
	RequestTimeout   Duration `toml:"request_timeout"`
	MaxRetries       int      `toml:"max_retries"`
	FallbackToDirect bool     `toml:"fallback_to_direct"`
}

GatewayConfig defines the server-backed AI gateway connection.

type Global

type Global struct {
	Interval Duration          `toml:"interval"`
	Labels   map[string]string `toml:"labels"`
}

type HTTPConfig

type HTTPConfig struct {
	Interface       string   `toml:"interface"`
	Method          string   `toml:"method"`
	Timeout         Duration `toml:"timeout"`
	FollowRedirects *bool    `toml:"follow_redirects"`
	BasicAuthUser   string   `toml:"basic_auth_user"`
	BasicAuthPass   string   `toml:"basic_auth_pass"`
	Headers         []string `toml:"headers"`
	Payload         string   `toml:"payload"`
	HTTPProxy       string   `toml:"http_proxy"`
	tls.ClientConfig
}

func (*HTTPConfig) GetMethod

func (hc *HTTPConfig) GetMethod() string

func (*HTTPConfig) GetProxy

func (hc *HTTPConfig) GetProxy() (proxyFunc, error)

func (*HTTPConfig) GetTimeout

func (hc *HTTPConfig) GetTimeout() Duration

type InternalConfig

type InternalConfig struct {
	// append labels to every event
	Labels map[string]string `toml:"labels"`

	// gather interval
	Interval Duration `toml:"interval"`

	// alerting rule
	Alerting Alerting `toml:"alerting"`

	// AI diagnose config
	Diagnose DiagnoseConfig `toml:"diagnose"`
}

func (*InternalConfig) GetAlerting

func (ic *InternalConfig) GetAlerting() Alerting

func (*InternalConfig) GetDiagnoseConfig

func (ic *InternalConfig) GetDiagnoseConfig() DiagnoseConfig

func (*InternalConfig) GetInterval

func (ic *InternalConfig) GetInterval() Duration

func (*InternalConfig) GetLabels

func (ic *InternalConfig) GetLabels() map[string]string

type LogConfig

type LogConfig struct {
	Level  string                 `toml:"level"`
	Format string                 `toml:"format"`
	Output string                 `toml:"output"`
	Fields map[string]interface{} `toml:"fields"`
}

type MCPConfig

type MCPConfig struct {
	Enabled         bool              `toml:"enabled"`
	DefaultIdentity string            `toml:"default_identity"`
	Servers         []MCPServerConfig `toml:"servers"`
}

MCPConfig holds configuration for MCP (Model Context Protocol) server connections.

type MCPServerConfig

type MCPServerConfig struct {
	Name       string            `toml:"name"`
	Command    string            `toml:"command"`
	Args       []string          `toml:"args"`
	Env        map[string]string `toml:"env"`
	Identity   string            `toml:"identity"`
	ToolsAllow []string          `toml:"tools_allow"`
}

MCPServerConfig defines one MCP server connection.

func (*MCPServerConfig) IsToolAllowed

func (s *MCPServerConfig) IsToolAllowed(toolName string) bool

IsToolAllowed checks whether a tool name passes the whitelist filter. If ToolsAllow is empty, all tools are allowed.

func (*MCPServerConfig) ResolvedIdentity

func (s *MCPServerConfig) ResolvedIdentity(defaultIdentity string, builtins map[string]string) string

ResolvedIdentity returns the identity string for this server, falling back to defaultIdentity, then auto-detected host info. Variables ${HOSTNAME}, ${SHORT_HOSTNAME}, ${IP}, and ${ENV_VAR} are expanded. builtins should be obtained from HostBuiltins().

type ModelConfig

type ModelConfig struct {
	// Provider selects the backend: "" or "openai" for OpenAI-compatible,
	// "bedrock" for AWS Bedrock Converse API with SigV4 auth.
	Provider string `toml:"provider"`

	BaseURL             string                 `toml:"base_url"`
	APIKey              string                 `toml:"api_key"`
	Model               string                 `toml:"model"`
	MaxTokens           int                    `toml:"max_tokens"`
	MaxCompletionTokens int                    `toml:"max_completion_tokens"`
	ContextWindow       int                    `toml:"context_window"`
	InputPrice          float64                `toml:"input_price"`
	OutputPrice         float64                `toml:"output_price"`
	ExtraBody           map[string]interface{} `toml:"extra_body"`
}

ModelConfig defines connection and model-specific parameters for one AI model.

func (ModelConfig) ExtraStr

func (m ModelConfig) ExtraStr(key string) string

ExtraStr returns a string value from ExtraBody, or empty if missing.

type NotifyConfig

type NotifyConfig struct {
	Console   *ConsoleConfig   `toml:"console"`
	Flashduty *FlashdutyConfig `toml:"flashduty"`
	PagerDuty *PagerDutyConfig `toml:"pagerduty"`
	WebAPI    *WebAPIConfig    `toml:"webapi"`
}

type PagerDutyConfig

type PagerDutyConfig struct {
	RoutingKey  string            `toml:"routing_key"`
	BaseUrl     string            `toml:"base_url"`
	SeverityMap map[string]string `toml:"severity_map"`
	Timeout     Duration          `toml:"timeout"`
	MaxRetries  int               `toml:"max_retries"`
}

type ServerConfig

type ServerConfig struct {
	Enabled         bool   `toml:"enabled"`
	Address         string `toml:"address"`
	AgentToken      string `toml:"agent_token"`
	CAFile          string `toml:"ca_file"`
	TLSSkipVerify   bool   `toml:"tls_skip_verify"`
	AlertBufferSize int    `toml:"alert_buffer_size"`
}

ServerConfig defines the optional catpaw-server connection. When Enabled is false (default), the Agent runs in pure local mode.

func (ServerConfig) GatewayBaseURL

func (c ServerConfig) GatewayBaseURL() (string, error)

func (*ServerConfig) GetAlertBufferSize

func (c *ServerConfig) GetAlertBufferSize() int

func (ServerConfig) HTTPBaseURL

func (c ServerConfig) HTTPBaseURL() (string, error)

func (ServerConfig) WebSocketURL

func (c ServerConfig) WebSocketURL() (string, error)

type Size

type Size int64

Size represents a byte size with human-readable TOML parsing. Supports: "50MB", "1GB", "512KB", "1024" (bytes), etc. Case-insensitive units: B, KB, MB, GB, TB.

const (
	KB Size = 1 << (10 * iota)
	MB
	GB
	TB
)

func (Size) String

func (s Size) String() string

func (*Size) UnmarshalTOML

func (s *Size) UnmarshalTOML(b []byte) error

func (*Size) UnmarshalText

func (s *Size) UnmarshalText(text []byte) error

type WebAPIConfig

type WebAPIConfig struct {
	URL        string            `toml:"url"`
	Method     string            `toml:"method"`
	Headers    map[string]string `toml:"headers"`
	Timeout    Duration          `toml:"timeout"`
	MaxRetries int               `toml:"max_retries"`
}

Jump to

Keyboard shortcuts

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