Skip to content

Commit

Permalink
Merge pull request #5 from nixwiz/add_flags
Browse files Browse the repository at this point in the history
Add failure flag and pseudo-fs flag
  • Loading branch information
Todd Campbell authored Dec 30, 2020
2 parents a1d29af + 6cded9d commit ddccff8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
40 changes: 32 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type Config struct {
ExcludeFSPath []string
Warning float64
Critical float64
IncludePseudo bool
FailOnError bool
}

var (
Expand All @@ -30,7 +32,7 @@ var (
}

options = []*sensu.PluginConfigOption{
&sensu.PluginConfigOption{
{
Path: "include-fs-type",
Env: "",
Argument: "include-fs-type",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -75,7 +77,7 @@ var (
Usage: "Warning threshold for file system usage",
Value: &plugin.Warning,
},
&sensu.PluginConfigOption{
{
Path: "critical",
Env: "",
Argument: "critical",
Expand All @@ -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,
},
}
)

Expand Down Expand Up @@ -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)
}
Expand All @@ -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
Expand Down

0 comments on commit ddccff8

Please sign in to comment.