sensors

package
v1.0.172 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusValueLow  = "low"
	StatusValueHigh = "high"
	StatusValueOK   = "ok"
)
View Source
const DefaultTestTimeout = time.Second

Variables

This section is empty.

Functions

func DoTestSensor

func DoTestSensor(t *testing.T, sensor ISensor, expected float64) (err error)

Types

type ISensor

type ISensor interface {
	/*
		Implemented in abstract class of UnimplementedSensor
	*/
	GetName() string
	GetType() string
	GetDescription() string
	GetLink() string
	GetMinimum() float64
	GetMaximum() float64
	GetTags() map[string]string
	GetValue() float64
	GetUpdatedAt() time.Time
	GetLastError() error
	GetRefreshRate() time.Duration
	GetStatus() string
	/*
		To be implemented in custom sensors
	*/
	Init(context.Context) error
	Ping(context.Context) error
	Close(context.Context) error
	Update(context.Context) error
}

type UnimplementedSensor

type UnimplementedSensor struct {
	/*
	 * Shared parameters
	 */
	// Name is used to distinguish sensors from other ones
	Name string `yaml:"name" validate:"required,alphanum"`
	// Type is used to define strategy to load sensor value
	Type string `yaml:"type" validate:"required, oneof=mysql redis postgres curl shell endpoint"`
	// Description is used to explain meaning of this sensor
	Description string `yaml:"description"`
	// Link is used to help visitor read more about sensor
	Link string `yaml:"link" validate:"http_url"`
	// Tags helps to group sensors
	Tags map[string]string `yaml:"tags"`
	// Value is used to store of value of sensor
	Value float64 `yaml:"-"`
	// UpdatedAt is used to store moment when sensor was updated last time
	UpdatedAt time.Time `yaml:"-"`
	// Error is used to store most recent error of sensor update
	Error error
	// RefreshRate is used to define how often we reload data
	RefreshRate time.Duration `yaml:"refresh_rate"`
	// Minimum is used to warn, when something is below safe value
	Minimum float64 `yaml:"minimum"`
	// Maximum is used to warn, when something is above safe value
	Maximum float64 `yaml:"maximum"`
	// A is coefficient in linear transformation Y=A*X+B used to, for example, convert
	// Fahrenheit degrees into Celsius degrees
	A float64 `yaml:"a"`
	// B is constant in linear transformation Y=A*X+B used to, for example, convert
	// Fahrenheit degrees into Celsius degrees
	B float64 `yaml:"b"`
	// Mutex protects
	Mutex *sync.RWMutex `yaml:"-"`
}

func (*UnimplementedSensor) GetDescription

func (u *UnimplementedSensor) GetDescription() string

func (*UnimplementedSensor) GetLastError

func (u *UnimplementedSensor) GetLastError() error
func (u *UnimplementedSensor) GetLink() string

func (*UnimplementedSensor) GetMaximum

func (u *UnimplementedSensor) GetMaximum() float64

func (*UnimplementedSensor) GetMinimum

func (u *UnimplementedSensor) GetMinimum() float64

func (*UnimplementedSensor) GetName

func (u *UnimplementedSensor) GetName() string

func (*UnimplementedSensor) GetRefreshRate

func (u *UnimplementedSensor) GetRefreshRate() time.Duration

func (*UnimplementedSensor) GetStatus added in v1.0.156

func (u *UnimplementedSensor) GetStatus() string

func (*UnimplementedSensor) GetTags

func (u *UnimplementedSensor) GetTags() map[string]string

func (*UnimplementedSensor) GetType

func (u *UnimplementedSensor) GetType() string

func (*UnimplementedSensor) GetUpdatedAt

func (u *UnimplementedSensor) GetUpdatedAt() time.Time

func (*UnimplementedSensor) GetValue

func (u *UnimplementedSensor) GetValue() float64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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