From 9c41f35213be6365866999c7267f9d583bb75d75 Mon Sep 17 00:00:00 2001 From: Todd Campbell Date: Tue, 29 Dec 2020 22:14:06 -0500 Subject: [PATCH] Add error checking Signed-off-by: Todd Campbell --- CHANGELOG.md | 5 +++++ main.go | 15 ++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7125f86..7f5aa91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/main.go b/main.go index bc75326..46745a9 100644 --- a/main.go +++ b/main.go @@ -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 @@ -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 {