config

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 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 (

	// 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 ErrGroupNameHasSpaces = errors.New("group name contains spaces")

ErrGroupNameHasSpaces is returned by validation checks if a group name contains spaces.

View Source
var ErrGroupNameIsEmpty = errors.New("group name is empty string")

ErrGroupNameIsEmpty is returned by validation checks if a group name is an empty string.

View Source
var ErrUserNameHasSpaces = errors.New("username contains spaces")

ErrUserNameHasSpaces is returned by validation checks if a username contains spaces.

View Source
var ErrUsernameIsEmpty = errors.New("username is empty string")

ErrUsernameIsEmpty is returned by validation checks if a username is an empty string.

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 returned function implements nagios.ExitCallBackFunc in order to optionally supply branding details with the service check output.

func Version

func Version() string

Version emits application name, version and repo location.

Types

type Config

type Config struct {
	Logging
	Search

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

Config is a unified set of configuration values for this application. This struct is configured via command-line flags or (maybe in the future) TOML configuration file provided by the user. Values held by this object are intended to be retrieved via "getter" methods.

func New

func New() (*Config, error)

New is a factory function that produces a new Config object based on user provided flag and where applicable, default values.

func (Config) Age

func (c Config) Age() FileAgeThresholds

Age returns the user-provided CRITICAL and WARNING thresholds in days for the specified paths.

func (Config) Description

func (c Config) Description() string

Description emits branding information whenever the user specifies the `-h` flag. The application uses this as a header prior to displaying available CLI flag options.

func (Config) EmitBranding

func (c Config) EmitBranding() bool

EmitBranding returns the user-provided choice of whether branded output is emitted with check results or the default value if not provided.

func (Config) FailFast added in v0.1.1

func (c Config) FailFast() bool

FailFast returns the user-provided choice of whether paths are processed in a way that prioritizes a first-fail result over a strict order of CRITICAL results before WARNING results. The default value is returned if not provided.

func (Config) GroupName

func (c Config) GroupName() string

GroupName returns the user-provided group name set via the group-name-missing-critical or group-name-missing-warning flags or the default value if not provided.

func (Config) GroupNameCritical

func (c Config) GroupNameCritical() bool

GroupNameCritical indicates whether user opted to check for group name mismatches. Failing results indicate a CRITICAL state.

func (Config) GroupNameWarning

func (c Config) GroupNameWarning() bool

GroupNameWarning indicates whether user opted to check for group name mismatches. Failing results indicate a WARNING state.

func (Config) LogLevel

func (c Config) LogLevel() string

LogLevel returns the user-provided logging level or the default value if not provided.

func (Config) MissingOK

func (c Config) MissingOK() bool

MissingOK returns the user-provided choice of whether missing paths are considered OK or the default value if not provided.

func (Config) PathExistsCritical

func (c Config) PathExistsCritical() bool

PathExistsCritical indicates whether the existence of specified paths is considered a CRITICAL state.

func (Config) PathExistsWarning

func (c Config) PathExistsWarning() bool

PathExistsWarning indicates whether the existence of specified paths is considered a WARNING state.

func (Config) PathsExclude added in v0.1.2

func (c Config) PathsExclude() []string

PathsExclude returns the user-provided list of paths to ignore or an empty list if a user-specified list of paths was not provided. Each path in the list is processed by filepath.Clean. This allows for more reliable comparison against PathsInclude values to determine if a path should be ignored.

func (Config) PathsInclude added in v0.1.2

func (c Config) PathsInclude() []string

PathsInclude returns the user-provided list of paths to check or an empty list if a user-specified list of paths was not provided. Each path in the list is processed by filepath.Clean. This allows for more reliable comparison against PathsExclude values to determine if a path should be ignored.

func (Config) Recursive

func (c Config) Recursive() bool

Recursive returns the user-provided choice of whether paths are checked recursively or the default value if not provided.

func (Config) ResolveIDs added in v0.1.2

func (c Config) ResolveIDs() ResolveIDs

ResolveIDs returns a ResolveIDs type which indicates whether user opted to resolve user and group id values to name values and if so, at which exit state values.

func (Config) SizeMax added in v0.1.2

func (c Config) SizeMax() FileSizeThresholds

SizeMax returns the user-provided CRITICAL and WARNING thresholds for maximum size in bytes for the specified paths.

func (Config) SizeMin added in v0.1.2

func (c Config) SizeMin() FileSizeThresholds

SizeMin returns the user-provided CRITICAL and WARNING thresholds for minimum size in bytes for the specified paths.

func (Config) String

func (c Config) String() string

String implements the Stringer interface in order to display all initialized (user-provided or default) values.

func (Config) Username

func (c Config) Username() string

Username returns the user-provided username set via the username-missing-critical or username-missing-warning flags or the default value if not provided.

func (Config) UsernameCritical

func (c Config) UsernameCritical() bool

UsernameCritical indicates whether user opted to check for username mismatches. Failing results indicate a CRITICAL state.

func (Config) UsernameWarning

func (c Config) UsernameWarning() bool

UsernameWarning indicates whether user opted to check for group name mismatches. Failing results indicate a WARNING state.

func (Config) Version

func (c Config) Version() string

Version reuses the package-level Version function to emit version information and associated branding details whenever the user specifies the `--version` flag. The application exits after displaying this information.

type FileAgeThresholds

type FileAgeThresholds struct {
	Critical int
	Warning  int
	Set      bool
}

FileAgeThresholds represents the user-specified file age thresholds for specified paths.

type FileSizeThresholds

type FileSizeThresholds struct {
	Description string
	Critical    int64
	Warning     int64
	Set         bool
}

FileSizeThresholds represents the user-specified file size thresholds for specified paths.

type FileSizeThresholdsMinMax added in v0.1.2

type FileSizeThresholdsMinMax struct {
	SizeMin FileSizeThresholds
	SizeMax FileSizeThresholds
}

FileSizeThresholdsMinMax represents the combined minimum and maximum user-specified file size thresholds for specified paths.

type IDs added in v0.1.2

type IDs struct {
	Username  string
	GroupName string
}

IDs represents username and group name values.

type Logging

type Logging struct {
	Level        *string `` /* 154-byte string literal not displayed */
	EmitBranding *bool   `` /* 340-byte string literal not displayed */
}

Logging represents options specific to how this application handles logging.

type ResolveIDs added in v0.1.2

type ResolveIDs struct {
	UsernameCheck     bool
	UsernameCritical  bool
	UsernameWarning   bool
	GroupNameCheck    bool
	GroupNameCritical bool
	GroupNameWarning  bool
	IDs
}

ResolveIDs is a helper struct to record whether user opted to resolve user and group id values to name values and if so, at which exit state values.

type Search struct {
	PathsInclude             []string `arg:"--paths,env:CHECK_PATH_PATHS_INCLUDE" help:"List of comma or space-separated paths to check."`
	PathsExclude             []string `` /* 135-byte string literal not displayed */
	Recursive                *bool    `arg:"--recurse,env:CHECK_PATH_RECURSE" help:"Perform recursive search into subdirectories per provided path."`
	MissingOK                *bool    `` /* 153-byte string literal not displayed */
	FailFast                 *bool    `` /* 238-byte string literal not displayed */
	AgeCritical              *int     `` /* 184-byte string literal not displayed */
	AgeWarning               *int     `` /* 181-byte string literal not displayed */
	SizeMinCritical          *int64   `` /* 186-byte string literal not displayed */
	SizeMinWarning           *int64   `` /* 183-byte string literal not displayed */
	SizeMaxCritical          *int64   `` /* 183-byte string literal not displayed */
	SizeMaxWarning           *int64   `` /* 181-byte string literal not displayed */
	ExistsCritical           *bool    `` /* 143-byte string literal not displayed */
	ExistsWarning            *bool    `` /* 140-byte string literal not displayed */
	UsernameMissingCritical  *string  `` /* 205-byte string literal not displayed */
	UsernameMissingWarning   *string  `` /* 202-byte string literal not displayed */
	GroupNameMissingCritical *string  `` /* 205-byte string literal not displayed */
	GroupNameMissingWarning  *string  `` /* 202-byte string literal not displayed */
}

Search represents options specific to controlling how this application performs searches in the filesystem.

Jump to

Keyboard shortcuts

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