domain

package module
v0.0.0-...-570e589 Latest Latest
Warning

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

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

README

Archived

This project is archived and no longer maintained.

Admin API for Speed Snitch agent

Go Report Card

Dev setup

  1. Run make dep to have dep install all Go dependencies
  2. Create a local aws.credentials file with format (See aws.credentials.example)
  3. Run make deploy to build and deploy lambda service

Note: You may also want to run dep ensure locally to get all Go packages installed for IDE intelligence.

Documentation

Index

Constants

View Source
const BusinessTimeFormat = "15:04"
View Source
const DataTypeSTNetServerList = "stnetserverlist"
View Source
const DataTypeSpeedTestNetServer = "speedtestnetserver"
View Source
const DateLayout = "2006-01-02"
View Source
const DefaultSpeedTestNetServerHost = "paris1.speedtest.orange.fr:8080"
View Source
const DefaultSpeedTestNetServerID = "5559"
View Source
const LogTypeDowntime = "downtime"
View Source
const LogTypeError = "error"
View Source
const LogTypeRestart = "restarted"
View Source
const PermissionSuperAdmin = "superAdmin"
View Source
const PermissionTagBased = "tagBased"
View Source
const ReportingIntervalDaily = "daily"
View Source
const ReportingIntervalMonthly = "monthly"
View Source
const ReportingIntervalWeekly = "weekly"
View Source
const SecondsPerDay = 86400 // 60 * 60 * 24
View Source
const ServerTypePing = "ping"
View Source
const ServerTypeSpeedTestNet = "speedTest"
View Source
const SpeedTestNetServerList = "http://c.speedtest.net/speedtest-servers-static.php"
View Source
const TaskTypePing = "ping"
View Source
const TaskTypeSpeedTest = "speedTest"
View Source
const TestConfigSpeedTest = "speedTest"
View Source
const UserReqHeaderEmail = "x-user-mail"
View Source
const UserReqHeaderUUID = "x-user-uuid"
View Source
const UserRoleAdmin = "admin"
View Source
const UserRoleSuperAdmin = "superAdmin"

Variables

View Source
var ErrorLogger = log.New(os.Stderr, "ERROR ", log.Llongfile)

Log errors to stderr

Functions

func CanUserSeeReportingEvent

func CanUserSeeReportingEvent(user User, event ReportingEvent) bool

CanUserSeeReportingEvent returns true if the user has a superAdmin role or

if the event has no node associated with it or
if the user has a tag that the event's node has

func CanUserUseNode

func CanUserUseNode(user User, node Node) bool

CanUserUseNode returns true if the user has a superAdmin role or

if the user has a tag that the node has

func CleanBusinessTimes

func CleanBusinessTimes(start, close string) (string, string, error)

CleanBusinessTimes takes to strings for 24-hour times (HH:MM). If they are both empty strings, it returns empty strings. Otherwise makes sure there is no error parsing them into time.Time values, in which case it returns the original values

func CleanMACAddress

func CleanMACAddress(mAddr string) (string, error)

func ClientError

func ClientError(status int, body string) (events.APIGatewayProxyResponse, error)

Similarly add a helper for send responses relating to client errors.

func DoTagsOverlap

func DoTagsOverlap(tags1, tags2 []Tag) bool

DoTagsOverlap returns true if there is a tag with the same UID

in both slices of tags.  Otherwise, returns false.

func GetEnv

func GetEnv(name, defaultValue string) string

func GetResourceIDFromRequest

func GetResourceIDFromRequest(req events.APIGatewayProxyRequest) uint

Get ID from path paramters as uint, otherwise return 0

func GetSliceSafeJSON

func GetSliceSafeJSON(v interface{}) (string, error)

GetSliceSafeJSON handles special logic for slices. If the length is 0, returns "[]". Otherwise, returns the results of json.Marshal(s)

func GetTimeNow

func GetTimeNow() string

GetTimeNow returns the current UTC time in the RFC3339 format

func GetUintFromString

func GetUintFromString(param string) uint

func GetUrlForAgentVersion

func GetUrlForAgentVersion(version, operatingsystem, arch string) string

GetUrlForAgentVersion creates url to agent binary for given version, os, and arch

func InArray

func InArray(needle interface{}, haystack interface{}) (exists bool, index int)

This function will search element inside array with any type. Will return boolean and index for matched element. True and index more than 0 if element is exist. needle is element to search, haystack is slice of value to be search.

func IsValidMACAddress

func IsValidMACAddress(mAddr string) bool

IsValidMacAddress checks whether the input is ...

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

func ReturnCSVOrError

func ReturnCSVOrError(items []TaskLogMapper, filename string, err error) (events.APIGatewayProxyResponse, error)

func ReturnJsonOrError

