disttrace

package
v0.0.0-...-9e7af6b Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2021 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigPollerProcRunning = make(chan bool, 1)

ConfigPollerProcRunning mutex for graceful shutdown

View Source
var OSSigReceived = make(chan bool, 1)

OSSigReceived mutex to show OS signal was received

Functions

func AlertErrorf

func AlertErrorf(source string, text string, args ...interface{})

AlertErrorf creates a new alert on web GUI of 'error' severity

func AlertInfof

func AlertInfof(source string, text string, args ...interface{})

AlertInfof creates a new alert on web GUI of 'info' severity

func AlertWarnf

func AlertWarnf(source string, text string, args ...interface{})

AlertWarnf creates a new alert on web GUI of 'warn' severity

func AuthUser

func AuthUser(name string, pwd string, db *DB) bool

AuthUser checks supplied username/PW combination

func CheckForQuit

func CheckForQuit() bool

CheckForQuit checks if should initiate quit

func CheckSlaveAuth

func CheckSlaveAuth(db *DB, user string, secret string) (bool, uuid.UUID)

CheckSlaveAuth checks supplied credentials for validity

func CleanAndCheckFileNameAndPath

func CleanAndCheckFileNameAndPath(path string) (string, error)

CleanAndCheckFileNameAndPath validates a path and filename

func ConfigPoller

func ConfigPoller(masterHost string, masterPort string, slave Slave, ppCfg **SlaveConfig)

ConfigPoller runs as process, periodically polls slave configuration on master

func DebugPrintAllArguments

func DebugPrintAllArguments(args ...string)

DebugPrintAllArguments prints all supplied arguments with their valie

func DeleteSlave

func DeleteSlave(db *DB, slaveID uuid.UUID) error

DeleteSlave deletes an existing slave from the db

func DeleteTarget

func DeleteTarget(db *DB, targetID uuid.UUID) error

DeleteTarget deletes an existing target from the db

func DeleteUser

func DeleteUser(db *DB, userID uuid.UUID) error

DeleteUser deletes an existing user from the db

func GetToken

func GetToken(claims AuthClaims) (token []byte, err error)

GetToken generates a new token with given claims

func GetUptime

func GetUptime() time.Duration

GetUptime returns the application's uptime since launch

func ListenForOSSignals

func ListenForOSSignals()

ListenForOSSignals registers for OS signals and waits for them

func PrintUsageAndExit

func PrintUsageAndExit(fSet flag.FlagSet, exitWithError bool)

PrintUsageAndExit prints usage instructions for cmdline arguments

func QuitGracefully

func QuitGracefully()

QuitGracefully sets exit signal for everyone

func SetLogOptions

func SetLogOptions(logger *logrus.Logger, logPathAndName string, logLevel string)

SetLogOptions sets the logging detail level

func TokenFromAuthHeader

func TokenFromAuthHeader(header string) (token string)

TokenFromAuthHeader extracts the JWT token from the Authorization header

func ValidateTraceResult

func ValidateTraceResult(res TraceResult) (bool, error)

ValidateTraceResult validates contents of a TraceResult

func VerifyToken

func VerifyToken(token []byte) (err error)

VerifyToken verifies a token

func WaitForOSSignalAndQuit

func WaitForOSSignalAndQuit()

WaitForOSSignalAndQuit blocks until a signal from OS is received, then sends exit signal

func WaitForValidConfig

func WaitForValidConfig(name string, ppCfg **SlaveConfig)

WaitForValidConfig blocks until ppCfg holds a valid config

Types

type AppAlert

type AppAlert struct {
	Time     time.Time
	Text     string
	Source   string
	Severity string
}

AppAlert holds an application notification, e.g. errors

func GetAlerts

func GetAlerts() []AppAlert

GetAlerts returns the last alerts

type AuthClaims

type AuthClaims struct {
	Payload  jwt.Payload
	Username string
}

AuthClaims holds the signed auth info

type DB

type DB struct {
	*sql.DB
}

DB wraps sql.DB

func InitDBConnectionAndUpdate

func InitDBConnectionAndUpdate(dataSourceName string) (*DB, error)

InitDBConnectionAndUpdate initializes a connection to the database and upgrades the schema if needed

func (*DB) Begin

func (db *DB) Begin() (*Tx, error)

Begin creates and returns a new transaction

func (*DB) Close

func (db *DB) Close() error

Close closes the connection to the database

func (*DB) Exec

func (db *DB) Exec(query string, args ...interface{}) (sql.Result, error)

Exec executes a statement and returns the result

func (*DB) Ping

func (db *DB) Ping() error

Ping verifies the connection to the database and establishes it if needed

func (*DB) Query

func (db *DB) Query(query string, args ...interface{}) (*sql.Rows, error)

