config

package
v0.1.3-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package config provides types and functions to collect, validate and apply user-provided settings.

Index

Constants

View Source
const (
	HelpFlagLong                   string = "help"
	HelpFlagShort                  string = "h"
	VersionFlagLong                string = "version"
	VerboseFlagLong                string = "verbose"
	BrandingFlag                   string = "branding"
	TrustCertFlagLong              string = "trust-cert"
	TimeoutFlagLong                string = "timeout"
	TimeoutFlagShort               string = "t"
	ReadLimitFlagLong              string = "read-limit"
	LogLevelFlagLong               string = "log-level"
	LogLevelFlagShort              string = "ll"
	ServerFlagLong                 string = "server"
	UsernameFlagLong               string = "username"
	PasswordFlagLong               string = "password"
	PortFlagLong                   string = "port"
	NetTypeFlagLong                string = "net-type"
	CACertificateFlagLong          string = "ca-cert"
	PermitTLSRenegotiationFlagLong string = "permit-tls-renegotiation"
	OmitOKSyncPlansFlagLong        string = "omit-ok"
	InspectorOutputFormatFlagLong  string = "output-format"
)

Flag names for consistent references. Exported so that they're available from tests.

View Source
const (
	InspectorOutputFormatOverview    string = "overview"
	InspectorOutputFormatPrettyTable string = "pretty-table"
	InspectorOutputFormatSimpleTable string = "simple-table"
	InspectorOutputFormatVerbose     string = "verbose"
)

Supported Inspector type application output formats

View Source
const (
	// LogLevelDisabled maps to zerolog.Disabled logging level
	LogLevelDisabled string = "disabled"

	// LogLevelPanic maps to zerolog.PanicLevel logging level
	LogLevelPanic string = "panic"

	// LogLevelFatal maps to zerolog.FatalLevel logging level
	LogLevelFatal string = "fatal"

	// LogLevelError maps to zerolog.ErrorLevel logging level
	LogLevelError string = "error"

	// LogLevelWarn maps to zerolog.WarnLevel logging level
	LogLevelWarn string = "warn"

	// LogLevelInfo maps to zerolog.InfoLevel logging level
	LogLevelInfo string = "info"

	// LogLevelDebug maps to zerolog.DebugLevel logging level
	LogLevelDebug string = "debug"

	// LogLevelTrace maps to zerolog.TraceLevel logging level
	LogLevelTrace string = "trace"
)
View Source
const ExitCodeCatchall int = 1

ExitCodeCatchall indicates a general or miscellaneous error has occurred. This exit code is not directly used by monitoring plugins in this project. See https://tldp.org/LDP/abs/html/exitcodes.html for additional details.

View Source
const MB int64 = 1048576

MB represents 1 Megabyte

Variables

View Source
var (
	// ErrVersionRequested indicates that the user requested application version
	// information.
	ErrVersionRequested = errors.New("version information requested")

	// ErrHelpRequested indicates that the user requested application
	// help/usage information.
	ErrHelpRequested = errors.New("help/usage information requested")

	// ErrUnsupportedOption indicates that an unsupported option was specified.
	ErrUnsupportedOption = errors.New("unsupported option")

	// ErrConfigNotInitialized indicates that the configuration is not in a
	// usable state and application execution can not successfully proceed.
	ErrConfigNotInitialized = errors.New("configuration not initialized")
)

Functions

func Branding

func Branding(msg string) func() string

Branding accepts a message and returns a function that concatenates that message with version information. This function is intended to be called as a final step before application exit after any other output has already been emitted.

func Usage

func Usage(flagSet *flag.FlagSet, w io.Writer) func()

Usage is a custom override for the default Help text provided by the flag package. Here we prepend some additional metadata to the existing output.

func Version

func Version() string

Version emits application name, version and repo location.

Types

type AppType

type AppType struct {

	// Plugin represents an application used as a Nagios plugin.
	Plugin bool

	// Inspector represents an application used for one-off or isolated
	// checks. Unlike a Nagios plugin which is focused on specific attributes
	// resulting in a severity-based outcome, an Inspector application is
	// intended for examining a small set of targets for
	// informational/troubleshooting purposes.
	Inspector bool
}

AppType represents the type of application that is being configured/initialized. Not all application types will use the same features and as a result will not accept the same flags. Unless noted otherwise, each of the application types are incompatible with each other, though some flags are common to all types.

type Config

type Config struct {

	// LoggingLevel is the supported logging level for this application.
	LoggingLevel string

	// InspectorOutputFormat is the output format used for Inspector type
	// applications.
	InspectorOutputFormat string

	// NetworkType indicates whether an attempt should be made to connect to
	// only IPv4, only IPv6 or SSH servers listening on either of IPv4 or IPv6
	// addresses ("auto").
	NetworkType string

	// Server is the SSH server FQDN or IP Address.
	Server string

	// Username is the valid user for the given SSH server.
	Username string

	// Password is the valid password for the specified user.
	Password string

	// CACertificate is the path to a CA certificate used to validate the
	// certificate chain used by the Red Hat Satellite server.
	CACertificate string

	// TCPPort is the port used by the SSH service.
	TCPPort int

	// ReadLimit is a limit in bytes set to help prevent abuse when reading
	// input that could be larger than expected. The default value is overly
	// generous and is unlikely to be met unless something is broken.
	ReadLimit int64

	// Log is an embedded zerolog Logger initialized via config.New().
	Log zerolog.Logger

	// TrustCert controls whether the certificate should be trusted as-is
	// without validation.
	TrustCert bool

	// PermitTLSRenegotiation controls whether the server is allowed to
	// request TLS renegotiation.
	PermitTLSRenegotiation bool

	// OmitOKSyncPlans indicates whether the user opted to omit sync plans
	// with a non-problematic or "OK" state from the output.
	OmitOKSyncPlans bool

	// EmitBranding controls whether "generated by" text is included at the
	// bottom of application output. This output is included in the Nagios
	// dashboard and notifications. This output may not mix well with branding
	// output from other tools such as atc0005/send2teams which also insert
	// their own branding output.
	EmitBranding bool

	// ShowVersion is a flag indicating whether the user opted to display only
	// the version string and then immediately exit the application.
	ShowVersion bool

	// ShowVerbose is a flag indicating whether the user opted to display
	// verbose details in the final plugin output.
	ShowVerbose bool

	// ShowHelp indicates whether the user opted to display usage information
	// and exit the application.
	ShowHelp bool
	// contains filtered or unexported fields
}

Config represents the application configuration as specified via command-line flags.

func New

func New(appType AppType) (*Config, error)

New is a factory function that produces a new Config object based on user provided flag and config file values. It is responsible for validating user-provided values and initializing the logging settings used by this application.

func (*Config) Help

func (c *Config) Help() string

Help emits application usage information to the previously configured destination for usage and error messages.

func (Config) Timeout

func (c Config) Timeout() time.Duration

Timeout converts the user-specified connection timeout value in seconds to an appropriate time duration value for use with setting a timeout value.

func (Config) UserAgent

func (c Config) UserAgent() string

UserAgent returns a string usable as-is as a custom user agent for plugins provided by this project.

Jump to

Keyboard shortcuts

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