Documentation ¶
Overview ¶
Package config provides types and functions to collect, validate and apply user-provided settings.
Index ¶
- Constants
- Variables
- func Branding(msg string) func() string
- func Version() string
- type Config
- func (c Config) DatastoreCAName() string
- func (c Config) DatastoreCASep() string
- func (c Config) HostCAName() string
- func (c Config) HostCASep() string
- func (c Config) Timeout() time.Duration
- func (c Config) UsingCAPrefixes() bool
- func (c Config) UsingSharedCA() bool
- func (c Config) VirtualHardwareApplyDefaultIsMinVersionCheck() bool
- func (c Config) VirtualHardwareApplyHomogeneousVersionCheck() bool
- func (c Config) VirtualHardwareApplyMinVersionCheck() bool
- func (c Config) VirtualHardwareApplyOutdatedByVersionCheck() bool
- type PluginType
Constants ¶
const ( PluginTypeTools string = "vmware-tools" PluginTypeSnapshotsAge string = "snapshots-age" PluginTypeSnapshotsCount string = "snapshots-count" PluginTypeSnapshotsSize string = "snapshots-size" PluginTypeDatastoresSize string = "datastore-size" PluginTypeResourcePoolsMemory string = "resource-pools-memory" PluginTypeVirtualCPUsAllocation string = "virtual-cpus-allocation" PluginTypeVirtualHardwareVersion string = "virtual-hardware-version" PluginTypeHostDatastoreVMsPairings string = "host-to-ds-to-vms" PluginTypeHostSystemMemory string = "host-system-memory" PluginTypeHostSystemCPU string = "host-system-cpu" PluginTypeVirtualMachinePowerCycleUptime string = "vm-power-uptime" )
Plugin types provided by this project.
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" )
const (
MaxClusterNameChars int = 80
)
Known limits https://trainingrevolution.wordpress.com/2018/07/22/vmware-vsphere-6-7-character-limits-for-objects/
const ThresholdNotUsed string = "Not used by this monitoring mode."
ThresholdNotUsed indicates that a plugin is not using a specific threshold. This is visible in locations where Long Service Output text is displayed.
Variables ¶
var ErrVersionRequested = errors.New("version information requested")
ErrVersionRequested indicates that the user requested application version information.
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 ¶
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 // ClusterName is the name of the vSphere cluster where monitored objects // reside. ClusterName string // LoggingLevel is the supported logging level for this application. LoggingLevel string // DatastoreName is the name of the datastore as it is found within the // vSphere inventory of the specified ESXi host or vCenter instance. DatastoreName string // DatacenterName is the name of a Datacenter in the associated vSphere // inventory. Not applicable to standline ESXi hosts. DatacenterName string // HostSystemName is the name of an ESXi host/server in the associated // vSphere inventory. HostSystemName string // HostSystemMemoryUseWarning specifies the percentage of memory use (as a // whole number) for the specified ESXi host when a WARNING threshold is // reached. HostSystemMemoryUseWarning int // HostSystemMemoryUseCritical specifies the percentage of memory use (as // a whole number) for the specified ESXi host when a CRITICAL threshold // is reached. HostSystemMemoryUseCritical int // HostSystemCPUUseWarning specifies the percentage of CPU use (as a whole // number) for the specified ESXi host when a WARNING threshold is // reached. HostSystemCPUUseWarning int // HostSystemCPUUseCritical specifies the percentage of CPU use (as a // whole number) for the specified ESXi host when a CRITICAL threshold is // reached. HostSystemCPUUseCritical int // 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 // ResourcePoolsMemoryUseWarning specifies the percentage of memory use // (as a whole number) across all specified Resource Pools when a WARNING // threshold is reached. ResourcePoolsMemoryUseWarning int // ResourcePoolsMemoryUseCritical specifies the percentage of memory use // (as a whole number) across all specified Resource Pools when a CRITICAL // threshold is reached. ResourcePoolsMemoryUseCritical int // ResourcePoolsMemoryMaxAllowed specifies the maximum amount of memory // that we are allowed to consume in GB (as a whole number) in the target // VMware environment across all specified Resource Pools. VMs that are // running outside of resource pools are not considered in these // calculations. ResourcePoolsMemoryMaxAllowed int // DatastoreUsageWarning specifies the percentage of a datastore's storage // usage (as a whole number) when a WARNING threshold is reached. DatastoreUsageWarning int // DatastoreUsageCritical specifies the percentage of a datastore's storage // usage (as a whole number) when a CRITICAL threshold is reached. DatastoreUsageCritical int // SnapshotsSizeCritical specifies the cumulative size in GB of all // snapshots for a VM when a WARNING threshold is reached. SnapshotsSizeWarning int // SnapshotsSizeCritical specifies the cumulative size in GB of all // snapshots for a VM when a CRITICAL threshold is reached. SnapshotsSizeCritical int // SnapshotsAgeWarning specifies the age of a snapshot in days when a // WARNING threshold is reached. SnapshotsAgeWarning int // SnapshotsAgeCritical specifies the age of a snapshot in days when a // CRITICAL threshold is reached. SnapshotsAgeCritical int // SnapshotsCountWarning specifies the number of snapshots per VM when a // WARNING threshold is reached. SnapshotsCountWarning int // SnapshotsCountCritical specifies the number of snapshots per VM when a // CRITICAL threshold is reached. SnapshotsCountCritical int // VMPowerCycleUptimeWarning specifies the power cycle (off/on) uptime in // days per VM when a WARNING threshold is reached. VMPowerCycleUptimeWarning int // VMPowerCycleUptimeCritical specifies the power cycle (off/on) uptime in // days per VM when a CRITICAL threshold is reached. VMPowerCycleUptimeCritical int // VirtualHardwareMinimumVersion is the minimum virtual hardware version // accepted for each Virtual Machine. Any Virtual Machine not meeting this // minimum value is considered to be in a CRITICAL state. Per KB 1003746, // version 3 appears to be the oldest version supported. VirtualHardwareMinimumVersion int // VirtualHardwareOutdatedByWarning specifies the WARNING threshold for // outdated virtual hardware versions. If the current virtual hardware // version for a VM is found to be more than this many versions older than // the latest version a WARNING state is triggered. VirtualHardwareOutdatedByWarning int // VirtualHardwareOutdatedByCritical specifies the CRITICAL threshold for // outdated virtual hardware versions. If the current virtual hardware // version for a VM is found to be more than this many versions older than // the latest version a CRITICAL state is triggered. VirtualHardwareOutdatedByCritical int // VirtualHardwareDefaultVersionIsMinimum indicates whether the host or // cluster default hardware version is the minimum allowed. VirtualHardwareDefaultVersionIsMinimum bool // IgnoreMissingCustomAttribute indicates whether a host or datastore // missing the specified Custom Attribute should be ignored. IgnoreMissingCustomAttribute bool // 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. Specifying list values automatically excludes VirtualMachine // objects outside a Resource Pool. IncludedResourcePools multiValueStringFlag // ExcludedResourcePools lists resource pools that are explicitly ignored // or excluded from being monitored. ExcludedResourcePools multiValueStringFlag // IgnoredVM is a list of VMs that are explicitly ignored or excluded // from being monitored. IgnoredVMs multiValueStringFlag // IgnoredDatastores is a list of datastore names for Datastores that are // allowed to be associated with a VirtualMachine that are not associated // with its current host. IgnoredDatastores 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) DatastoreCAName ¶ added in v0.2.0
DatastoreCAName returns the user-provided Custom Attribute name specific to datastores or the shared Custom Attribute name used for both datastores and hosts.
func (Config) DatastoreCASep ¶ added in v0.2.0
DatastoreCASep returns the user-provided Custom Attribute prefix separator specific to datastores, the shared separator provided for both datastores and hosts or the default separator if not specified.
func (Config) HostCAName ¶ added in v0.2.0
HostCAName returns the user-provided Custom Attribute name specific to hosts or the shared Custom Attribute name used for both hosts and datastores.
func (Config) HostCASep ¶ added in v0.2.0
HostCASep returns the user-provided Custom Attribute prefix separator specific to datastores, the shared separator provided for both datastores and hosts or the default separator if not specified.
func (Config) Timeout ¶
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.
func (Config) UsingCAPrefixes ¶ added in v0.2.0
UsingCAPrefixes indicates whether the user opted to use a Custom Attribute prefix in place of a literal value for linking Hosts with specific Datastores.
func (Config) UsingSharedCA ¶ added in v0.2.0
UsingSharedCA indicates whether the user opted to use a shared Custom Attribute for linking Hosts with specific Datastores, or whether they opted to instead specify Custom Attributes for Hosts and Datastores separately. This method relies heavily on config validation to enforce only one flag set for specifying the required Custom Attribute.
func (Config) VirtualHardwareApplyDefaultIsMinVersionCheck ¶ added in v0.13.0
VirtualHardwareApplyDefaultIsMinVersionCheck indicates whether all virtual machines are required to have the host or cluster default hardware version or greater. This is only used if the other behaviors were not requested.
func (Config) VirtualHardwareApplyHomogeneousVersionCheck ¶ added in v0.11.0
VirtualHardwareApplyHomogeneousVersionCheck indicates whether the default behavior of asserting that all virtual hardware versions are the same is applied. This is only used if the other behaviors were not requested.
func (Config) VirtualHardwareApplyMinVersionCheck ¶ added in v0.11.0
VirtualHardwareApplyMinVersionCheck indicates whether all virtual machines are required to have the specified minimum hardware version or greater. This is only used if the other behaviors were not requested.
func (Config) VirtualHardwareApplyOutdatedByVersionCheck ¶ added in v0.11.0
VirtualHardwareApplyOutdatedByVersionCheck indicates whether the outdated by CRITICAL and WARNING threshold checks are applied to assert that virtual hardware versions are within the specified thresholds. This is only used if the other behaviors were not requested.
type PluginType ¶
type PluginType struct { Tools bool SnapshotsAge bool SnapshotsCount bool SnapshotsSize bool DatastoresSize bool ResourcePoolsMemory bool VirtualCPUsAllocation bool VirtualHardwareVersion bool Host2Datastores2VMs bool HostSystemMemory bool HostSystemCPU bool VirtualMachinePowerCycleUptime 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.