Documentation
¶
Overview ¶
Package fleet provides a low-level implementation of the NAOS fleet management protocol.
Index ¶
- func BaseTopics(devices []*Device) []string
- func Debug(url string, baseTopics []string, delete bool, jobs int) (map[string][]byte, error)
- func Discover(url string, baseTopics []string, jobs int) (map[string]DiscoverResult, error)
- func GetParams(url, param string, baseTopics []string, jobs int) (map[string]string, error)
- func Monitor(url string, baseTopics []string, stop chan struct{}, cb func(*Heartbeat)) error
- func Record(url string, baseTopics []string, stop chan struct{}, cb func(*LogMessage)) error
- func SetParams(url, param, value string, baseTopics []string, jobs int) (map[string]string, error)
- func UnsetParams(url, param string, baseTopics []string, jobs int) error
- type Announcement
- type Device
- type DiscoverResult
- type Fleet
- func (f *Fleet) Collect(duration time.Duration) ([]*Device, error)
- func (f *Fleet) Debug(pattern string, delete bool, jobs int) (map[*Device][]byte, error)
- func (f *Fleet) Discover(pattern string, jobs int) ([]*Device, error)
- func (f *Fleet) FilterDevices(pattern string) []*Device
- func (f *Fleet) FindDevice(baseTopic string) *Device
- func (f *Fleet) GetParams(pattern, param string, jobs int) ([]*Device, error)
- func (f *Fleet) Monitor(pattern string, quit chan struct{}, callback func(*Device, *Heartbeat)) error
- func (f *Fleet) Ping(pattern string, jobs int) error
- func (f *Fleet) Record(pattern string, quit chan struct{}, callback func(time.Time, *Device, string)) error
- func (f *Fleet) Save(path string) error
- func (f *Fleet) SetParams(pattern, param, value string, jobs int) ([]*Device, error)
- func (f *Fleet) UnsetParams(pattern, param string, jobs int) ([]*Device, error)
- func (f *Fleet) Update(version, pattern string, firmware []byte, jobs int, ...) error
- type Heartbeat
- type LogMessage
- type UpdateStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BaseTopics ¶ added in v0.14.0
BaseTopics returns a list of base topics from the provided devices.
func Discover ¶
Discover will connect to the specified MQTT broker and discover all available parameters and metrics for the specified base topics.
func Monitor ¶
Monitor will connect to the specified MQTT broker and periodically collect heartbeat information from all specified base topics until the provided stop channel has been closed. The collected heartbeats are provided via the callback.
func Record ¶
func Record(url string, baseTopics []string, stop chan struct{}, cb func(*LogMessage)) error
Record will enable log recording mode on all devices and yield the received log messages until the provided channel has been closed.
Types ¶
type Announcement ¶
An Announcement is returned by Collect.
type Device ¶ added in v0.14.0
type Device struct {
BaseTopic string `json:"base_topic"`
DeviceName string `json:"device_name"`
AppName string `json:"app_name"`
AppVersion string `json:"app_version"`
Parameters map[string]string `json:"parameters,omitempty"`
Metrics []string `json:"metrics,omitempty"`
}
A Device represents a single device in a fleet.
type DiscoverResult ¶ added in v0.14.0
DiscoverResult represents the result of a discovery operation.
type Fleet ¶ added in v0.14.0
type Fleet struct {
Broker string `json:"broker,omitempty"`
Devices map[string]*Device `json:"devices,omitempty"`
}
A Fleet represents a fleet of devices.
func (*Fleet) Collect ¶ added in v0.14.0
Collect will collect and update the flet with found devices for the given duration. It will return a list of devices that have been added to the fleet.
func (*Fleet) Debug ¶ added in v0.14.0
Debug will load the latest coredump from all matching devices. If delete is true, the coredumps are deleted from the devices after retrieval. A table of devices and their corresponding coredumps is returned.
func (*Fleet) Discover ¶ added in v0.14.0
Discover will request all parameters and metrics from all matching devices. The fleet is updated with the reported parameters and metrics, and a list of queried devices is returned.
func (*Fleet) FilterDevices ¶ added in v0.14.0
FilterDevices will return a list of devices that have a name matching the supplied glob pattern.
func (*Fleet) FindDevice ¶ added in v0.14.0
FindDevice returns the first device that has the matching base topic.
func (*Fleet) GetParams ¶ added in v0.14.0
GetParams will request specified parameter from all matching devices. The fleet is updated with the reported value and a list of queried devices is returned.
func (*Fleet) Monitor ¶ added in v0.14.0
func (f *Fleet) Monitor(pattern string, quit chan struct{}, callback func(*Device, *Heartbeat)) error
Monitor will monitor the matching devices and update the fleet accordingly. The specified callback is called for every heartbeat with the updated device and the received heartbeat.
func (*Fleet) Record ¶ added in v0.14.0
func (f *Fleet) Record(pattern string, quit chan struct{}, callback func(time.Time, *Device, string)) error
Record will enable log recording on all matching devices and yield the received log messages until the provided channel has been closed.
func (*Fleet) SetParams ¶ added in v0.14.0
SetParams will set the specified parameter on all matching devices. The fleet is updated with the saved value and a list of updated devices is returned.
func (*Fleet) UnsetParams ¶ added in v0.14.0
UnsetParams will unset the specified parameter on all matching devices. The fleet is updated with the unset value and a list of updated devices is returned.
type Heartbeat ¶
type Heartbeat struct {
ReceivedAt time.Time
BaseTopic string
DeviceName string
AppName string
AppVersion string
AppPartition string
UpTime time.Duration
BatteryLevel float64 // -1, 0 - 1
FreeMemory []float64
CPUUsage []float64 // 0 - 1
SignalStrength int64 // -50 - -100
}
A Heartbeat gathered from a device.
type LogMessage ¶
A LogMessage receive from a device.
type UpdateStatus ¶
UpdateStatus represents the status of a firmware update.
func Update ¶
func Update(url string, baseTopics []string, firmware []byte, jobs int, callback func(string, UpdateStatus)) ([]UpdateStatus, error)
Update will perform a firmware update on the provided devices. If a callback is provided it will be called with the current status of the update.