scoutclient

package
Version: v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package scoutclient is an API client to the Choria Scout agent Version 0.26.0.

Actions:

  • Checks - Obtain a list of checks and their current status
  • Resume - Resume active checking of one or more checks
  • Maintenance - Pause checking of one or more checks
  • GossValidate - Performs a Goss validation using a specific file
  • Trigger - Force an immediate check of one or more checks

Index

Constants

View Source
const (
	// DisplayDDL shows results based on the configuration in the DDL file
	DisplayDDL = DisplayMode(iota)
	// DisplayOK shows only passing results
	DisplayOK
	// DisplayFailed shows only failed results
	DisplayFailed
	// DisplayAll shows all results
	DisplayAll
	// DisplayNone shows no results
	DisplayNone
)
View Source
const (
	// OK is the reply status when all worked
	OK = StatusCode(iota)

	// Aborted is status for when the action could not run, most failures in an action should set this
	Aborted

	// UnknownAction is the status for unknown actions requested
	UnknownAction

	// MissingData is the status for missing input data
	MissingData

	// InvalidData is the status for invalid input data
	InvalidData

	// UnknownError is the status general failures in agents should set when things go bad
	UnknownError
)

Variables

This section is empty.

Functions

func DDL

func DDL() (*agent.DDL, error)

DDL is a parsed and loaded DDL for the agent

func DDLBytes

func DDLBytes() ([]byte, error)

DDLBytes is the raw JSON encoded DDL file for the agent

Types

type BroadcastNS

type BroadcastNS struct {
	sync.Mutex
	// contains filtered or unexported fields
}

BroadcastNS is a NodeSource that uses the Choria network broadcast method to discover nodes

func (*BroadcastNS) Discover

func (b *BroadcastNS) Discover(ctx context.Context, fw inter.Framework, filters []FilterFunc) ([]string, error)

Discover performs the discovery of nodes against the Choria Network

func (*BroadcastNS) Reset

func (b *BroadcastNS) Reset()

Reset resets the internal node cache

type ChecksOutput

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

ChecksOutput is the output from the checks action

func (*ChecksOutput) Checks

func (d *ChecksOutput) Checks() []interface{}

Checks is the value of the checks output

Description: Details about each check

func (*ChecksOutput) HashMap

func (d *ChecksOutput) HashMap() map[string]interface{}

HashMap is the raw output data

func (*ChecksOutput) JSON

func (d *ChecksOutput) JSON() ([]byte, error)

JSON is the JSON representation of the output data

func (*ChecksOutput) ParseChecksOutput

func (d *ChecksOutput) ParseChecksOutput(target interface{}) error

ParseChecksOutput parses the result value from the Checks action into target

func (*ChecksOutput) ResultDetails

func (d *ChecksOutput) ResultDetails() *ResultDetails

ResultDetails is the details about the request

type ChecksRequester

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

ChecksRequester performs a RPC request to scout#checks

func (*ChecksRequester) Do

Do performs the request

type ChecksResult

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

ChecksResult is the result from a checks action

func (*ChecksResult) AllOutputs added in v0.26.0

func (d *ChecksResult) AllOutputs() []*ChecksOutput

AllOutputs provide access to all outputs

func (*ChecksResult) EachOutput

func (d *ChecksResult) EachOutput(h func(r *ChecksOutput))

EachOutput iterates over all results received

func (*ChecksResult) RenderResults

func (d *ChecksResult) RenderResults(w io.Writer, format RenderFormat, displayMode DisplayMode, verbose bool, silent bool, colorize bool, log Log) error

func (*ChecksResult) Stats

func (d *ChecksResult) Stats() Stats

Stats is the rpc request stats

type DisplayMode

type DisplayMode uint8

DisplayMode overrides the DDL display hints

type ExternalNS added in v0.20.0

type ExternalNS struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ExternalNS is a NodeSource that calls an external command for discovery

func (*ExternalNS) Discover added in v0.20.0