Query executes a query and returns a reference to the resultset

func (*DB) QueryRow

func (db *DB) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow executes a query and returns a single row

type Slave

type Slave struct {
	ID     uuid.UUID `json:",omitempty" valid:"-"`
	Name   string    `valid:"alphanum,	required"`
	Secret string    `valid:"alphanum,	required"`
}

Slave holds all infos about a slave

func CreateSlave

func CreateSlave(db *DB, slave Slave) (Slave, error)

CreateSlave stores a new slave in the db

func GetSlave

func GetSlave(slaveID uuid.UUID, db *DB) (Slave, error)

GetSlave returns the specified slave from DB

func GetSlaves

func GetSlaves(db *DB) ([]Slave, error)

GetSlaves reads all slaves from the db

func UpdateSlave

func UpdateSlave(db *DB, slave Slave) (Slave, error)

UpdateSlave updates an existing new slave in the db

type SlaveConfig

type SlaveConfig struct {
	ID         uuid.UUID     `json:",omitempty" valid:"-"`
	MasterHost string        `json:"-" valid:"-"`
	MasterPort string        `json:"-" valid:"-"`
	Targets    []TraceTarget `valid:"-"`
}

SlaveConfig holds the configuration for a dist-traceroute-slave

type Stmt

type Stmt struct {
	*sql.Stmt
}

Stmt wraps sql.Stmt

func (*Stmt) Exec

func (stmt *Stmt) Exec(args ...interface{}) (sql.Result, error)

Exec executes a prepared statement

type SubmitResult

type SubmitResult struct {
	Success       bool
	Error         string
	RetryPossible bool
}

SubmitResult holds information about success or failure of submission of result(s)

type TraceResult

type TraceResult struct {
	Slave    Slave                   `valid:"		required"`
	ID       uuid.UUID               `valid:"-"`
	DateTime time.Time               `valid:"-"`
	Target   TraceTarget             `valid:"		required"`
	Success  bool                    `valid:"-"`
	HopCount int                     `valid:"int,	required, 	range(1|100)"`
	Hops     []tracert.TracerouteHop `valid:"-"`
}

TraceResult holds all relevant information of a single traceroute run

type TraceTarget

type TraceTarget struct {
	ID        uuid.UUID `valid:"-"`
	Name      string    `valid:"alphanum,	required"`
	Address   string    `valid:"host,		required"`
	Retries   int       `valid:"int,	required,	range(0|10)"`
	MaxHops   int       `valid:"int,	required,	range(1|100)"`
	TimeoutMs int       `valid:"int,	required,	range(1|10000)"`
}

TraceTarget contains information about a single dist-traceroute target

func CreateTarget

func CreateTarget(db *DB, target TraceTarget) (TraceTarget, error)

CreateTarget stores a new target in the db

func GetTarget

func GetTarget(targetID uuid.UUID, db *DB) (TraceTarget, error)

GetTarget returns the specified target from DB

func GetTargets

func GetTargets(db *DB) ([]TraceTarget, error)

GetTargets reads all targets from the db

func UpdateTarget

func UpdateTarget(db *DB, target TraceTarget) (TraceTarget, error)

UpdateTarget updates an existing new target in the db

type Tx

type Tx struct {
	*sql.Tx
}

Tx wraps sql.Tx

func (*Tx) Commit

func (tx *Tx) Commit() error

Commit commits a transaction to the database

func (*Tx) Exec

func (tx *Tx) Exec(query string, args ...interface{}) (sql.Result, error)

Exec executes a statement on the given transaction and returns the result

func (*Tx) Prepare

func (tx *Tx) Prepare(query string) (*Stmt, error)

Prepare creates a prepared statement

func (*Tx) Query

func (tx *Tx) Query(query string, args ...interface{}) (*sql.Rows, error)

Query executes a query on the given transaction and returns a reference to the resultset

func (*Tx) QueryRow

func (tx *Tx) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow executes a query on the given transaction and returns a single row

func (*Tx) Rollback

func (tx *Tx) Rollback() error

Rollback aborts the transaction

type User

type User struct {
	ID                  uuid.UUID
	Name                string
	Password            []byte
	Salt                int
	PasswordNeedsChange bool
}

User contains information about a single dist-traceroute user

func CreateUser

func CreateUser(db *DB, user User) (User, error)

CreateUser stores a new user in the db

func GetUser

func GetUser(userID uuid.UUID, db *DB) (User, error)

GetUser returns the specified user from DB

func GetUsers

func GetUsers(db *DB) ([]User, error)

GetUsers reads all users from the db

func UpdateUser

func UpdateUser(db *DB, user User) (User, error)

UpdateUser updates an existing user in the db

Jump to

Keyboard shortcuts

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