Documentation
¶
Index ¶
- Constants
- Variables
- func CanUserSeeReportingEvent(user User, event ReportingEvent) bool
- func CanUserUseNode(user User, node Node) bool
- func CleanBusinessTimes(start, close string) (string, string, error)
- func CleanMACAddress(mAddr string) (string, error)
- func ClientError(status int, body string) (events.APIGatewayProxyResponse, error)
- func DoTagsOverlap(tags1, tags2 []Tag) bool
- func GetEnv(name, defaultValue string) string
- func GetResourceIDFromRequest(req events.APIGatewayProxyRequest) uint
- func GetSliceSafeJSON(v interface{}) (string, error)
- func GetTimeNow() string
- func GetUintFromString(param string) uint
- func GetUrlForAgentVersion(version, operatingsystem, arch string) string
- func InArray(needle interface{}, haystack interface{}) (exists bool, index int)
- func IsValidMACAddress(mAddr string) bool
- func ReturnCSVOrError(items []TaskLogMapper, filename string, err error) (events.APIGatewayProxyResponse, error)
- func ReturnJsonOrError(response interface{}, err error) (events.APIGatewayProxyResponse, error)
- func ServerError(err error) (events.APIGatewayProxyResponse, error)
- func TimestampToHumanReadable(timestamp int64) string
- type AssociationReplacements
- type Contact
- type Country
- type ForeignKey
- type HelloRequest
- type NamedServer
- type Node
- type NodeConfig
- type NodeTags
- type ReportingEvent
- type ReportingSnapshot
- type STNetServerList
- type STNetServerSettings
- type SpeedTestNetServer
- type Tag
- type Task
- type TaskData
- type TaskLogError
- type TaskLogMapper
- type TaskLogNetworkDowntime
- type TaskLogPingTest
- type TaskLogRestart
- type TaskLogSpeedTest
- type User
- type UserTags
- type Version
Constants ¶
const BusinessTimeFormat = "15:04"
const DataTypeSTNetServerList = "stnetserverlist"
const DataTypeSpeedTestNetServer = "speedtestnetserver"
const DateLayout = "2006-01-02"
const DefaultSpeedTestNetServerHost = "paris1.speedtest.orange.fr:8080"
const DefaultSpeedTestNetServerID = "5559"
const LogTypeDowntime = "downtime"
const LogTypeError = "error"
const LogTypeRestart = "restarted"
const PermissionSuperAdmin = "superAdmin"
const PermissionTagBased = "tagBased"
const ReportingIntervalDaily = "daily"
const ReportingIntervalMonthly = "monthly"
const ReportingIntervalWeekly = "weekly"
const SecondsPerDay = 86400 // 60 * 60 * 24
const ServerTypePing = "ping"
const ServerTypeSpeedTestNet = "speedTest"
const SpeedTestNetServerList = "http://c.speedtest.net/speedtest-servers-static.php"
const TaskTypePing = "ping"
const TaskTypeSpeedTest = "speedTest"
const TestConfigSpeedTest = "speedTest"
const UserReqHeaderEmail = "x-user-mail"
const UserReqHeaderUUID = "x-user-uuid"
const UserRoleAdmin = "admin"
const UserRoleSuperAdmin = "superAdmin"
Variables ¶
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 ¶
CanUserUseNode returns true if the user has a superAdmin role or
if the user has a tag that the node has
func CleanBusinessTimes ¶
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 ClientError ¶
func ClientError(status int, body string) (events.APIGatewayProxyResponse, error)
Similarly add a helper for send responses relating to client errors.
func DoTagsOverlap ¶
DoTagsOverlap returns true if there is a tag with the same UID
in both slices of tags. Otherwise, returns false.
func GetResourceIDFromRequest ¶
func GetResourceIDFromRequest(req events.APIGatewayProxyRequest) uint
Get ID from path paramters as uint, otherwise return 0
func GetSliceSafeJSON ¶
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 GetUrlForAgentVersion ¶
GetUrlForAgentVersion creates url to agent binary for given version, os, and arch
func InArray ¶
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 ¶
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.
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 ForeignKey ¶
type HelloRequest ¶
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 ¶
type NodeConfig ¶
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 TaskData ¶
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 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