func ReturnJsonOrError(response interface{}, err error) (events.APIGatewayProxyResponse, error)

func ServerError

func ServerError(err error) (events.APIGatewayProxyResponse, error)

Add a helper for handling errors. This logs any error to os.Stderr and returns a 500 Internal Server Error response that the AWS API Gateway understands.

func TimestampToHumanReadable

func TimestampToHumanReadable(timestamp int64) string

Types

type AssociationReplacements

type AssociationReplacements struct {
	Replacements    interface{}
	AssociationName string
}

type Contact

type Contact struct {
	gorm.Model
	NodeID uint
	Name   string `gorm:"not null"`
	Email  string `gorm:"not null"`
	Phone  string
}

************************************************************** /* /* Define types that will be stored to database using GORM /* /*************************************************************

type Country

type Country struct {
	gorm.Model
	Code string `gorm:"type:varchar(4);not null;unique_index"`
	Name string `gorm:"type:varchar(64);not null"`
}

type ForeignKey

type ForeignKey struct {
	ChildModel  interface{}
	ChildField  string
	ParentTable string
	ParentField string
	OnDelete    string
	OnUpdate    string
}

type HelloRequest

type HelloRequest struct {
	ID      string
	Version string
	Uptime  int64
	OS      string
	Arch    string
}

type NamedServer

type NamedServer struct {
	gorm.Model
	ServerType           string             `gorm:"not null" json:"Type"`
	SpeedTestNetServerID uint               `gorm:"default:null"` // Only needed if ServerType is SpeedTestNetServer
	SpeedTestNetServer   SpeedTestNetServer `json:"-"`
	ServerHost           string             `json:"Host"` // Needed for non-SpeedTestNetServers
	ServerCountry        string             `json:"Country"`
	ServerCountryCode    string             `gorm:"-" json:"CountryCode"` // Only needed if ServerType is SpeedTestNetServer
	Name                 string             `gorm:"not null;unique_index"`
	Description          string
	Notes                string `gorm:"type:varchar(2048)"`
}

type Node

type Node struct {
	gorm.Model
	MacAddr             string  `gorm:"type:varchar(32);not null;unique_index"`
	OS                  string  `gorm:"type:varchar(16); not null"`
	Arch                string  `gorm:"type:varchar(8); not null"`
	RunningVersion      Version `gorm:"foreignkey:RunningVersionID"`
	RunningVersionID    uint    `gorm:"default:null"`
	ConfiguredVersion   Version `gorm:"foreignkey:ConfiguredVersionID" json:"-"`
	ConfiguredVersionID uint    `gorm:"default:null"`
	Uptime              int64   `gorm:"default:0"`
	LastSeen            string  `gorm:"type:varchar(64)"`
	FirstSeen           string  `gorm:"type:varchar(64)"`
	Location            string
	Coordinates         string
	Network             string
	IPAddress           string
	Tasks               []Task
	Contacts            []Contact
	Tags                []Tag `gorm:"many2many:node_tags"`
	ConfiguredBy        string
	Nickname            string
	Notes               string
	BusinessStartTime   string `gorm:"type:varchar(5);default:'00:00'"`
	BusinessCloseTime   string `gorm:"type:varchar(5);default:'00:00'"`
}

func (*Node) IsScheduled

func (n *Node) IsScheduled() bool

type NodeConfig

type NodeConfig struct {
	Version struct {
		Number string
		URL    string
	}
	Tasks []Task
}

type NodeTags

type NodeTags struct {
	gorm.Model
	Tag    Node `gorm:"foreignkey:TagID"`
	TagID  uint
	Node   Node `gorm:"foreignkey:NodeID"`
	NodeID uint
}

type ReportingEvent

type ReportingEvent struct {
	gorm.Model
	Node        Node   `gorm:"foreignkey:NodeID" json:"-"`
	NodeID      uint   `gorm:"default:null;unique_index:idx_node_name_date"`
	Timestamp   int64  `gorm:"type:int(11); not null;default:0"`
	Date        string `gorm:"not null;unique_index:idx_node_name_date"`
	Name        string `gorm:"not null;unique_index:idx_node_name_date"`
	Description string `gorm:"type:varchar(2048)"`
}

func (*ReportingEvent) SetTimestamp

func (r *ReportingEvent) SetTimestamp() error

type ReportingSnapshot

type ReportingSnapshot struct {
	gorm.Model
	Node                      Node
	NodeID                    uint    `gorm:"default:null"`
	Timestamp                 int64   `gorm:"type:int(11); not null"`
	Interval                  string  `gorm:"not null"`
	UploadAvg                 float64 `gorm:"not null;default:0"`
	UploadMax                 float64 `gorm:"not null;default:0"`
	UploadMin                 float64 `gorm:"not null;default:0"`
	UploadTotal               float64 `gorm:"not null;default:0"`
	DownloadAvg               float64 `gorm:"not null;default:0"`
	DownloadMax               float64 `gorm:"not null;default:0"`
	DownloadMin               float64 `gorm:"not null;default:0"`
	DownloadTotal             float64 `gorm:"not null;default:0"`
	LatencyAvg                float64 `gorm:"not null;default:0"`
	LatencyMax                float64 `gorm:"not null;default:0"`
	LatencyMin                float64 `gorm:"not null;default:0"`
	LatencyTotal              float64 `gorm:"not null;default:0"`
	PacketLossAvg             float64 `gorm:"not null;default:0"`
	PacketLossMax             float64 `gorm:"not null;default:0"`
	PacketLossMin             float64 `gorm:"not null;default:0"`
	PacketLossTotal           float64 `gorm:"not null;default:0"`
	SpeedTestDataPoints       int64   `gorm:"not null;default:0"`
	LatencyDataPoints         int64   `gorm:"not null;default:0"`
	NetworkDowntimeSeconds    int64   `gorm:"not null;default:0"`
	NetworkOutagesCount       int64   `gorm:"not null;default:0"`
	RestartsCount             int64   `gorm:"not null;default:0"`
	BizUploadAvg              float64 `gorm:"not null;default:0"`
	BizUploadMax              float64 `gorm:"not null;default:0"`
	BizUploadMin              float64 `gorm:"not null;default:0"`
	BizUploadTotal            float64 `gorm:"not null;default:0"`
	BizDownloadAvg            float64 `gorm:"not null;default:0"`
	BizDownloadMax            float64 `gorm:"not null;default:0"`
	BizDownloadMin            float64 `gorm:"not null;default:0"`
	BizDownloadTotal          float64 `gorm:"not null;default:0"`
	BizLatencyAvg             float64 `gorm:"not null;default:0"`
	BizLatencyMax             float64 `gorm:"not null;default:0"`
	BizLatencyMin             float64 `gorm:"not null;default:0"`
	BizLatencyTotal           float64 `gorm:"not null;default:0"`
	BizPacketLossAvg          float64 `gorm:"not null;default:0"`
	BizPacketLossMax          float64 `gorm:"not null;default:0"`
	BizPacketLossMin          float64 `gorm:"not null;default:0"`
	BizPacketLossTotal        float64 `gorm:"not null;default:0"`
	BizSpeedTestDataPoints    int64   `gorm:"not null;default:0"`
	BizLatencyDataPoints      int64   `gorm:"not null;default:0"`
	BizNetworkDowntimeSeconds int64   `gorm:"not null;default:0"`
	BizNetworkOutagesCount    int64   `gorm:"not null;default:0"`
	BizRestartsCount          int64   `gorm:"not null;default:0"`
}

type STNetServerList

type STNetServerList struct {
	Country Country
	Servers []SpeedTestNetServer `xml:"server"`
}

type STNetServerSettings

type STNetServerSettings struct {
	ServerLists []STNetServerList `xml:"servers"`
}

This relates to the xml response from the external url where we get the list of speedtest.net servers

type SpeedTestNetServer

type SpeedTestNetServer struct {
	gorm.Model
	Lat         string `xml:"lat,attr"`
	Lon         string `xml:"lon,attr"`
	Name        string `xml:"name,attr"`
	Country     string `xml:"country,attr"`
	CountryCode string `xml:"cc,attr"`
	ServerID    string `xml:"id,attr" gorm:"not null"`
	Host        string `xml:"host,attr" gorm:"not null"`
}

type Tag

type Tag struct {
	gorm.Model
	Name        string `gorm:"not null;unique_index"`
	Description string `gorm:"not null"`
	Nodes       []Node `gorm:"many2many:node_tags"`
	Users       []User `gorm:"many2many:user_tags"`
}

type Task

type Task struct {
	gorm.Model
	NodeID        uint
	Type          string `gorm:"type:varchar(32);not null"`
	Schedule      string `gorm:"not null"`
	NamedServer   NamedServer
	NamedServerID uint `gorm:"default:null"`
	ServerHost    string
	TaskData      TaskData `gorm:"type:text"`
}

type TaskData

type TaskData struct {
	StringValues map[string]string
	IntValues    map[string]int
	FloatValues  map[string]float64
	IntSlices    map[string][]int
}

func (*TaskData) Scan

func (td *TaskData) Scan(value interface{}) error

func (TaskData) Value

func (td TaskData) Value() (driver.Value, error)

type TaskLogError

type TaskLogError struct {
	gorm.Model
	Node                 Node
	NodeID               uint  `gorm:"default:null"`
	Timestamp            int64 `gorm:"type:int(11); not null"`
	ErrorCode            string
	ErrorMessage         string
	NamedServer          NamedServer
	NamedServerID        uint `gorm:"default:null"`
	ServerHost           string
	ServerCountry        string
	ServerName           string
	NodeLocation         string
	NodeCoordinates      string
	NodeNetwork          string
	NodeIPAddress        string
	NodeRunningVersion   Version `gorm:"foreignkey:NodeRunningVersionID"`
	NodeRunningVersionID uint    `gorm:"default:null"`
}

type TaskLogMapper

type TaskLogMapper interface {
	GetTaskLogMap() map[string]string
	GetTaskLogKeys() []string
}

type TaskLogNetworkDowntime

type TaskLogNetworkDowntime struct {
	gorm.Model
	Node            Node
	NodeID          uint   `gorm:"default:null"`
	Timestamp       int64  `gorm:"type:int(11); not null;default:0"`
	DowntimeStart   string `gorm:"not null"`
	DowntimeSeconds int64  `gorm:"not null;default:0"`
	NodeNetwork     string
	NodeIPAddress   string
}

func (TaskLogNetworkDowntime) GetTaskLogKeys

func (t TaskLogNetworkDowntime) GetTaskLogKeys() []string

func (TaskLogNetworkDowntime) GetTaskLogMap

func (t TaskLogNetworkDowntime) GetTaskLogMap() map[string]string

type TaskLogPingTest

type TaskLogPingTest struct {
	gorm.Model
	Node                 Node
	NamedServer          NamedServer
	NodeID               uint    `gorm:"default:null"`
	Timestamp            int64   `gorm:"type:int(11); not null"`
	Latency              float64 `gorm:"not null;default:0"`
	PacketLossPercent    float64 `gorm:"not null;default:0"`
	NamedServerID        uint    `gorm:"default:null"`
	ServerHost           string
	ServerCountry        string
	ServerName           string
	NodeLocation         string
	NodeCoordinates      string
	NodeNetwork          string
	NodeIPAddress        string
	NodeRunningVersion   Version `gorm:"foreignkey:NodeRunningVersionID"`
	NodeRunningVersionID uint    `gorm:"default:null"`
}

func (TaskLogPingTest) GetTaskLogKeys

func (t TaskLogPingTest) GetTaskLogKeys() []string

func (TaskLogPingTest) GetTaskLogMap

func (t TaskLogPingTest) GetTaskLogMap() map[string]string

type TaskLogRestart

type TaskLogRestart struct {
	gorm.Model
	Node      Node
	NodeID    uint  `gorm:"default:null"`
	Timestamp int64 `gorm:"type:int(11); not null"`
}

func (TaskLogRestart) GetTaskLogKeys

func (t TaskLogRestart) GetTaskLogKeys() []string

func (TaskLogRestart) GetTaskLogMap

func (t TaskLogRestart) GetTaskLogMap() map[string]string

type TaskLogSpeedTest

type TaskLogSpeedTest struct {
	gorm.Model
	Node                 Node
	NamedServer          NamedServer
	NodeID               uint    `gorm:"default:null"`
	Timestamp            int64   `gorm:"type:int(11); not null"`
	Upload               float64 `gorm:"not null;default:0"`
	Download             float64 `gorm:"not null;default:0"`
	NamedServerID        uint    `gorm:"default:null"`
	ServerHost           string
	ServerCountry        string
	ServerCoordinates    string
	ServerName           string
	NodeLocation         string `gorm:"not null"`
	NodeCoordinates      string `gorm:"not null"`
	NodeNetwork          string
	NodeIPAddress        string  `gorm:"not null"`
	NodeRunningVersion   Version `gorm:"foreignkey:NodeRunningVersionID"`
	NodeRunningVersionID uint    `gorm:"default:null"`
}

func (TaskLogSpeedTest) GetTaskLogKeys

func (t TaskLogSpeedTest) GetTaskLogKeys() []string

func (TaskLogSpeedTest) GetTaskLogMap

func (t TaskLogSpeedTest) GetTaskLogMap() map[string]string

type User

type User struct {
	gorm.Model
	UUID  string
	Name  string `gorm:"not null"`
	Email string `gorm:"not null;unique_index"`
	Role  string `gorm:"not null"`
	Tags  []Tag  `gorm:"many2many:user_tags"`
}

type UserTags

type UserTags struct {
	gorm.Model
	Tag    Node `gorm:"foreignkey:TagID"`
	TagID  uint
	User   User `gorm:"foreignkey:UserID"`
	UserID uint
}

type Version

type Version struct {
	gorm.Model
	Number      string `gorm:"not null;unique_index"`
	Description string `gorm:"not null"`
}

Jump to

Keyboard shortcuts

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