Skip to content

Commit

Permalink
Merge pull request #4 from nixwiz/add_error_checking
Browse files Browse the repository at this point in the history
Add error checking
  • Loading branch information
Todd Campbell authored Dec 30, 2020
2 parents ce68896 + 9c41f35 commit a1d29af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased

## [0.1.1] - 2020-12-29

### Change
- Added appropriate error checking

## [0.1.0] - 2020-12-14

### Added
Expand Down
15 changes: 8 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import (
"github.com/shirou/gopsutil/disk"
)

// TODO
// 1. Magic factor for larger file systems
// 2. Metrics output (--metrics, --metrics-only)
// 3. inodes?

// Config represents the check plugin config.
type Config struct {
sensu.PluginConfig
Expand Down Expand Up @@ -116,11 +111,17 @@ func executeCheck(event *types.Event) (int, error) {
warnings int
)

parts, _ := disk.Partitions(true)
parts, err := disk.Partitions(true)
if err != nil {
return sensu.CheckStateCritical, fmt.Errorf("Failed to get partions, error: %v", err)
}

for _, p := range parts {
device := p.Mountpoint
s, _ := disk.Usage(device)
s, err := disk.Usage(device)
if err != nil {
return sensu.CheckStateCritical, fmt.Errorf("Failed to get disk usage for %s, error: %v", device, err)
}

// Ignore empty file systems
if s.Total == 0 {
Expand Down

0 comments on commit a1d29af

Please sign in to comment.