lib

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Copyright © 2022 Nicolas MASSE

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

View Source
const (
	MQTT_QOS_0 = 0 // QoS 1
	MQTT_QOS_1 = 1 // QoS 2
	MQTT_QOS_2 = 2 // QoS 3
)

Those flags define the MQTT Quality of Service (QoS) levels

Variables

This section is empty.

Functions

func NewMqttClient

func NewMqttClient(config MqttConfig) (mqtt.Client, error)

NewMqttClient creates a new MQTT client and connects to the broker

func SetMqttLogger

func SetMqttLogger(logger *log.Logger)

SetMqttLogger sets the logger to be used by the underlying MQTT library

Types

type Archiver

type Archiver struct {
	S3Config         S3Config    // credentials to connect to S3
	MqttConfig       MqttConfig  // credentials to connect to MQTT
	WorkingDir       string      // location to store JSON files
	Logger           *log.Logger // a logger
	SubscribePattern string      // the pattern (ie. "#") to subscribe to
	FilterRegex      string      // topics matching this regex will filtered out
	// contains filtered or unexported fields
}

An Archiver represents the process of archiving MQTT events to S3. The Archiver will subscribe to topics designated by the SubscribePattern, save events to a JSON file in the WorkingDir. It will rotate the JSON file every day, compress it and send it to S3. The files are stored in S3 in a folder per year.

func (*Archiver) StartArchive

func (archiver *Archiver) StartArchive() error

StartArchive starts the archiving process. It is not safe to call this method multiple times on the same object.

func (*Archiver) StopArchive

func (archiver *Archiver) StopArchive()

StopArchive stops the archiving process. It is not safe to call this method multiple times on the same object.

type EventLogEntry

type EventLogEntry struct {
	Version   int       `json:"v"`            // Version number (in case the format changes in the future)
	Timestamp time.Time `json:"ts,omitempty"` // An optional timestamp
	Topic     string    `json:"topic"`        // The topic this event comes from
	Payload   []byte    `json:"data"`         // The actual data (is base64 encoded in the JSON structure)
}

An EventLogEntry represents a single event received from the MQTT broker

type MqttConfig

type MqttConfig struct {
	BrokerURL   string        // broker url (tcp://hostname:port or ssl://hostname:port)
	Username    string        // username (optional)
	Password    string        // password (optional)
	ClientID    string        // MQTT ClientID
	Timeout     time.Duration // how much time to wait for connect and subscribe operations to complete
	GracePeriod time.Duration // how much time to wait for the disconnect operation to complete
}

An MqttConfig represents the required information to connect to an MQTT broker.

type S3Config

type S3Config struct {
	Endpoint   string // S3 endpoint. Format is "hostname:port"
	AccessKey  string // S3 access key (or username)
	SecretKey  string // S3 access key (or token)
	UseSSL     bool   // Enable/disable the use of TLS to connect to S3
	BucketName string // The name of the bucket where to store archives
}

An S3Config represents the mandatory parameters to connect to an S3 service

Directories

Path Synopsis
cli
cmd

Jump to

Keyboard shortcuts

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