This repository has been archived by the owner on Jan 12, 2021. It is now read-only.
forked from goss-org/goss
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for disk_usage to goss (#8)
MVP PR that adds support for disk_usage (total bytes, free bytes and percent available). Testing strategy: - ci on linux and windows passes - goss add disk-usage "invalid dir", goss add disk-usage / and goss validate work as expected
- Loading branch information
1 parent
7ed2517
commit 6e9588d
Showing
15 changed files
with
431 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package resource | ||
|
||
import ( | ||
"github.com/aelsabbahy/goss/system" | ||
"github.com/aelsabbahy/goss/util" | ||
) | ||
|
||
type DiskUsage struct { | ||
Title string `json:"title,omitempty" yaml:"title,omitempty"` | ||
Meta meta `json:"meta,omitempty" yaml:"meta,omitempty"` | ||
Path string `json:"-" yaml:"-"` | ||
Exists matcher `json:"exists" yaml:"exists"` | ||
TotalBytes matcher `json:"total_bytes" yaml:"total_bytes"` | ||
FreeBytes matcher `json:"free_bytes" yaml:"free_bytes"` | ||
UtilizationPercent matcher `json:"utilization_percent" yaml:"utilization_percent"` | ||
} | ||
|
||
func (u *DiskUsage) ID() string { return u.Path } | ||
func (u *DiskUsage) SetID(id string) { u.Path = id } | ||
|
||
func (u *DiskUsage) GetTitle() string { return u.Title } | ||
func (u *DiskUsage) GetMeta() meta { return u.Meta } | ||
|
||
func (u *DiskUsage) Validate(sys *system.System) []TestResult { | ||
skip := false | ||
sysDU := sys.NewDiskUsage(u.Path, sys, util.Config{}) | ||
sysDU.Calculate() | ||
|
||
var results []TestResult | ||
results = append(results, ValidateValue(u, "exists", u.Exists, sysDU.Exists, skip)) | ||
if shouldSkip(results) { | ||
skip = true | ||
} | ||
if u.TotalBytes != nil { | ||
results = append(results, ValidateValue(u, "total_bytes", u.TotalBytes, sysDU.TotalBytes, skip)) | ||
} | ||
if u.FreeBytes != nil { | ||
results = append(results, ValidateValue(u, "free_bytes", u.FreeBytes, sysDU.FreeBytes, skip)) | ||
} | ||
if u.UtilizationPercent != nil { | ||
results = append(results, ValidateValue(u, "utilization_percent", u.UtilizationPercent, sysDU.UtilizationPercent, skip)) | ||
} | ||
return results | ||
} | ||
|
||
func NewDiskUsage(sysDiskUsage system.DiskUsage, config util.Config) (*DiskUsage, error) { | ||
sysDiskUsage.Calculate() | ||
exists, _ := sysDiskUsage.Exists() | ||
u := &DiskUsage{ | ||
Path: sysDiskUsage.Path(), | ||
Exists: exists, | ||
} | ||
|
||
if !contains(config.IgnoreList, "total_bytes") { | ||
if totalBytes, err := sysDiskUsage.TotalBytes(); err != nil { | ||
u.TotalBytes = totalBytes | ||
} | ||
} | ||
if !contains(config.IgnoreList, "free_bytes") { | ||
if freeBytes, err := sysDiskUsage.FreeBytes(); err != nil { | ||
u.FreeBytes = freeBytes | ||
} | ||
} | ||
if !contains(config.IgnoreList, "utilization_percent") { | ||
if utilizationPercent, err := sysDiskUsage.UtilizationPercent(); err != nil { | ||
u.UtilizationPercent = utilizationPercent | ||
} | ||
} | ||
return u, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.