diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f5aa91..4d3d080 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ Versioning](http://semver.org/spec/v2.0.0.html). ## Unreleased +### Added +- Added flags --include-pseudo-fs and --fail-on-error + +### Changed +- Changed the behavior for failures to get fs usage based on flag +- Changed call to get partitions to use --include-pseudo-fs flag + ## [0.1.1] - 2020-12-29 ### Change diff --git a/README.md b/README.md index 6019103..1b9a69e 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,8 @@ Flags: -E, --exclude-fs-path strings Comma separated list of file system paths to exclude from checking -w, --warning float Warning threshold for file system usage (default 85) -c, --critical float Critical threshold for file system usage (default 95) + -p, --include-pseudo-fs Include pseudo-filesystems (e.g. tmpfs) (default false) + -f, --fail-on-error Fail and exit on errors getting file system usage (e.g. permission denied) (default false) -h, --help help for check-disk-usage Use "check-disk-usage [command] --help" for more information about a command. @@ -50,14 +52,22 @@ Use "check-disk-usage [command] --help" for more information about a command. ### Usage notes * The include and exclude options for both file system type and path are -mutually exclusive (e.g. you can not use --exclude-fs-type and ---include-fs-type on the same check). +mutually exclusive (e.g. you can not use `--exclude-fs-type` and +`--include-fs-type` on the same check). * The file system path on Linux/UNIX/macOS systems means the file system mount point (e.g. /, /tmp, /home) * The file system path on Windows refers to the drive letter (e.g. C:, D:). Volumes mounted via UNC paths are not checked. * File system types and paths on Windows are capitalized and need to be specified as such (e.g. NTFS, C:) +* The `--include-pseudo-fs` option is false by default meaning that on Linux +systems file system with types such as tmpfs (e.g. /dev, /run, etc.) will +be ignored. This takes precedence over any explicit includes or excludes. +* The `--fail-on-error` option determines what occurs if the check encounters an +error, such as `permission denied` for a file system. If true, the check will +exit with as a critical failure and provide the error message. If false (the +defaut), it will specify unknown for that file system, provide the error and +continue to check the remaining file systems as expected. ## Configuration diff --git a/main.go b/main.go index 46745a9..0896123 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,8 @@ type Config struct { ExcludeFSPath []string Warning float64 Critical float64 + IncludePseudo bool + FailOnError bool } var ( @@ -30,7 +32,7 @@ var ( } options = []*sensu.PluginConfigOption{ - &sensu.PluginConfigOption{ + { Path: "include-fs-type", Env: "", Argument: "include-fs-type", @@ -39,7 +41,7 @@ var ( Usage: "Comma separated list of file system types to check", Value: &plugin.IncludeFSType, }, - &sensu.PluginConfigOption{ + { Path: "exclude-fs-type", Env: "", Argument: "exclude-fs-type", @@ -48,7 +50,7 @@ var ( Usage: "Comma separated list of file system types to exclude from checking", Value: &plugin.ExcludeFSType, }, - &sensu.PluginConfigOption{ + { Path: "include-fs-path", Env: "", Argument: "include-fs-path", @@ -57,7 +59,7 @@ var ( Usage: "Comma separated list of file system paths to check", Value: &plugin.IncludeFSPath, }, - &sensu.PluginConfigOption{ + { Path: "exclude-fs-path", Env: "", Argument: "exclude-fs-path", @@ -66,7 +68,7 @@ var ( Usage: "Comma separated list of file system paths to exclude from checking", Value: &plugin.ExcludeFSPath, }, - &sensu.PluginConfigOption{ + { Path: "warning", Env: "", Argument: "warning", @@ -75,7 +77,7 @@ var ( Usage: "Warning threshold for file system usage", Value: &plugin.Warning, }, - &sensu.PluginConfigOption{ + { Path: "critical", Env: "", Argument: "critical", @@ -84,6 +86,24 @@ var ( Usage: "Critical threshold for file system usage", Value: &plugin.Critical, }, + { + Path: "include-pseudo-fs", + Env: "", + Argument: "include-pseudo-fs", + Shorthand: "p", + Default: false, + Usage: "Include pseudo-filesystems (e.g. tmpfs) (default false)", + Value: &plugin.IncludePseudo, + }, + { + Path: "fail-on-error", + Env: "", + Argument: "fail-on-error", + Shorthand: "f", + Default: false, + Usage: "Fail and exit on errors getting file system usage (e.g. permission denied) (default false)", + Value: &plugin.FailOnError, + }, } ) @@ -111,7 +131,7 @@ func executeCheck(event *types.Event) (int, error) { warnings int ) - parts, err := disk.Partitions(true) + parts, err := disk.Partitions(plugin.IncludePseudo) if err != nil { return sensu.CheckStateCritical, fmt.Errorf("Failed to get partions, error: %v", err) } @@ -120,7 +140,11 @@ func executeCheck(event *types.Event) (int, error) { device := p.Mountpoint s, err := disk.Usage(device) if err != nil { - return sensu.CheckStateCritical, fmt.Errorf("Failed to get disk usage for %s, error: %v", device, err) + if plugin.FailOnError { + return sensu.CheckStateCritical, fmt.Errorf("Failed to get disk usage for %s, error: %v", device, err) + } + fmt.Printf("%s UNKNOWN: %s - error: %v", plugin.PluginConfig.Name, device, err) + continue } // Ignore empty file systems