func (p *ExternalNS) Discover(ctx context.Context, fw inter.Framework, filters []FilterFunc) ([]string, error)

func (*ExternalNS) Reset added in v0.20.0

func (p *ExternalNS) Reset()

Reset resets the internal node cache

type FilterFunc

type FilterFunc func(f *protocol.Filter) error

FilterFunc can generate a Choria filter

type GossValidateOutput

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

GossValidateOutput is the output from the goss_validate action

func (*GossValidateOutput) Failures

func (d *GossValidateOutput) Failures() int64

Failures is the value of the failures output

Description: The number of tests that failed

func (*GossValidateOutput) HashMap

func (d *GossValidateOutput) HashMap() map[string]interface{}

HashMap is the raw output data

func (*GossValidateOutput) JSON

func (d *GossValidateOutput) JSON() ([]byte, error)

JSON is the JSON representation of the output data

func (*GossValidateOutput) ParseGossValidateOutput

func (d *GossValidateOutput) ParseGossValidateOutput(target interface{}) error

ParseGossValidateOutput parses the result value from the GossValidate action into target

func (*GossValidateOutput) ResultDetails

func (d *GossValidateOutput) ResultDetails() *ResultDetails

ResultDetails is the details about the request

func (*GossValidateOutput) Results

func (d *GossValidateOutput) Results() []interface{}

Results is the value of the results output

Description: The full test results

func (*GossValidateOutput) Runtime

func (d *GossValidateOutput) Runtime() int64

Runtime is the value of the runtime output

Description: The time it took to run the tests, in seconds

func (*GossValidateOutput) Success

func (d *GossValidateOutput) Success() string

Success is the value of the success output

Description: Indicates if the test passed

func (*GossValidateOutput) Summary

func (d *GossValidateOutput) Summary() string

Summary is the value of the summary output

Description: A human friendly test result

func (*GossValidateOutput) Tests

func (d *GossValidateOutput) Tests() int64

Tests is the value of the tests output

Description: The number of tests that were run

type GossValidateRequester

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

GossValidateRequester performs a RPC request to scout#goss_validate

func (*GossValidateRequester) Do

Do performs the request

func (*GossValidateRequester) Vars

Vars is an optional input to the goss_validate action

Description: Path to a file to use as template variables

type GossValidateResult

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

GossValidateResult is the result from a goss_validate action

func (*GossValidateResult) AllOutputs added in v0.26.0

func (d *GossValidateResult) AllOutputs() []*GossValidateOutput

AllOutputs provide access to all outputs

func (*GossValidateResult) EachOutput

func (d *GossValidateResult) EachOutput(h func(r *GossValidateOutput))

EachOutput iterates over all results received

func (*GossValidateResult) RenderResults

func (d *GossValidateResult) RenderResults(w io.Writer, format RenderFormat, displayMode DisplayMode, verbose bool, silent bool, colorize bool, log Log) error

func (*GossValidateResult) Stats

func (d *GossValidateResult) Stats() Stats

Stats is the rpc request stats

type InitializationOption

type InitializationOption func(opts *initOptions)

InitializationOption is an optional setting used to initialize the client

func Discovery

func Discovery(ns NodeSource) InitializationOption

Discovery sets the NodeSource to use when finding nodes to manage

func DiscoveryMethod

func DiscoveryMethod(m string) InitializationOption

DiscoveryMethod accepts a discovery method name as supplied from the CLI and configures the correct NodeSource reverts to broadcast method if an unsupported method is supplied, custom node sources can be set using Discovery()

func DiscoveryTimeout

func DiscoveryTimeout(t time.Duration) InitializationOption

DiscoveryTimeout sets a timeout for discovery for those methods that support it

func Logger

Logger sets the logger to use else one is made via the Choria framework

func Progress

func Progress() InitializationOption

Progress enables displaying a progress bar

type Log

type Log interface {
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
	Panicf(format string, args ...interface{})
}

type MaintenanceOutput

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

MaintenanceOutput is the output from the maintenance action

