config

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EXTENSION_ACTION_ADD       = "add"
	EXTENSION_ACTION_OVERWRITE = "overwrite"
	EXTENSION_ACTION_REMOVE    = "remove"
)
View Source
const (
	METRIC_TYPE_COUNTER = "counter"
	METRIC_TYPE_GAUGE   = "gauge"
)
View Source
const (
	PARAM_TYPE_STRING   = "string"
	PARAM_TYPE_INT      = "int"
	PARAM_TYPE_BOOL     = "bool"
	PARAM_TYPE_TIMESPAN = "timespan"
	PARAM_TYPE_DATETIME = "datetime"

	PARAM_DATETYPE_TO_NOW    = "tonow"
	PARAM_DATETYPE_FROM_NOW  = "fromnow"
	PARAM_DATETYPE_TIMESTAMP = "timestamp"
)
View Source
const (
	DATETIME_FORMAT_V6 = "Jan/02/2006 15:04:05"
	DATETIME_FORMAT_V7 = "2006-01-02 15:04:05"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AddMetric added in v0.2.0

type AddMetric func(labelValues []string, value float64)

type Command

type Command struct {
	CommandBase CommandBase `yaml:",inline"`

	Metrics     Metrics   `yaml:"metrics"`
	Labels      Labels    `yaml:"labels,omitempty"`
	Variables   Labels    `yaml:"variables,omitempty"`
	SubCommands []Command `yaml:"sub_commands,omitempty"`
}

func DefaultCommand

func DefaultCommand() Command

func (*Command) Run

func (x *Command) Run(ctx context.Context, log zerolog.Logger, client *routeros.Client, registerer prometheus.Registerer, parentVariables map[string]string, metricCache map[string]AddMetric) error

func (*Command) UnmarshalYAML

func (x *Command) UnmarshalYAML(unmarshal func(interface{}) error) error

func (*Command) Validate

func (x *Command) Validate() error

type CommandBase

type CommandBase struct {
	Command string `yaml:"command"`
	Timeout int    `yaml:"timeout"`

	Prefix string `yaml:"prefix,omitempty"`
	// contains filtered or unexported fields
}

func DefaultCommandBase

func DefaultCommandBase() CommandBase

func (*CommandBase) UnmarshalYAML

func (x *CommandBase) UnmarshalYAML(unmarshal func(interface{}) error) error

func (*CommandBase) Validate

func (x *CommandBase) Validate() error

type CommandExtension

type CommandExtension struct {
	Command string `yaml:"command"`

	Metrics     []MetricExtension `yaml:"metrics"`
	Labels      []LabelExtension  `yaml:"labels"`
	Variables   []LabelExtension  `yaml:"variables"`
	SubCommands CommandExtensions `yaml:"sub_commands"`
}

func (*CommandExtension) ExtendCommand

func (x *CommandExtension) ExtendCommand(log zerolog.Logger, command Command)

type CommandExtensions added in v0.5.2

type CommandExtensions []CommandExtension

func (CommandExtensions) Extend added in v0.5.2

func (x CommandExtensions) Extend(log zerolog.Logger, commands []Command)

func (CommandExtensions) GetByCommand added in v0.5.2

func (x CommandExtensions) GetByCommand(commandStr string) []CommandExtension

type Config

type Config struct {
	ConfigD ConfigD `yaml:",inline"`

	Listen         string `yaml:"listen"`
	MetricsPath    string `yaml:"metrics_path"`
	ProbePath      string `yaml:"probe_path"`
	ReloadPath     string `yaml:"reload_path"`
	DumpConfigPath string `yaml:"dump_config_path"`
	Namespace      string `yaml:"namespace"`

	Credentials Credentials `yaml:",inline"`

	ConfigFiles []string `yaml:"config_files"`

	ConnectionCleanupInterval         int           `yaml:"connection_cleanup_interval"`
	ConnectionCleanupIntervalDuration time.Duration `yaml:"-"`
	ConnectionUseTimeout              int           `yaml:"connection_use_timeout"`
	ConnectionUseTimeoutDuration      time.Duration `yaml:"-"`

	TargetMap map[string]*Target `yaml:"-"`
	// contains filtered or unexported fields
}

func DefaultConfig

func DefaultConfig() Config

func (*Config) GetModule

func (c *Config) GetModule(name string) *Module

func (*Config) GetTarget

func (c *Config) GetTarget(name string) *Target

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error

type ConfigD

type ConfigD struct {
	Targets          []*Target          `yaml:"targets,omitempty"`
	Modules          []*Module          `yaml:"modules,omitempty"`
	ModuleExtensions []*ModuleExtension `yaml:"module_extensions,omitempty"`
}

func DefaultConfigD

func DefaultConfigD() ConfigD

func (*ConfigD) UnmarshalYAML

func (x *ConfigD) UnmarshalYAML(unmarshal func(interface{}) error) error

func (*ConfigD) Validate

func (x *ConfigD) Validate() error

type Credentials

type Credentials struct {
	Username *string `yaml:"username"`
	Password *string `yaml:"password"`
}

func (Credentials) MarshalYAML added in v0.5.0

func (c Credentials) MarshalYAML() (interface{}, error)

type Extension

type Extension struct {
	ExtensionAction string `yaml:"extension_action"`
}

func DefaultExtension

func DefaultExtension() Extension

func (*Extension) UnmarshalYAML

func (x *Extension) UnmarshalYAML(unmarshal func(interface{}) error) error

func (*Extension) Validate

func (x *Extension) Validate() error

type Label

type Label struct {
	Param Param `yaml:",inline"`

	LabelName string `yaml:"label_name"`
}

func DefaultLabel

func DefaultLabel() Label

func (*Label) AsString

func (label *Label) AsString(log zerolog.Logger, response map[string]string, variables map[string]string) string

func (*Label) UnmarshalYAML

func (label *Label) UnmarshalYAML(unmarshal func(interface{}) error) error

func (*Label) Validate

func (label *Label) Validate() error

type LabelExtension

type LabelExtension struct {
	Extension Extension `yaml:",inline"`
	Label     Label     `yaml:",inline"`
}

type Labels

type Labels []Label

func (*Labels) Add added in v0.5.0

func (x *Labels) Add(item Label)

func (Labels) GetByName added in v0.5.0

func (x Labels) GetByName(name string) (*Label, int)

func (Labels) LabelNames added in v0.5.0

func (x Labels) LabelNames() []string

func (Labels) LabelValues added in v0.5.0

func (x Labels) LabelValues(log zerolog.Logger, response map[string]string, variables map[string]string) []string

func (*Labels) RemoveByIndex added in v0.5.0

func (x *Labels) RemoveByIndex(i int)

type Metric

type Metric struct {
	Param Param `yaml:",inline"`

	MetricName string `yaml:"metric_name"`
	MetricType string `yaml:"metric_type"`
	Help       string `yaml:"help,omitempty"`
	Labels     Labels `yaml:"labels,omitempty"`
}

func DefaultMetric

func DefaultMetric() Metric

func (*Metric) AddValue

func (metric *Metric) AddValue(log zerolog.Logger, registerer prometheus.Registerer, value float64, commandLabelNames, commandLabelValues []string, response map[string]string, variables map[string]string, metricCache map[string]AddMetric)

func (*Metric) TryGetValue

func (metric *Metric) TryGetValue(log zerolog.Logger, response map[string]string, variables map[string]string) (float64, bool)

func (*Metric) UnmarshalYAML

func (x *Metric) UnmarshalYAML(unmarshal func(interface{}) error) error

func (*Metric) Validate

func (metric *Metric) Validate() error

type MetricArray

type MetricArray []Metric

func (*MetricArray) Add

func (x *MetricArray) Add(item Metric)

func (*MetricArray) GetByName

func (x *MetricArray) GetByName(name string) (*Metric, int)

func (*MetricArray) RemoveByIndex

func (x *MetricArray) RemoveByIndex(i int)

type MetricExtension

type MetricExtension struct {
	Extension `yaml:",inline"`
	Metric    `yaml:",inline"`
}

type Metrics

type Metrics = *MetricArray

type Module

type Module struct {
	Name     string    `yaml:"name"`
	Commands []Command `yaml:"commands"`
}

func DefaultModule

func DefaultModule() Module

func (*Module) Run

func (module *Module) Run(ctx context.Context, log zerolog.Logger, client *routeros.Client, registerer prometheus.Registerer, variables map[string]string) error

func (*Module) UnmarshalYAML

func (module *Module) UnmarshalYAML(unmarshal func(interface{}) error) error

func (*Module) Validate

func (module *Module) Validate() error

type ModuleExtension

type ModuleExtension struct {
	Name     string            `yaml:"name"`
	Commands CommandExtensions `yaml:"commands"`
}

func (*ModuleExtension) ExtendModule

func (x *ModuleExtension) ExtendModule(log zerolog.Logger, module Module)

type Param

type Param struct {
	ParamName string `yaml:"param_name"`
	ParamType string `yaml:"param_type"`
	Default   string `yaml:"default,omitempty"`
	Value     string `yaml:"value,omitempty"`

	RemapValues   map[string]*string `yaml:"remap_values,omitempty"`
	RemapValuesRe []remapRe          `yaml:"remap_values_re,omitempty"`

	Negate       bool   `yaml:"negate,omitempty"`
	DateTimeType string `yaml:"datetime_type,omitempty"`
}

func DefaultParam

func DefaultParam() Param

func (*Param) PreprocessValue

func (param *Param) PreprocessValue(log zerolog.Logger, response map[string]string, variables map[string]string) (string, bool)

func (*Param) UnmarshalYAML

func (param *Param) UnmarshalYAML(unmarshal func(interface{}) error) error

func (*Param) Validate

func (param *Param) Validate() error

type SafeConfig

type SafeConfig struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func New

func New(configFile string) (*SafeConfig, error)

func (*SafeConfig) EnableReloadByHTTP

func (sc *SafeConfig) EnableReloadByHTTP()

func (*SafeConfig) EnableReloadBySIGHUP

func (sc *SafeConfig) EnableReloadBySIGHUP()

func (*SafeConfig) Get

func (sc *SafeConfig) Get() *Config

func (*SafeConfig) LoadConfig

func (sc *SafeConfig) LoadConfig() (err error)

type Target

type Target struct {
	Name            string            `yaml:"name"`
	Address         string            `yaml:"address"`
	Timeout         int               `yaml:"timeout"`
	TimeoutDuration time.Duration     `yaml:"-"`
	Queue           int               `yaml:"queue"`
	Credentials     Credentials       `yaml:",inline"`
	Variables       map[string]string `yaml:"variables"`
	Modules         []string          `yaml:"modules"`
}

func DefaultTarget

func DefaultTarget() Target

func (*Target) Dial

func (t *Target) Dial() (*routeros.Client, error)

func (*Target) UnmarshalYAML

func (target *Target) UnmarshalYAML(unmarshal func(interface{}) error) error

func (*Target) Validate

func (target *Target) Validate() error

Jump to

Keyboard shortcuts

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