agent

package module
v0.0.0-...-ccadce5 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: MIT Imports: 15 Imported by: 0

README

Archived

This project is archived and is no longer maintained.

Speed Snitch Agent

Go Report Card

This repo includes the source for our Speed Snitch agent which we use to monitor and report on internet speeds at remote locations. The agent communicates with a management API to receive configuration details related to Tasks (speed tests, latency tests, etc.).

This project is intended to work in conjunction with the speed-snitch-admin-api and speed-snitch-admin-ui projects for the central management capabilities. They can be found at github.com/silinternational.

Build Instructions

  1. Run make dep
  2. Build binary (this will create cmd/speedsnitch/speedsnitch):
    • Mac: make mac
    • Linux: make linux
    • Windows: make windows

Debian Package

  1. Edit fpm.env based on the contents of fpm.env.dist but using the correct values
  2. Run make fpm
  3. The package will be created in ./docker/fpm as speedsnitch.linux_0.1.2_amd64.deb

Release Process

  1. Create new release branch for version number from develop following convention x.x.x (note: don't include release in the name.)
  2. Update source with new version number
  3. Commit/push changes
  4. Create PR from x.x.x to develop
  5. After PR reviewed and merged, create PR from develop to master
  6. Review and merge PR to master

Special Instructions for systemd on a Raspberry Pi

On a Raspberry Pi, you can have systemd ensure the speedsnitch executable is always running and restarts following an update.

  1. Edit extras/pi_lib_systemd_system/speedSnitchAgent.service to have the correct values.
  2. Copy (as root) the following files into /usr/lib/systemd/system/ ...
    • extras/pi_lib_systemd_system/speedSnitchAgent.service
    • extras/pi_lib_systemd_system/speedSnitchWatcher.service
    • extras/pi_lib_systemd_system/speedSnitchWatcher.path
  3. Create symlinks for these files ...
    • $ cd /etc/systemd/system
    • $ mkdir -p default.target.wants
    • $ cd default.target.wants
    • $ sudo ln -s /usr/lib/systemd/system/speedSnitchAgent.service speedSnitchAgent.service
    • $ sudo ln -s /usr/lib/systemd/system/speedSnitchWatcher.service speedSnitchWatcher.service
    • $ sudo ln -s /usr/lib/systemd/system/speedSnitchWatcher.path speedSnitchWatcher.path
  4. In the /usr/lib/systemd/system/speedSnitchAgent.service file replace the parameters in the ExecStart value.
  5. Reload the systemd daemons and start the new services
    • $ sudo systemctl daemon-reload
    • $ sudo systemctl start speedSnitchWatcher.path
    • $ sudo systemctl start speedSnitchWatcher.service
  6. In order to view the status ... $ sudo systemctl status speedSnitchAgent.service
  7. In order to see more lines from its output ... $ journalctl -e -u speedSnitchAgent.service

License - MIT

MIT License

Copyright (c) 2018 SIL International

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.

Documentation

Index

Constants

View Source
const ConfigFileName = "speedsnitch.txt"
View Source
const ExeFileName = "speedsnitch"
View Source
const MaxSecondsOffset = 50
View Source
const NetworkOffline = "offline"
View Source
const NetworkOnline = "online"
View Source
const TypeError = "error"
View Source
const TypePing = "ping"
View Source
const TypeReboot = "reboot"
View Source
const TypeRestarted = "restarted" // For sending a log after a restart
View Source
const TypeSpeedTest = "speedTest"
View Source
const Version = "0.0.13"

Variables

This section is empty.

Functions

func DownloadFile

func DownloadFile(filepath string, url string, mode os.FileMode) error

DownloadFile will download a url to a local file. It's efficient because it will write as it downloads and not load the whole file into memory.

func GetBlacklistedMacAddrPrefixes

func GetBlacklistedMacAddrPrefixes() []string

func GetMacAddr

func GetMacAddr() string

getMacAddr gets the lowest (alphabetically) MAC hardware address of the host machine

func GetRandomSecondAsString

func GetRandomSecondAsString() string

func GetTimeNow

func GetTimeNow() string

GetTimeNow returns the current UTC time in the RFC3339 format

func IsValidMACAddress

func IsValidMACAddress(mAddr string, blacklistPrefixes []string) bool

IsValidMacAddress checks whether the input is ...

  • 12 hexacedimal digits OR
  • 6 pairs of hexadecimal digits separated by colons and/or hyphens

It also rejects those that begin with text that matches an entry in the blacklistPrefixes slice.

func Reboot

func Reboot() error

Reboot checks the GOOS and GOARCH and if they are valid, reboots the system

func VerifyFileSignature

func VerifyFileSignature(directory, targetFile, signedFile string, keys []io.Reader) error

VerifyFileSignature only checks the signature of the target file if there is a gpg key to use

Types

type APIConfig

type APIConfig struct {
	BaseURL string
	APIKey  string
}

func GetAppConfig

func GetAppConfig(reader io.Reader) APIConfig

GetAppConfig accepts an io.Reader for testing purposes. If the io.Reader param is nil, then it uses the default config file to provide an custom APIConfig

type Config

type Config struct {
	Version struct {
		Number string `json:"Number"`
		URL    string `json:"URL"`
	} `json:"Version"`

	Log struct {
		Format      string
		Destination string
	}

	Tasks []Task `json:"Tasks"`
}

type LogReporter

type LogReporter interface {
	Process(string, string, ...interface{}) error
}

Any struct that implements a Process method - for swapping which Logging service we use

type LoggerInstance

type LoggerInstance struct {
	LogReporter
}

Needed to be able to swap in a customized logging struct that implements a Logger To use this ...

` // mycustomlogapp.go
`type Logger struct {}`
`func (l Logger) Process(logKey, text string, a ...interface{}) { ... }`

`// main.go
`logger := agent.LoggerInstance{mycustomlogapp.Logger{}}`

type SpeedTestInstance

type SpeedTestInstance struct {
	SpeedTestRunner
}

type SpeedTestResults

type SpeedTestResults struct {
	Download          float64       `json:"Download,omitempty"`          // Mb per second
	Upload            float64       `json:"Upload,omitempty"`            // Mb per second
	Latency           time.Duration `json:"Latency,omitempty"`           // Latency in nanoseconds
	PacketLossPercent float64       `json:"PacketLossPercent,omitempty"` // Percentage of package loss on ping
	Timestamp         time.Time     `json:"Timestamp"`
	Error             string        `json:"Error"`
}

func (*SpeedTestResults) CleanData

func (s *SpeedTestResults) CleanData()

type SpeedTestRunner

type SpeedTestRunner interface {
	Run(TaskData) (SpeedTestResults, error)
}

type Task

type Task struct {
	Type          string   `json:"Type"`
	Schedule      string   `json:"Schedule"`
	NamedServerID uint     `json:"NamedServerID"`
	ServerHost    string   `json:"ServerHost"`
	TaskData      TaskData `json:"TaskData"`
	SpeedTestRunner
}

type TaskData

type TaskData struct {
	StringValues map[string]string  `json:"StringValues"`
	IntValues    map[string]int     `json:"IntValues"`
	FloatValues  map[string]float64 `json:"FloatValues"`
	IntSlices    map[string][]int   `json:"IntSlices"`
}

type TaskLogEntry

type TaskLogEntry struct {
	Timestamp         int64   `json:"Timestamp"`
	EntryType         string  `json:"EntryType"`
	ServerCountry     string  `json:"ServerCountry,omitempty"`
	NamedServerID     uint    `json:"NamedServerID,omitempty"`
	Upload            float64 `json:"Upload,omitempty"`
	Download          float64 `json:"Download,omitempty"`
	Latency           float64 `json:"Latency,omitempty"`
	PacketLossPercent float64 `json:"PacketLossPercent,omitempty"`
	ErrorCode         string  `json:"ErrorCode,omitempty"`
	ErrorMessage      string  `json:"ErrorMessage,omitempty"`
	DowntimeStart     string  `json:"DowntimeStart,omitempty"`
	DowntimeSeconds   int64   `json:"DowntimeSeconds,omitempty"`
}

func GetTaskLogEntry

func GetTaskLogEntry(entryType string) TaskLogEntry

Directories

Path Synopsis
cmd
lib

Jump to

Keyboard shortcuts

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