func (*MaintenanceOutput) Failed

func (d *MaintenanceOutput) Failed() []interface{}

Failed is the value of the failed output

Description: List of checks that could not be paused

func (*MaintenanceOutput) HashMap

func (d *MaintenanceOutput) HashMap() map[string]interface{}

HashMap is the raw output data

func (*MaintenanceOutput) JSON

func (d *MaintenanceOutput) JSON() ([]byte, error)

JSON is the JSON representation of the output data

func (*MaintenanceOutput) ParseMaintenanceOutput

func (d *MaintenanceOutput) ParseMaintenanceOutput(target interface{}) error

ParseMaintenanceOutput parses the result value from the Maintenance action into target

func (*MaintenanceOutput) ResultDetails

func (d *MaintenanceOutput) ResultDetails() *ResultDetails

ResultDetails is the details about the request

func (*MaintenanceOutput) Skipped

func (d *MaintenanceOutput) Skipped() []interface{}

Skipped is the value of the skipped output

Description: List of checks that was skipped

func (*MaintenanceOutput) Transitioned

func (d *MaintenanceOutput) Transitioned() []interface{}

Transitioned is the value of the transitioned output

Description: List of checks that were paused

type MaintenanceRequester

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

MaintenanceRequester performs a RPC request to scout#maintenance

func (*MaintenanceRequester) Checks

func (d *MaintenanceRequester) Checks(v []interface{}) *MaintenanceRequester

Checks is an optional input to the maintenance action

Description: Check to pause, empty means all

func (*MaintenanceRequester) Do

Do performs the request

type MaintenanceResult

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

MaintenanceResult is the result from a maintenance action

func (*MaintenanceResult) AllOutputs added in v0.26.0

func (d *MaintenanceResult) AllOutputs() []*MaintenanceOutput

AllOutputs provide access to all outputs

func (*MaintenanceResult) EachOutput

func (d *MaintenanceResult) EachOutput(h func(r *MaintenanceOutput))

EachOutput iterates over all results received

func (*MaintenanceResult) RenderResults

func (d *MaintenanceResult) RenderResults(w io.Writer, format RenderFormat, displayMode DisplayMode, verbose bool, silent bool, colorize bool, log Log) error

func (*MaintenanceResult) Stats

func (d *MaintenanceResult) Stats() Stats

Stats is the rpc request stats

type MetaNS added in v0.20.0

type MetaNS struct {
	// Options is the CLI options to discover based on
	Options *discovery.StandardOptions

	// Agent should be the agent the request is targeted at
	Agent string

	// DisablePipedDiscovery prevents the STDIN being used as a discovery source
	DisablePipedDiscovery bool

	sync.Mutex
	// contains filtered or unexported fields
}

MetaNS is a NodeSource that assists CLI tools in creating Choria standard command line based discovery.

func NewMetaNS added in v0.20.0

func NewMetaNS(opts *discovery.StandardOptions, enablePipeMode bool) *MetaNS

NewMetaNS creates a new meta discovery node source

func (*MetaNS) Discover added in v0.20.0

func (p *MetaNS) Discover(ctx context.Context, fw inter.Framework, _ []FilterFunc) ([]string, error)

Discover performs the discovery of nodes against the Choria Network.

func (*MetaNS) Reset added in v0.20.0

func (p *MetaNS) Reset()

Reset resets the internal node cache

type Metadata

type Metadata struct {
	License     string `json:"license"`
	Author      string `json:"author"`
	Timeout     int    `json:"timeout"`
	Name        string `json:"name"`
	Version     string `json:"version"`
	URL         string `json:"url"`
	Description string `json:"description"`
}

Metadata is the agent metadata

type NodeSource

type NodeSource interface {
	Reset()
	Discover(ctx context.Context, fw inter.Framework, filters []FilterFunc) ([]string, error)
}

NodeSource discovers nodes

type PuppetDBNS

type PuppetDBNS struct {
	sync.Mutex
	// contains filtered or unexported fields
}

