config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const (
	PluginTypeTools                 string = "vmware-tools"
	PluginTypeSnapshotsAge          string = "snapshots-age"
	PluginTypeSnapshotsSize         string = "snapshots-size"
	PluginTypeDatastoresSize        string = "datastore-size"
	PluginTypeResourcePoolsMemory   string = "resource-pools-memory"
	PluginTypeVirtualCPUsAllocation string = "virtual-cpus-allocation"
)

Plugin types provided by this project.

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"
)

Variables

View Source
var ErrVersionRequested = errors.New("version information requested")

ErrVersionRequested indicates that the user requested application version information.

View Source
var Usage = func() {
	fmt.Fprintln(flag.CommandLine.Output(), "\n"+Version()+"\n")
	fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
	flag.PrintDefaults()
}

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.

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 Version

func Version() string

Version emits application name, version and repo location.

Types

type Config

type Config struct {

	// Server is the fully-qualified domain name of the system running a
	// certificate-enabled service.
	Server string

	// Username is the user account used to login to the ESXi host or vCenter
	// instance.
	Username string

	// Password is associated with the account used to login to the ESXi host
	// or vCenter instance.
	Password string

	// Domain is the domain for the user account used to login to the ESXi
	// host or vCenter instance.
	Domain string

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

	// Port is the TCP port used by the certifcate-enabled service.
	Port int

	// VCPUsAllocatedWarning specifies the percentage of vCPUs allocation (as
	// a whole number) when a WARNING threshold is reached.
	VCPUsAllocatedWarning int

	// VCPUsAllocatedCritical specifies the percentage of vCPUs allocation (as
	// a whole number) when a CRITICAL threshold is reached.
	VCPUsAllocatedCritical int

	// VCPUsMaxAllowed specifies the maximum amount of virtual CPUs (as a
	// whole number) that we are allowed to allocate in the target VMware
	// environment.
	VCPUsMaxAllowed int

	// PoweredOff indicates whether powered off VMs are evaluated in addition
	// to powered on VMs.
	PoweredOff bool

	// Whether the certificate should be trusted as-is without validation.
	TrustCert 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

	// IncludedResourcePools lists resource pools that are explicitly
	// monitored.
	IncludedResourcePools multiValueStringFlag

	// ExcludedResourcePools lists resource pools that are explicitly ignored
	// or excluded from being monitored.
	ExcludedResourcePools multiValueStringFlag

	// IgnoreVM lists VMs that are explicitly ignored or excluded from being
	// monitored.
	IgnoredVMs multiValueStringFlag

	// Log is an embedded zerolog Logger initialized via config.New().
	Log zerolog.Logger
	// contains filtered or unexported fields
}

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

func New

func New(pluginType PluginType) (*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) 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 initial connection attempt timeout value.

type PluginType

type PluginType struct {
	Tools                  bool
	SnapshotsAge           bool
	SnapshotsSize          bool
	DatastoresSize         bool
	ResourcePoolsMemory    bool
	VirtualCPUsAllocation  bool
	VirtualHardwareVersion bool
}

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

Jump to

Keyboard shortcuts

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