file

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(lines []interface{}) ([]string, error)

Check returns an error if any Error structs are present in the slice of lines

func CompleteCondition

func CompleteCondition(c Condition) bool

CompleteCondition returns true if all parts of the CompleteCondition are holding non-nil equivalent values.

func ConditionCheckLines

func ConditionCheckLines(ctx context.Context, cc chan ConditionCheck, in chan Line, interval time.Duration)

ConditionCheckLines monitors incoming Lines and uses them to assess whether a current condition has been met, which is expressed as Count lines maching the AcceptPattern occuring before the timeout. The Satisfied channel is closed regardless of completion or timeout - there is no indication from ConditionCheckLines whether the condition was satisfied. This is left to any analysis task that the user is presumably coding up separately to analyse the results. In any case, for checking equipment, the condition is normally used to ensure a sufficiency of data with some tolerance, so not exactly meeting the condition is not as much as an issue as it might otherwise be - hence we can leave this to the external analysis to decide.

func FilterLines

func FilterLines(ctx context.Context, a chan FilterAction, in chan Line, w chan Line)

FilterLines intercepts and drops incoming lines, if they don't pass the DenyPattern and AcceptPattern checks

func FormatLine

func FormatLine(line Line) string

FormatLine returns a string representing a Line, ready for writing to file

func LoadFile

func LoadFile(filename string) ([]interface{}, error)

LoadFile reads a .play file and returns a slice of interfaces each one representing a line in the file

func ParseByLine

func ParseByLine(in io.Reader, out chan interface{}) error

ParseByLine reads from the supplied io.Reader, line by line, parsing each line into a struct representing known actions or errors, all of which are returned over out channel

func ParseFile

func ParseFile(filename string, out chan interface{}) error

ParseFile parses a file into an interface per line, which is sent over the out channel.

func ParseLine

func ParseLine(line string) interface{}

ParseLine parses a line and returns a struct representing it, e.g. Wait, Error, Comment, Send.

func Play

func Play(ctx context.Context, closed chan struct{}, lines []interface{}, a chan FilterAction, s chan string, c chan ConditionCheck, w chan Line)

Play takes a slice of Line and plays each Line as required, e.g. Wait, Send (with Delay or Condition), Comment (e.g. echo to file)

func Run

func Run(ctx context.Context, hup chan os.Signal, session, token, logfilename, playfilename string, interval time.Duration, check, force bool) error

Run connects to the session and handles writing to/from files If a playfilename is present, the connection is closed once the file has finished playing A long delay can be left at the end of the playfile to keep the connection open and logging Connections without a playfilename are kept open indefinitely. interval sets how often the condition check timeout is checked - this has a small effect on CPU usage, and can be set at say 10ms for testing, or 1s or more for usage with long collection periods

func Tee

func Tee(ctx context.Context, in, in0, in1 chan Line)

Tee copies incoming Lines on in into copies on in0 and in1 so that they can be consumed for different purposes

func Write

func Write(ctx context.Context, in chan Line, w io.Writer)

Write writes the line to the file, after formatting, returning when the context is cancelled, or the in channel is closed.

func WsMessageToLine

func WsMessageToLine(ctx context.Context, in chan reconws.WsMessage, out chan Line)

WsMessageToLine converts reconws.WsMessage to Line format, adding a timestamp.

Types

type Comment

type Comment struct {
	Msg  string
	Echo bool
}

Comment represents a comment in the playfile which can either be ignored, or echoed to the local logging file.

type Condition

type Condition struct {
	AcceptPattern regexp.Regexp
	Count         int
	Timeout       time.Duration
}

Condition represents a condition for waiting for a number of responses meeting a pattern, or a maximum waiting time, whichever occurs first

func (*Condition) String

func (c *Condition) String() string

String returns a string representation of a Condition commands that mimics its representation in .play file <AcceptPattern, Count, Timeout>

type ConditionCheck

type ConditionCheck struct {
	Condition Condition
	Satisfied chan struct{}
}

ConditionCheck represents a condition that should be checked by ConditionCheckLines.

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error represents an error in the parsing of the playfile

type Filter

type Filter struct {
	AcceptPatterns *map[string]regexp.Regexp
	DenyPatterns   *map[string]regexp.Regexp
}

Filter represents the setting of the logging Filter with a map of patterns to deny (DenyPatterns), and a map of patterns to accept (AcceptPatterns) The mapping is according to the original string used to construct the filter.

func NewFilter

func NewFilter() *Filter

NewFilter returns a pointer to a new, initialised filter ready for use

func (*Filter) Accept

func (f *Filter) Accept(line string) bool

Accept returns true if this line is passed by the filter

func (*Filter) AddAcceptPattern

func (f *Filter) AddAcceptPattern(p *regexp.Regexp)

AddAcceptPattern adds a pattern to the AcceptPatterns that will be used to check if a message is accepted (passed)

func (*Filter) AddDenyPattern

func (f *Filter) AddDenyPattern(p *regexp.Regexp)

AddDenyPattern adds a pattern to the DenyPatterns that will be used to check if a message is denied (blocked)

func (*Filter) AllPass

func (f *Filter) AllPass() bool

AllPass returns true if both AcceptPatterns and DenyPatterns are empty, i.e. all messages should pass. we do this for convenience and efficiency, rather than having an explict 'all pass' filter added to the AcceptList because we'd have to remove it the first time we add a filter and the second time we add a filter we'd have to check whether the first filter was the allpass one, and we might not know whether that was from initialisation or explicitly added by a user ....

func (*Filter) DeleteAcceptPattern

func (f *Filter) DeleteAcceptPattern(p *regexp.Regexp)

DeleteAcceptPattern will remove a given pattern from the list of patterns used to check for acceptance of a line

func (*Filter) DeleteDenyPattern

func (f *Filter) DeleteDenyPattern(p *regexp.Regexp)

DeleteDenyPattern will remove a given pattern from the list of patterns used to check for denial of a line

func (*Filter) Deny

func (f *Filter) Deny(line string) bool

Deny returns true if this line is blocked by the filter

func (*Filter) Pass

func (f *Filter) Pass(line string) bool

Pass returns a bool indicating whether a line passes (true) or is blocked (false) by the filter

func (*Filter) Reset

func (f *Filter) Reset()

Reset replaces both AcceptPatterns and DenyPatterns with empty initialised maps, ready for use

type FilterAction

type FilterAction struct {
	Verb    FilterVerb
	Pattern *regexp.Regexp
}

FilterAction represents an action taken on the setting of the logging filter

type FilterVerb

type FilterVerb int

FilterVerb represents names of actions that can be taken on settings of the logging filter

const (
	//Unknown do nothing
	Unknown FilterVerb = iota
	// Accept add an AcceptPattern
	Accept
	// Deny add a DenyPattern
	Deny
	// Remove all AcceptPattern and DenyPatterns (make filter all-pass again)
	Reset
)

These const represent what type of filter action is needed

func (*FilterVerb) String

func (v *FilterVerb) String() string

type Line

type Line struct {
	Time    time.Time
	Content string
}

Line represents content of a line received from the relay and the time it was received.

type Send

type Send struct {
	Msg       string
	Delay     time.Duration
	Condition Condition
}

Send is an instruction to send a message after a Delay and optionally wait for a condition to be met before moving to the next message to send

type Wait

type Wait struct {
	Delay time.Duration
}

Wait represents an instruction to wait before proceeding to subsequent instructions, useful for testing mostly.

Jump to

Keyboard shortcuts

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