PuppetDBNS is a NodeSource that uses the PuppetDB PQL Queries to discover nodes

func (*PuppetDBNS) Discover

func (p *PuppetDBNS) Discover(ctx context.Context, fw inter.Framework, filters []FilterFunc) ([]string, error)

Discover performs the discovery of nodes against the Choria Network

func (*PuppetDBNS) Reset

func (p *PuppetDBNS) Reset()

Reset resets the internal node cache

type RenderFormat

type RenderFormat int

RenderFormat is the format used by the RenderResults helper

const (
	// JSONFormat renders the results as a JSON document
	JSONFormat RenderFormat = iota

	// TextFormat renders the results as a Choria typical result set in line with choria req output
	TextFormat

	// TableFormat renders all successful responses in a table
	TableFormat

	// TXTFooter renders only the request summary statistics
	TXTFooter
)

type ResultDetails

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

ResultDetails is the details about a result

func (*ResultDetails) OK

func (d *ResultDetails) OK() bool

OK determines if the request was successful

func (*ResultDetails) Sender

func (d *ResultDetails) Sender() string

Sender is the identity of the remote that produced the message

func (*ResultDetails) StatusCode

func (d *ResultDetails) StatusCode() StatusCode

StatusCode is the status code produced by the remote

func (*ResultDetails) StatusMessage

func (d *ResultDetails) StatusMessage() string

StatusMessage is the status message produced by the remote

type ResumeOutput

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

ResumeOutput is the output from the resume action

func (*ResumeOutput) Failed

func (d *ResumeOutput) Failed() []interface{}

Failed is the value of the failed output

Description: List of checks that could not be resumed

func (*ResumeOutput) HashMap

func (d *ResumeOutput) HashMap() map[string]interface{}

HashMap is the raw output data

func (*ResumeOutput) JSON

func (d *ResumeOutput) JSON() ([]byte, error)

JSON is the JSON representation of the output data

func (*ResumeOutput) ParseResumeOutput

func (d *ResumeOutput) ParseResumeOutput(target interface{}) error

ParseResumeOutput parses the result value from the Resume action into target

func (*ResumeOutput) ResultDetails

func (d *ResumeOutput) ResultDetails() *ResultDetails

ResultDetails is the details about the request

func (*ResumeOutput) Skipped

func (d *ResumeOutput) Skipped() []interface{}

Skipped is the value of the skipped output

Description: List of checks that was skipped

func (*ResumeOutput) Transitioned

func (d *ResumeOutput) Transitioned() []interface{}

Transitioned is the value of the transitioned output

Description: List of checks that were resumed

type ResumeRequester

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

ResumeRequester performs a RPC request to scout#resume

func (*ResumeRequester) Checks

func (d *ResumeRequester) Checks(v []interface{}) *ResumeRequester

Checks is an optional input to the resume action

Description: Check to resume, empty means all

func (*ResumeRequester) Do

Do performs the request

type ResumeResult

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

ResumeResult is the result from a resume action

func (*ResumeResult) AllOutputs added in v0.26.0

func (d *ResumeResult) AllOutputs() []*ResumeOutput

AllOutputs provide access to all outputs

func (*ResumeResult) EachOutput

func (d *ResumeResult) EachOutput(h func(r *ResumeOutput))

EachOutput iterates over all results received

func (*ResumeResult) RenderResults

func (d *ResumeResult) RenderResults(w io.Writer, format RenderFormat, displayMode DisplayMode, verbose bool, silent bool, colorize bool, log Log) error

func (*ResumeResult) Stats

func (d *ResumeResult) Stats() Stats

Stats is the rpc request stats

type ScoutClient

type ScoutClient struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ScoutClient to the scout agent

func Must

func Must(fw inter.Framework, opts ...InitializationOption) (client *ScoutClient)

Must create a new client and panics on error

func New

func New(fw inter.Framework, opts ...InitializationOption) (client *ScoutClient, err error)

New creates a new client to the scout agent

