Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions cmd/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"slices"
"strconv"
"time"

Expand Down Expand Up @@ -70,7 +71,6 @@ var diskCmd = &cobra.Command{
\_ [OK] Percentage of used inodes: 5.23%
|/_inodes_free_percentage=82.688% /_space_free=33146855424B;@40;@20;0;62669000704 /_space_used=26305536000B;40;20;0;62669000704 /_inodes_free=3231100;;@200;0;3907584 /_inodes_used=676484;;@400;0;3907584 /_space_free_percentage=55.754%;60;30 /_space_used_percentage=44.246%;@20:40;@20 /_inodes_used_percentage=17.312%;99;98 /boot_inodes_free_percentage=99.718% /boot_space_free=173091840B;@40;@20;0;493201408 /boot_space_used=294524928B;40;20;0;493201408 /boot_inodes_free=124576;;@200;0;124928 /boot_inodes_used=352;;@400;0;124928 /boot_space_free_percentage=37.016%;60;30 /boot_space_used_percentage=62.984%;@20:40;@20 /boot_inodes_used_percentage=0.282%;99;98 /var_inodes_free_percentage=92.832% /var_space_free=141826428928B;@40;@20;0;250843787264 /var_space_used=96200613888B;40;20;0;250843787264 /var_inodes_free=14510026;;@200;0;15630336 /var_inodes_used=1120310;;@400;0;15630336 /var_space_free_percentage=59.584%;60;30 /var_space_used_percentage=40.416%;@20:40;@20 /var_inodes_used_percentage=7.168%;99;98 /home_inodes_free_percentage=94.768% /home_space_free=247921197056B;@40;@20;0;502813065216 /home_space_used=229275156480B;40;20;0;502813065216 /home_inodes_free=29617311;;@200;0;31252480 /home_inodes_used=1635169;;@400;0;31252480 /home_space_free_percentage=51.954%;60;30 /home_space_used_percentage=48.046%;@20:40;@20 /home_inodes_used_percentage=5.232%;99;98`,
Run: func(_ *cobra.Command, _ []string) {

overall := result.Overall{}

err := validateOptions(&FsConfig)
Expand Down Expand Up @@ -129,7 +129,6 @@ var diskCmd = &cobra.Command{
}

overall.AddSubcheck(countResult)

} else if len(filesystemList) == 0 {
nullResult := result.PartialResult{}
_ = nullResult.SetState(check.OK)
Expand All @@ -154,12 +153,12 @@ var diskCmd = &cobra.Command{
if filesystemList[index].Error == nil {
sc.Output = fmt.Sprintf("%s (%.2f%% used space, %.2f%% free inodes)", sc.Output, filesystemList[index].UsageStats.UsedPercent, 100-filesystemList[index].UsageStats.InodesUsedPercent)
}

overall.AddSubcheck(sc)
}

// Output and Exit
check.ExitRaw(overall.GetStatus(), overall.GetOutput())

},
}

Expand Down Expand Up @@ -521,11 +520,8 @@ func computeFsCheckResult(fs *filesystem.FilesystemType, config *filesystem.Chec

filesystemsWithFixedNumberOfInodes := filesystem.GetFilesystemsWithFixedNumberOfInodes()

for i := range filesystemsWithFixedNumberOfInodes {
if fs.PartStats.Fstype == filesystemsWithFixedNumberOfInodes[i] {
returnResult.AddSubcheck(computeFsCheckResultInodes(fs, config))
break
}
if slices.Contains(filesystemsWithFixedNumberOfInodes, fs.PartStats.Fstype) {
returnResult.AddSubcheck(computeFsCheckResultInodes(fs, config))
}

return returnResult
Expand Down
9 changes: 9 additions & 0 deletions cmd/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var loadCmd = &cobra.Command{

// 1 Minute average
var partialLoad1 result.PartialResult

_ = partialLoad1.SetDefaultState(check.OK)

// TODO Use strings.Builder
Expand All @@ -77,14 +78,17 @@ var loadCmd = &cobra.Command{
} else {
_ = partialLoad1.SetState(check.OK)
}

if LoadConfig.PerCPU {
tmpOutput += fmt.Sprintf(", system total: %.2f", originalLoad[0])
}

partialLoad1.Output = tmpOutput
partialLoad1.Perfdata.Add(tmpPerfdata)

// 5 Minute average
var partialLoad5 result.PartialResult

_ = partialLoad5.SetDefaultState(check.OK)

tmpOutput = fmt.Sprintf("5 minute average: %.2f", loadStats.LoadAvg.Load5)
Expand All @@ -110,14 +114,17 @@ var loadCmd = &cobra.Command{
} else {
_ = partialLoad5.SetState(check.OK)
}

if LoadConfig.PerCPU {
tmpOutput += fmt.Sprintf(", system total: %.2f", originalLoad[1])
}

partialLoad5.Output = tmpOutput
partialLoad5.Perfdata.Add(tmpPerfdata)

// 15 Minute average
var partialLoad15 result.PartialResult

_ = partialLoad15.SetDefaultState(check.OK)

tmpOutput = fmt.Sprintf("15 minute average: %.2f", loadStats.LoadAvg.Load15)
Expand All @@ -143,9 +150,11 @@ var loadCmd = &cobra.Command{
} else {
_ = partialLoad15.SetState(check.OK)
}

if LoadConfig.PerCPU {
tmpOutput += fmt.Sprintf(", system total: %.2f", originalLoad[2])
}

partialLoad15.Output = tmpOutput
partialLoad15.Perfdata.Add(tmpPerfdata)

Expand Down
5 changes: 4 additions & 1 deletion cmd/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ var memoryCmd = &cobra.Command{
|available_memory_percentage=74.36%;15:100;5:100 available_memory=24856633344B;10:20;;0;33427595264 free_memory=16696102912B;;;0;33427595264 free_memory_percentage=49.947%;;50:80 used_memory=6542696448B;@10;;0;33427595264 free_memory_percentage=19.573% swap_usage_percent=0%;20;85 swap_used=0B;;;0;38654701568
`,
Run: func(_ *cobra.Command, _ []string) {

var overall result.Overall

// ## RAM stuff
Expand Down Expand Up @@ -59,6 +58,7 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa

// # Available
var partialMemAvailable result.PartialResult

_ = partialMemAvailable.SetDefaultState(check.OK)

partialMemAvailable.Output = fmt.Sprintf("Available Memory (%s/%s, %.2f%%)",
Expand Down Expand Up @@ -127,6 +127,7 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa

// # Free
var partialMemFree result.PartialResult

_ = partialMemFree.SetDefaultState(check.OK)

pdMemFree := perfdata.Perfdata{
Expand Down Expand Up @@ -197,6 +198,7 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa

// Used Memory
var partialMemUsed result.PartialResult

_ = partialMemUsed.SetDefaultState(check.OK)

partialMemUsed.Output = fmt.Sprintf("Used Memory (%s/%s, %.2f%%)",
Expand Down Expand Up @@ -411,6 +413,7 @@ func init() {

func computeSwapResults(stats *memory.Mem) *result.PartialResult {
var partialSwap result.PartialResult

_ = partialSwap.SetDefaultState(check.OK)

_ = partialSwap.SetDefaultState(check.OK)
Expand Down
2 changes: 0 additions & 2 deletions cmd/netdev.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,11 @@ func NetdevCheck(_ *cobra.Command, _ []string) {
overall := result.Overall{}

interfaces, err := netdev.GetAllInterfaces()

if err != nil {
check.ExitError(err)
}

interfaces, err = netdev.FilterInterfaces(&interfaces, &NetdevConfig.Filters)

if err != nil {
check.ExitError(err)
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/psi.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ func init() {

func checkPsiCPUPressure(config *psiConfig) result.PartialResult {
var cpuCheck result.PartialResult

_ = cpuCheck.SetDefaultState(check.OK)
cpuCheck.Output = "CPU"

Expand Down Expand Up @@ -376,6 +377,7 @@ func checkPsiCPUPressure(config *psiConfig) result.PartialResult {

func checkPsiIoPressure(config *psiConfig) result.PartialResult {
var ioCheck result.PartialResult

_ = ioCheck.SetDefaultState(check.OK)
ioCheck.Output = "IO"

Expand Down Expand Up @@ -515,6 +517,7 @@ func checkPsiIoPressure(config *psiConfig) result.PartialResult {

func checkPsiMemoryPressure(config *psiConfig) result.PartialResult {
var memoryCheck result.PartialResult

_ = memoryCheck.SetDefaultState(check.OK)
memoryCheck.Output = "Memory"

Expand Down
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ var rootCmd = &cobra.Command{
func Execute() {
defer check.CatchPanic()

if err := rootCmd.Execute(); err != nil {
err := rootCmd.Execute()
if err != nil {
check.ExitError(err)
}
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/sensors.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,23 @@ thresholds respecting the sensor type and the respective specialities`,
overall.Add(check.Unknown, "No devices found")
check.ExitRaw(overall.GetStatus(), overall.GetOutput())
}

var (
alarms uint = 0
)

for _, device := range devices {
var devicePartial result.PartialResult

_ = devicePartial.SetDefaultState(check.OK)

devicePartial.Output = device.Name
for idx, sensor := range device.Sensors {
var ssc result.PartialResult

_ = ssc.SetDefaultState(check.OK)
ssc.Perfdata.Add(&(device.Sensors[idx]).Perfdata)

if sensor.Alarm {
ssc.Output = "Alarm!"
_ = ssc.SetState(check.Critical)
Expand Down
3 changes: 1 addition & 2 deletions internal/common/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Options struct {
RegexpMatching bool
}

// Filters on Value with a list of filters
// Filter filters the input with a list of filters
// @return, true if value should be included, false otherwise
func Filter[I Filterable](input []I, filterList *[]string, valueIdentifier uint, opts Options) ([]I, error) {
if len(*filterList) == 0 {
Expand All @@ -40,7 +40,6 @@ func Filter[I Filterable](input []I, filterList *[]string, valueIdentifier uint,
(*filterList)[j],
input[i].GetFilterableValue(valueIdentifier),
)

if err != nil {
return []I{}, err
}
Expand Down
3 changes: 2 additions & 1 deletion internal/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/shirou/gopsutil/v3/disk"
)

// FilesystemType describes the retrieved metadata of a filesystem
// nolint: revive
type FilesystemType struct {
PartStats disk.PartitionStat
Expand All @@ -29,8 +30,8 @@ func GetDiskUsageSingle(ctx context.Context, timeout time.Duration, fs *Filesyst

go func() {
tmp := tmpFileSystemWrapper{}
usageStats, err := disk.Usage(fs.PartStats.Mountpoint)

usageStats, err := disk.Usage(fs.PartStats.Mountpoint)
if err == nil {
tmp.usage = *usageStats
}
Expand Down
7 changes: 1 addition & 6 deletions internal/netdev/netdev.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ func (iface IfaceData) GetFilterableValue(ident uint) string {

func GetAllInterfaces() ([]IfaceData, error) {
interfaces, err := listInterfaces()

if err != nil {
return []IfaceData{}, err
}
Expand All @@ -130,7 +129,6 @@ func GetAllInterfaces() ([]IfaceData, error) {
result[i].Name = interfaces[i]

err = getInterfaceState(&result[i])

if err != nil {
return result, err
}
Expand Down Expand Up @@ -216,14 +214,13 @@ func getInfacesStatistics(data *IfaceData) error {

for idx, stat := range GetIfaceStatNames() {
numberBytes, err := os.ReadFile(path.Join(basePath, stat))

if err != nil {
return err
}

numberString := string(numberBytes)
val, err = strconv.ParseUint(numberString[:len(numberString)-1], 10, 64)

val, err = strconv.ParseUint(numberString[:len(numberString)-1], 10, 64)
if err != nil {
return err
}
Expand All @@ -244,7 +241,6 @@ func FilterInterfaces(interfaces *[]IfaceData, filters *Filter) ([]IfaceData, er
EmptyFilterNoMatch: false,
},
)

if err != nil {
return []IfaceData{}, err
}
Expand All @@ -258,7 +254,6 @@ func FilterInterfaces(interfaces *[]IfaceData, filters *Filter) ([]IfaceData, er
EmptyFilterNoMatch: false,
},
)

if err != nil {
return []IfaceData{}, err
}
Expand Down
1 change: 0 additions & 1 deletion internal/psi/psi.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ func parsePressureValue(val string) (PressureValue, error) {

func readPressureFile(pressurePath string) (*PressureElement, error) {
readFile, err := os.Open(pressurePath)

if err != nil {
return nil, err
}
Expand Down
Loading
Loading