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 AppInfo
- type Config
- func (c Config) DatastoreCAName() string
- func (c Config) DatastoreCASep() string
- func (c Config) DatastorePerfPercentileSet() MultiValueDSPerfPercentileSetFlag
- func (c Config) DatastorePerfThresholds() DSPerformanceSummaryThresholds
- func (c Config) HostCAName() string
- func (c Config) HostCASep() string
- func (c Config) Timeout() time.Duration
- func (c Config) UserAgent() string
- 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 DSPerformanceSummaryThresholds
- type MultiValueDSPerfPercentileSetFlag
- func (mvdsperf MultiValueDSPerfPercentileSetFlag) CriticalThresholdValues() string
- func (mvdsperf *MultiValueDSPerfPercentileSetFlag) Set(value string) error
- func (mvdsperf *MultiValueDSPerfPercentileSetFlag) String() string
- func (mvdsperf MultiValueDSPerfPercentileSetFlag) WarningThresholdValues() string
- type PluginType
Constants ¶
const ( PluginTypeTools string = "vmware-tools" PluginTypeSnapshotsAge string = "snapshots-age" PluginTypeSnapshotsCount string = "snapshots-count" PluginTypeSnapshotsSize string = "snapshots-size" PluginTypeDatastoresSpace string = "datastores-space" PluginTypeDatastoresPerformance string = "datastore-performance" 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" PluginTypeDiskConsolidation string = "disk-consolidation" PluginTypeInteractiveQuestion string = "interactive-question" PluginTypeAlarms string = "alarms" )
Plugin types provided by this project. These values are used as labels in logging and report output. See also the PluginType struct type used to indicate what plugin is executing.
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 ( // native vSphere keywords AlarmStatusRed string = "red" AlarmStatusYellow string = "yellow" AlarmStatusGreen string = "green" AlarmStatusGray string = "gray" // Nagios keywords, though these values are displayed within the web UI AlarmStatusCritical string = "critical" AlarmStatusWarning string = "warning" AlarmStatusOk string = "ok" AlarmStatusUnknown string = "unknown" )
Valid Triggered Alarm status keywords. Provided by sysadmin, maps to ManagedEntityStatus values.
const ( StateOKLabel string = "OK" StateWARNINGLabel string = "WARNING" StateCRITICALLabel string = "CRITICAL" StateUNKNOWNLabel string = "UNKNOWN" StateDEPENDENTLabel string = "DEPENDENT" )
Nagios plugin/service check state "labels". Duplicates constants provided by the atc0005/go-nagios package in order to not create a dependency between this package and that one.
TODO: Is this a valid concern? The individual plugins in this project already have this dependency.
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."
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() { flag.CommandLine.SetOutput(os.Stdout) 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 AppInfo ¶ added in v0.17.3
type AppInfo struct { // Name specifies the public name shared by all plugins in this project. Name string // Version specifies the public version shared by all plugins in this // project. Version string // URL specifies the public repo URL shared by all plugins in this // project. URL string // Plugin indicates which plugin provided by this project is currently // executing. Plugin string }
AppInfo identifies common details about the plugins provided by this project.
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. This field is used by plugins which support monitoring only // a single Datacenter. Not applicable to standalone ESXi hosts. DatacenterName string // DatacenterNames is the name of one or more Datacenters in the // associated vSphere inventory. This field is used by plugins which // support monitoring multiple Datacenters. Not applicable to standalone // ESXi hosts. DatacenterNames multiValueStringFlag // HostSystemName is the name of an ESXi host/server in the associated // vSphere inventory. HostSystemName string // 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 // IncludedAlarmEntityTypes is a list of entity types for Alarms that will // be explicitly included for evaluation. Unless included by later // filtering logic, unmatched Triggered Alarms will be excluded from final // evaluation. Explicitly included Triggered Alarms are still subject to // permanent exclusion if an explicit exclusion match is made. IncludedAlarmEntityTypes multiValueStringFlag // ExcludedAlarmEntityTypes is a list of entity types for Alarms that will // be explicitly excluded from further evaluation by other stages in the // filtering pipeline. Explicit exclusions have precedence over explicit // inclusions. ExcludedAlarmEntityTypes multiValueStringFlag // IncludedAlarmEntityNames is a list of entity names for Alarms that will // be explicitly included for evaluation. Unless included by later // filtering logic, unmatched Triggered Alarms will be excluded from final // evaluation. Explicitly included Triggered Alarms are still subject to // permanent exclusion if an explicit exclusion match is made. IncludedAlarmEntityNames multiValueStringFlag // ExcludedAlarmEntityTypes is a list of entity names for Alarms that will // be explicitly excluded from further evaluation by other stages in the // filtering pipeline. Explicit exclusions have precedence over explicit // inclusions. ExcludedAlarmEntityNames multiValueStringFlag // IncludedAlarmEntityResourcePools is a list of resource pools that are // compared against the name of a resource pool for an entity associated // with one or more Triggered Alarms. Any Triggered Alarm with an // associated entity that is part of one of these resource pools is // explicitly included for evaluation. // // Unless included by later filtering logic, unmatched Triggered Alarms // will be excluded from final evaluation. Explicitly included Triggered // Alarms are still subject to permanent exclusion if an explicit // exclusion match is made. IncludedAlarmEntityResourcePools multiValueStringFlag // ExcludedAlarmEntityTypes is a list of resource pools that are compared // against the name of a resource pool for an entity associated with one // or more Triggered Alarms. Any Triggered Alarm with an associated that // is NOT part of one of these resource pools will be explicitly excluded // from further evaluation by other stages in the filtering pipeline. // Explicit exclusions have precedence over explicit inclusions. ExcludedAlarmEntityResourcePools multiValueStringFlag // IncludedAlarmNames is a list of names for defined Alarms that will be // explicitly included for evaluation. Unless included by later filtering // logic, unmatched Triggered Alarms will be excluded from final // evaluation. Explicitly included Triggered Alarms are still subject to // permanent exclusion if an explicit exclusion match is made. IncludedAlarmNames multiValueStringFlag // ExcludedAlarmNames is a list of names for defined Alarms that will be // explicitly excluded from further evaluation by other stages in the // filtering pipeline. Explicit exclusions have precedence over explicit // inclusions. ExcludedAlarmNames multiValueStringFlag // IncludedAlarmDescriptions is a list of descriptions for defined Alarms // that will be explicitly included for evaluation. Unless included by // later filtering logic, unmatched Triggered Alarms will be excluded from // final evaluation. Explicitly included Triggered Alarms are still // subject to permanent exclusion if an explicit exclusion match is made. IncludedAlarmDescriptions multiValueStringFlag // ExcludedAlarmDescriptions is a list of descriptions for defined Alarms // that will be explicitly excluded from further evaluation by other // stages in the filtering pipeline. Explicit exclusions have precedence // over explicit inclusions. ExcludedAlarmDescriptions multiValueStringFlag // IncludedAlarmNames is a list of statuses for Triggered Alarms that will // be explicitly included for evaluation. Unless included by later // filtering logic, unmatched Triggered Alarms will be excluded from final // evaluation. Explicitly included Triggered Alarms are still subject to // permanent exclusion if an explicit exclusion match is made. IncludedAlarmStatuses multiValueStringFlag // ExcludedAlarmStatuses is a list of statuses for Triggered Alarms that // will be explicitly excluded from further evaluation by other stages in // the filtering pipeline. Explicit exclusions have precedence over // explicit inclusions. ExcludedAlarmStatuses multiValueStringFlag // App represents common details about the plugins provided by this // project. App AppInfo // Log is an embedded zerolog Logger initialized via config.New(). Log zerolog.Logger // 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 // DatastoreSpaceUsageWarning specifies the percentage of a datastore's // storage usage (as a whole number) when a WARNING threshold is reached. DatastoreSpaceUsageWarning int // DatastoreSpaceUsageCritical specifies the percentage of a datastore's // storage usage (as a whole number) when a CRITICAL threshold is reached. DatastoreSpaceUsageCritical 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 // IgnoreMissingDatastorePerfMetrics indicates whether the lack of // available metrics for a specific datastore should be ignored. This is // not intended to handle scenarios where metrics collection is disabled // entirely, but for new datastores where metrics have not yet been // collected for the active interval. IgnoreMissingDatastorePerfMetrics bool // HideHistoricalDatastorePerfMetricSets indicates whether metrics for a // specific datastore should be excluded from the performance summary // report emitted at plugin completion. HideHistoricalDatastorePerfMetricSets bool // PoweredOff indicates whether powered off VMs are evaluated in addition // to powered on VMs. PoweredOff bool // EvaluateAcknowledgedAlarms indicates whether acknowledged triggered // alarms are evaluated in addition to unacknowledged ones. EvaluateAcknowledgedAlarms bool // TriggerReloadStateData indicates whether the state data for evaluated // objects (e.g., VirtualMachines) will be reloaded/refreshed prior to // evaluation of specific properties. TriggerReloadStateData 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 // 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) DatastorePerfPercentileSet ¶ added in v0.27.0
func (c Config) DatastorePerfPercentileSet() MultiValueDSPerfPercentileSetFlag
DatastorePerfPercentileSet returns a mapping of Datastore Performance Summary percentile to latency thresholds. This mapping is used to evaluate Datastore Performance metrics to determine overall plugin state.
func (Config) DatastorePerfThresholds ¶ added in v0.27.0
func (c Config) DatastorePerfThresholds() DSPerformanceSummaryThresholds
DatastorePerfThresholds returns Datastore Performance Summary latency thresholds for the default percentile. If defined by the user, those values are returned. If the user did not specify individual threshold values, default values are returned.
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 plugin runtime/execution timeout value in seconds to an appropriate time duration value for use with setting context deadline value.
func (Config) UserAgent ¶ added in v0.17.3
UserAgent returns a string usable as-is as a custom user agent for plugins provided by this project.
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 DSPerformanceSummaryThresholds ¶ added in v0.27.0
type DSPerformanceSummaryThresholds struct { // ReadLatencyWarning is the read latency in ms when a WARNING threshold // is reached. ReadLatencyWarning float64 // ReadLatencyCritical is the read latency in ms when a CRITICAL threshold // is reached. ReadLatencyCritical float64 // WriteLatencyWarning is the write latency in ms when a WARNING threshold // is reached. WriteLatencyWarning float64 // WriteLatencyCritical is the write latency in ms when a CRITICAL // threshold is reached. WriteLatencyCritical float64 // VMLatencyWarning is the latency in ms as observed by VMs using the // datastore when a WARNING threshold is reached. VMLatencyWarning float64 // VMLatencyCritical is the latency in ms as observed by VMs using the // datastore when a CRITICAL threshold is reached. VMLatencyCritical float64 }
DSPerformanceSummaryThresholds represents the thresholds used to evaluate Datastore Performance Summary values.
type MultiValueDSPerfPercentileSetFlag ¶ added in v0.27.0
type MultiValueDSPerfPercentileSetFlag map[int]DSPerformanceSummaryThresholds
MultiValueDSPerfPercentileSetFlag is a custom type that satisfies the flag.Value interface. This type is used to accept Datastore Performance Summary percentile "sets". These sets define thresholds used to check Datastore Performance latency metrics to determine overall plugin state.
func (MultiValueDSPerfPercentileSetFlag) CriticalThresholdValues ¶ added in v0.27.0
func (mvdsperf MultiValueDSPerfPercentileSetFlag) CriticalThresholdValues() string
CriticalThresholdValues returns a comma separated string consisting of all specified metric percentiles and the the associated CRITICAL threshold values.
func (*MultiValueDSPerfPercentileSetFlag) Set ¶ added in v0.27.0
func (mvdsperf *MultiValueDSPerfPercentileSetFlag) Set(value string) error
Set is called once by the flag package, in command line order, for each flag present.
func (*MultiValueDSPerfPercentileSetFlag) String ¶ added in v0.27.0
func (mvdsperf *MultiValueDSPerfPercentileSetFlag) String() string
String returns a comma separated string consisting of all map entries.
func (MultiValueDSPerfPercentileSetFlag) WarningThresholdValues ¶ added in v0.27.0
func (mvdsperf MultiValueDSPerfPercentileSetFlag) WarningThresholdValues() string
WarningThresholdValues returns a comma separated string consisting of all specified metric percentiles and the the associated WARNING threshold values.
type PluginType ¶
type PluginType struct { Tools bool SnapshotsAge bool SnapshotsCount bool SnapshotsSize bool DatastoresSpace bool DatastoresPerformance bool ResourcePoolsMemory bool VirtualCPUsAllocation bool VirtualHardwareVersion bool Host2Datastores2VMs bool HostSystemMemory bool HostSystemCPU bool VirtualMachinePowerCycleUptime bool DiskConsolidation bool InteractiveQuestion bool Alarms 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. See also the PluginType* constants.