func (*ScoutClient) AgentMetadata

func (p *ScoutClient) AgentMetadata() *Metadata

AgentMetadata is the agent metadata this client supports

func (*ScoutClient) Checks

func (p *ScoutClient) Checks() *ChecksRequester

Checks performs the checks action

Description: Obtain a list of checks and their current status

func (*ScoutClient) DiscoverNodes

func (p *ScoutClient) DiscoverNodes(ctx context.Context) (nodes []string, err error)

DiscoverNodes performs a discovery using the configured filter and node source

func (*ScoutClient) GossValidate

func (p *ScoutClient) GossValidate(inputFile string) *GossValidateRequester

GossValidate performs the goss_validate action

Description: Performs a Goss validation using a specific file

Required Inputs:

  • file (string) - Path to the Goss validation specification

Optional Inputs:

  • vars (string) - Path to a file to use as template variables

func (*ScoutClient) Maintenance

func (p *ScoutClient) Maintenance() *MaintenanceRequester

Maintenance performs the maintenance action

Description: Pause checking of one or more checks

Optional Inputs:

  • checks ([]interface{}) - Check to pause, empty means all

func (*ScoutClient) OptionAgentFilter

func (p *ScoutClient) OptionAgentFilter(a ...string) *ScoutClient

OptionAgentFilter adds an agent filter

func (*ScoutClient) OptionClassFilter

func (p *ScoutClient) OptionClassFilter(f ...string) *ScoutClient

OptionClassFilter adds a class filter

func (*ScoutClient) OptionCollective

func (p *ScoutClient) OptionCollective(c string) *ScoutClient

OptionCollective sets the collective to target

func (*ScoutClient) OptionCombinedFilter

func (p *ScoutClient) OptionCombinedFilter(f ...string) *ScoutClient

OptionCombinedFilter adds a combined filter

func (*ScoutClient) OptionCompoundFilter

func (p *ScoutClient) OptionCompoundFilter(f ...string) *ScoutClient

OptionCompoundFilter adds a compound filter

func (*ScoutClient) OptionDiscoveryTimeout

func (p *ScoutClient) OptionDiscoveryTimeout(t time.Duration) *ScoutClient

OptionDiscoveryTimeout configures the request discovery timeout, defaults to configured discovery timeout

func (*ScoutClient) OptionExprFilter

func (p *ScoutClient) OptionExprFilter(f string) *ScoutClient

OptionExprFilter sets a filter expression that will remove results from the result set

func (*ScoutClient) OptionFactFilter

func (p *ScoutClient) OptionFactFilter(f ...string) *ScoutClient

OptionFactFilter adds a fact filter

func (*ScoutClient) OptionIdentityFilter

func (p *ScoutClient) OptionIdentityFilter(f ...string) *ScoutClient

OptionIdentityFilter adds an identity filter

func (*ScoutClient) OptionInBatches

func (p *ScoutClient) OptionInBatches(size int, sleep int) *ScoutClient

OptionInBatches performs requests in batches

func (*ScoutClient) OptionLimitMethod

func (p *ScoutClient) OptionLimitMethod(m string) *ScoutClient

OptionLimitMethod configures the method to use when limiting targets - "random" or "first"

func (*ScoutClient) OptionLimitSeed

func (p *ScoutClient) OptionLimitSeed(s int64) *ScoutClient

OptionLimitSeed sets the random seed used to select targets when limiting and limit method is "random"

func (*ScoutClient) OptionLimitSize

func (p *ScoutClient) OptionLimitSize(s string) *ScoutClient

OptionLimitSize sets limits on the targets, either a number of a percentage like "10%"

func (*ScoutClient) OptionReplyTo added in v0.23.0

func (p *ScoutClient) OptionReplyTo(t string) *ScoutClient

OptionReplyTo sets a custom reply target

func (*ScoutClient) OptionReset

func (p *ScoutClient) OptionReset() *ScoutClient

OptionReset resets the client options to use across requests to an empty list

