Documentation
¶
Overview ¶
Package fleet provides a low-level implementation of the NAOS fleet management protocol.
Index ¶
- Constants
- func Debug(backend Backend, devices []*Device, delete bool, jobs int) ([][]byte, error)
- func GetParams(backend Backend, param string, devices []*Device, jobs int) ([]string, error)
- func Monitor(backend Backend, devices []*Device, stop chan struct{}, cb func(*Heartbeat), ...) error
- func Record(backend Backend, devices []*Device, stop chan struct{}, cb func(*LogMessage), ...) error
- func SetParams(backend Backend, param, value string, devices []*Device, jobs int) ([]string, error)
- func UnsetParams(backend Backend, param string, devices []*Device, jobs int) error
- type Announcement
- type Backend
- type Device
- type DiscoverResult
- type Fleet
- func (f *Fleet) Backend() (Backend, error)
- 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) 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 ¶
const ( SourceMQTT = "mqtt" SourceHub = "hub" )
The available device sources.
Variables ¶
This section is empty.
Functions ¶
func Debug ¶
Debug will request coredump debug information from the specified devices. The returned list is aligned with the provided list.
func GetParams ¶
GetParams will receive the provided parameter for all specified devices. The returned list is aligned with the provided list.
func Monitor ¶
func Monitor(backend Backend, devices []*Device, stop chan struct{}, cb func(*Heartbeat), onError func(*Device, error)) error
Monitor will periodically collect heartbeat information from all specified devices until the provided stop channel has been closed. The collected heartbeats are provided via the callback. Devices that fail are reported via the error callback as soon as they fail, potentially from multiple goroutines.
func Record ¶
func Record(backend Backend, devices []*Device, stop chan struct{}, cb func(*LogMessage), onError func(*Device, error)) error
Record will enable log recording mode on all devices and yield the received log messages until the provided channel has been closed. Devices that fail are reported via the error callback as soon as they fail, potentially from multiple goroutines.
Types ¶
type Announcement ¶
type Announcement struct {
Source string
BaseTopic string
DeviceID string
DeviceName string
AppName string
AppVersion string
}
An Announcement is returned by a backend when collecting devices.
Note: Not correctly formatted announcements are ignored.
type Backend ¶ added in v0.17.0
type Backend interface {
// Collect will collect announcements from all available devices for the
// specified duration.
Collect(duration time.Duration) ([]*Announcement, error)
// Resolve will return the addressable devices for the provided fleet
// devices. The returned list is aligned with the provided list. Devices
// that cannot be addressed yield a device that fails when opened.
Resolve(devices []*Device) ([]msg.Device, error)
// Close will close the backend and all underlying connections.
Close()
}
A Backend provides access to the devices of a fleet.
func NewBackend ¶ added in v0.17.0
NewBackend will create a backend for the provided broker and hub. If both are specified, devices are resolved using their configured source.
func NewHubBackend ¶ added in v0.17.0
NewHubBackend will create a backend that connects to the specified NAOS hub.
func NewMQTTBackend ¶ added in v0.17.0
NewMQTTBackend will create a backend that connects to the specified MQTT broker.
type Device ¶ added in v0.14.0
type Device struct {
Source string `json:"source,omitempty"`
BaseTopic string `json:"base_topic"`
DeviceID string `json:"device_id,omitempty"`
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"`
HubURL string `json:"hub_url,omitempty"`
HubToken string `json:"hub_token,omitempty"`
Devices map[string]*Device `json:"devices,omitempty"`
}
A Fleet represents a fleet of devices.
func (*Fleet) Backend ¶ added in v0.17.0
Backend will open a backend for the fleet. The caller is responsible for closing the returned backend. The hub token is read from the NAOS_HUB_TOKEN environment variable if set, otherwise from the fleet.
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) 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), onError func(*Device, error)) 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. Devices that fail are reported via the error callback.
func (*Fleet) Record ¶ added in v0.14.0
func (f *Fleet) Record(pattern string, quit chan struct{}, callback func(time.Time, *Device, string), onError func(*Device, error)) error
Record will enable log recording on all matching devices and yield the received log messages until the provided channel has been closed. Devices that fail are reported via the error callback.
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
Device *Device
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(backend Backend, devices []*Device, firmware []byte, jobs int, callback func(*Device, 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. The returned list is aligned with the provided list.