func (*ScoutClient) OptionTargets

func (p *ScoutClient) OptionTargets(t []string) *ScoutClient

OptionTargets sets specific node targets which would avoid discovery for all action calls until reset

func (*ScoutClient) OptionWorkers

func (p *ScoutClient) OptionWorkers(w int) *ScoutClient

OptionWorkers sets how many worker connections should be started to the broker

func (*ScoutClient) Resume

func (p *ScoutClient) Resume() *ResumeRequester

Resume performs the resume action

Description: Resume active checking of one or more checks

Optional Inputs:

  • checks ([]interface{}) - Check to resume, empty means all

func (*ScoutClient) Trigger

func (p *ScoutClient) Trigger() *TriggerRequester

Trigger performs the trigger action

Description: Force an immediate check of one or more checks

Optional Inputs:

  • checks ([]interface{}) - Check to trigger, empty means all

type Stats

type Stats interface {
	Agent() string
	Action() string
	All() bool
	NoResponseFrom() []string
	UnexpectedResponseFrom() []string
	DiscoveredCount() int
	DiscoveredNodes() *[]string
	FailCount() int
	OKCount() int
	ResponsesCount() int
	PublishDuration() (time.Duration, error)
	RequestDuration() (time.Duration, error)
	DiscoveryDuration() (time.Duration, error)
	OverrideDiscoveryTime(start time.Time, end time.Time)
	UniqueRequestID() string
}

Stats are the statistics for a request

type StatusCode

type StatusCode uint8

StatusCode is a reply status as defined by MCollective SimpleRPC - integers 0 to 5

See the constants OK, RPCAborted, UnknownRPCAction, MissingRPCData, InvalidRPCData and UnknownRPCError

type TriggerOutput

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

TriggerOutput is the output from the trigger action

func (*TriggerOutput) Failed

func (d *TriggerOutput) Failed() []interface{}

Failed is the value of the failed output

Description: List of checks that could not be triggered

func (*TriggerOutput) HashMap

func (d *TriggerOutput) HashMap() map[string]interface{}

HashMap is the raw output data

func (*TriggerOutput) JSON

func (d *TriggerOutput) JSON() ([]byte, error)

JSON is the JSON representation of the output data

func (*TriggerOutput) ParseTriggerOutput

func (d *TriggerOutput) ParseTriggerOutput(target interface{}) error

ParseTriggerOutput parses the result value from the Trigger action into target

func (*TriggerOutput) ResultDetails

func (d *TriggerOutput) ResultDetails() *ResultDetails

ResultDetails is the details about the request

func (*TriggerOutput) Skipped

func (d *TriggerOutput) Skipped() []interface{}

Skipped is the value of the skipped output

Description: List of checks that was skipped

func (*TriggerOutput) Transitioned

func (d *TriggerOutput) Transitioned() []interface{}

Transitioned is the value of the transitioned output

Description: List of checks that were triggered

type TriggerRequester

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

TriggerRequester performs a RPC request to scout#trigger

func (*TriggerRequester) Checks

func (d *TriggerRequester) Checks(v []interface{}) *TriggerRequester

Checks is an optional input to the trigger action

Description: Check to trigger, empty means all

func (*TriggerRequester) Do

Do performs the request

type TriggerResult

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

TriggerResult is the result from a trigger action

func (*TriggerResult) AllOutputs added in v0.26.0

func (d *TriggerResult) AllOutputs() []*TriggerOutput

AllOutputs provide access to all outputs

func (*TriggerResult) EachOutput

func (d *TriggerResult) EachOutput(h func(r *TriggerOutput))

EachOutput iterates over all results received

func (*TriggerResult) RenderResults

func (d *TriggerResult) RenderResults(w io.Writer, format RenderFormat, displayMode DisplayMode, verbose bool, silent bool, colorize bool, log Log) error

func (*TriggerResult) Stats

func (d *TriggerResult) Stats() Stats

Stats is the rpc request stats

Jump to

Keyboard shortcuts

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