From e10f039f94bfe3337a4b189b947c9b360cbdea26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Wed, 24 Jun 2026 16:59:12 +0200 Subject: [PATCH 1/3] Migrate to go-check 1.0.0-rc4 --- cmd/filesystem.go | 135 +++++++++++++++---------------- cmd/load.go | 39 +++++---- cmd/memory.go | 108 ++++++++++++------------- cmd/netdev.go | 21 +++-- cmd/psi.go | 74 ++++++++--------- cmd/root.go | 4 +- cmd/sensors.go | 16 ++-- go.mod | 2 +- go.sum | 2 + internal/load/load.go | 6 +- internal/psi/psi.go | 16 ++-- internal/psi/psi_test.go | 40 ++++----- internal/sensors/sensors.go | 3 +- internal/sensors/sensors_test.go | 3 +- 14 files changed, 232 insertions(+), 237 deletions(-) diff --git a/cmd/filesystem.go b/cmd/filesystem.go index 2d37289..1007e07 100644 --- a/cmd/filesystem.go +++ b/cmd/filesystem.go @@ -12,7 +12,6 @@ import ( "github.com/NETWAYS/check_system_basics/internal/filesystem" "github.com/NETWAYS/go-check" "github.com/NETWAYS/go-check/convert" - "github.com/NETWAYS/go-check/perfdata" "github.com/NETWAYS/go-check/result" "github.com/shirou/gopsutil/v3/disk" "github.com/spf13/cobra" @@ -109,8 +108,8 @@ var diskCmd = &cobra.Command{ } if FsConfig.CriticalTotalCountOfFs.IsSet || FsConfig.WarningTotalCountOfFs.IsSet { - countResult := result.PartialResult{} - _ = countResult.SetDefaultState(check.OK) + countResult := result.NewPartialResult() + countResult.SetDefaultState(check.OK) if len(filesystemList) == 1 { countResult.Output = "Found one matching filesystem" @@ -119,10 +118,10 @@ var diskCmd = &cobra.Command{ } if FsConfig.CriticalTotalCountOfFs.IsSet && FsConfig.CriticalTotalCountOfFs.Th.DoesViolate(float64(len(filesystemList))) { - _ = countResult.SetState(check.Critical) + countResult.SetState(check.Critical) countResult.Output += ". This violates the threshold of " + FsConfig.CriticalTotalCountOfFs.String() } else if FsConfig.WarningTotalCountOfFs.IsSet && FsConfig.WarningTotalCountOfFs.Th.DoesViolate(float64(len(filesystemList))) { - _ = countResult.SetState(check.Warning) + countResult.SetState(check.Warning) countResult.Output += ". This violates the threshold of " + FsConfig.WarningTotalCountOfFs.String() } else { countResult.Output += ". This number resides within the given thresholds" @@ -130,11 +129,11 @@ var diskCmd = &cobra.Command{ overall.AddSubcheck(countResult) } else if len(filesystemList) == 0 { - nullResult := result.PartialResult{} - _ = nullResult.SetState(check.OK) + nullResult := result.NewPartialResult() + nullResult.SetState(check.OK) nullResult.Output = "No filesystems remaining after applying filter expressions. Therefore all are OK" overall.AddSubcheck(nullResult) - check.ExitRaw(overall.GetStatus(), overall.GetOutput()) + check.Exit(overall.GetStatus(), overall.GetOutput()) } // Retrieve stats @@ -158,18 +157,18 @@ var diskCmd = &cobra.Command{ } // Output and Exit - check.ExitRaw(overall.GetStatus(), overall.GetOutput()) + check.Exit(overall.GetStatus(), overall.GetOutput()) }, } -func computeFsCheckResultInodes(fs *filesystem.FilesystemType, config *filesystem.CheckConfig) result.PartialResult { +func computeFsCheckResultInodes(fs *filesystem.FilesystemType, config *filesystem.CheckConfig) *result.PartialResult { returnResult := result.PartialResult{ Output: "Inodes", } - _ = returnResult.SetDefaultState(check.OK) + returnResult.SetDefaultState(check.OK) // One Perfdata point here with inodes free, warn, crit, total - pdAbsoluteFreeInodes := perfdata.Perfdata{ + pdAbsoluteFreeInodes := check.Perfdata{ Min: 0, Max: fs.UsageStats.InodesTotal, Uom: "", @@ -178,14 +177,14 @@ func computeFsCheckResultInodes(fs *filesystem.FilesystemType, config *filesyste } if config.WarningAbsolutThreshold.Inodes.Free.IsSet || config.CriticalAbsolutThreshold.Inodes.Free.IsSet { - tmpPartialResult := result.PartialResult{} - _ = tmpPartialResult.SetDefaultState(check.OK) + tmpPartialResult := result.NewPartialResult() + tmpPartialResult.SetDefaultState(check.OK) if config.WarningAbsolutThreshold.Inodes.Free.IsSet { pdAbsoluteFreeInodes.Warn = &config.WarningAbsolutThreshold.Inodes.Free.Th if config.WarningAbsolutThreshold.Inodes.Free.Th.DoesViolate(float64(fs.UsageStats.InodesFree)) { - _ = tmpPartialResult.SetState(check.Warning) + tmpPartialResult.SetState(check.Warning) tmpPartialResult.Output = fmt.Sprintf("Absolute free inode number violates threshold: %d / %d", fs.UsageStats.InodesFree, fs.UsageStats.InodesTotal) } } @@ -194,7 +193,7 @@ func computeFsCheckResultInodes(fs *filesystem.FilesystemType, config *filesyste pdAbsoluteFreeInodes.Crit = &config.CriticalAbsolutThreshold.Inodes.Free.Th if config.CriticalAbsolutThreshold.Inodes.Free.Th.DoesViolate(float64(fs.UsageStats.InodesFree)) { - _ = tmpPartialResult.SetState(check.Critical) + tmpPartialResult.SetState(check.Critical) tmpPartialResult.Output = fmt.Sprintf("Absolute free inode number violates threshold: %d / %d", fs.UsageStats.InodesFree, fs.UsageStats.InodesTotal) } } @@ -210,7 +209,7 @@ func computeFsCheckResultInodes(fs *filesystem.FilesystemType, config *filesyste } // One Perfdata point here with inodes used, warn, crit, total - pdAbsoluteUsedInodes := perfdata.Perfdata{ + pdAbsoluteUsedInodes := check.Perfdata{ Min: 0, Max: fs.UsageStats.InodesTotal, Uom: "", @@ -219,14 +218,14 @@ func computeFsCheckResultInodes(fs *filesystem.FilesystemType, config *filesyste } if config.WarningAbsolutThreshold.Inodes.Used.IsSet || config.CriticalAbsolutThreshold.Inodes.Used.IsSet { - tmpPartialResult := result.PartialResult{} - _ = tmpPartialResult.SetDefaultState(check.OK) + tmpPartialResult := result.NewPartialResult() + tmpPartialResult.SetDefaultState(check.OK) if config.WarningAbsolutThreshold.Inodes.Used.IsSet { pdAbsoluteUsedInodes.Warn = &config.WarningAbsolutThreshold.Inodes.Used.Th if config.WarningAbsolutThreshold.Inodes.Used.Th.DoesViolate(float64(fs.UsageStats.InodesUsed)) { - _ = tmpPartialResult.SetState(check.Warning) + tmpPartialResult.SetState(check.Warning) tmpPartialResult.Output = fmt.Sprintf("Absolute used inode number violates threshold: %d / %d", fs.UsageStats.InodesUsed, fs.UsageStats.InodesTotal) } } @@ -235,7 +234,7 @@ func computeFsCheckResultInodes(fs *filesystem.FilesystemType, config *filesyste pdAbsoluteUsedInodes.Crit = &config.CriticalAbsolutThreshold.Inodes.Used.Th if config.CriticalAbsolutThreshold.Inodes.Used.Th.DoesViolate(float64(fs.UsageStats.InodesUsed)) { - _ = tmpPartialResult.SetState(check.Critical) + tmpPartialResult.SetState(check.Critical) tmpPartialResult.Output = fmt.Sprintf("Absolute used inode number violates threshold: %d / %d", fs.UsageStats.InodesUsed, fs.UsageStats.InodesTotal) } } @@ -251,21 +250,21 @@ func computeFsCheckResultInodes(fs *filesystem.FilesystemType, config *filesyste } // One Perfdata point here with inodes free, warn, crit, total - pdPercentageFreeInodes := perfdata.Perfdata{ + pdPercentageFreeInodes := check.Perfdata{ Uom: "%", Label: fs.PartStats.Mountpoint + "_inodes_free_percentage", Value: 100 - fs.UsageStats.InodesUsedPercent, } if config.WarningPercentThreshold.Inodes.Free.IsSet || config.CriticalPercentThreshold.Inodes.Free.IsSet { - tmpPartialResult := result.PartialResult{} - _ = tmpPartialResult.SetDefaultState(check.OK) + tmpPartialResult := result.NewPartialResult() + tmpPartialResult.SetDefaultState(check.OK) if config.WarningPercentThreshold.Inodes.Free.IsSet { pdPercentageFreeInodes.Warn = &config.WarningPercentThreshold.Inodes.Free.Th if config.WarningPercentThreshold.Inodes.Free.Th.DoesViolate(pdPercentageFreeInodes.Value.(float64)) { - _ = tmpPartialResult.SetState(check.Warning) + tmpPartialResult.SetState(check.Warning) tmpPartialResult.Output = fmt.Sprintf("Percentage of free inodes violates threshold: %.2f%%", pdPercentageFreeInodes.Value) } } @@ -274,7 +273,7 @@ func computeFsCheckResultInodes(fs *filesystem.FilesystemType, config *filesyste pdPercentageFreeInodes.Warn = &config.CriticalPercentThreshold.Inodes.Free.Th if config.CriticalPercentThreshold.Inodes.Free.Th.DoesViolate(pdPercentageFreeInodes.Value.(float64)) { - _ = tmpPartialResult.SetState(check.Critical) + tmpPartialResult.SetState(check.Critical) tmpPartialResult.Output = fmt.Sprintf("Percentage of free inodes violates threshold: %.2f%%", pdPercentageFreeInodes.Value) } } @@ -290,21 +289,21 @@ func computeFsCheckResultInodes(fs *filesystem.FilesystemType, config *filesyste } // One Perfdata point here with inodes used, warn, crit, total - pdPercentageUsedInodes := perfdata.Perfdata{ + pdPercentageUsedInodes := check.Perfdata{ Uom: "%", Label: fs.PartStats.Mountpoint + "_inodes_used_percentage", Value: fs.UsageStats.InodesUsedPercent, } if config.WarningPercentThreshold.Inodes.Used.IsSet || config.CriticalPercentThreshold.Inodes.Used.IsSet { - tmpPartialResult := result.PartialResult{} - _ = tmpPartialResult.SetDefaultState(check.OK) + tmpPartialResult := result.NewPartialResult() + tmpPartialResult.SetDefaultState(check.OK) if config.WarningPercentThreshold.Inodes.Used.IsSet { pdPercentageUsedInodes.Warn = &config.WarningPercentThreshold.Inodes.Used.Th if config.WarningPercentThreshold.Inodes.Used.Th.DoesViolate(fs.UsageStats.InodesUsedPercent) { - _ = tmpPartialResult.SetState(check.Warning) + tmpPartialResult.SetState(check.Warning) tmpPartialResult.Output = fmt.Sprintf("Percentage of used inodes violates threshold: %.2f%%", fs.UsageStats.InodesUsedPercent) } } @@ -313,7 +312,7 @@ func computeFsCheckResultInodes(fs *filesystem.FilesystemType, config *filesyste pdPercentageUsedInodes.Crit = &config.CriticalPercentThreshold.Inodes.Used.Th if config.CriticalPercentThreshold.Inodes.Used.Th.DoesViolate(fs.UsageStats.InodesUsedPercent) { - _ = tmpPartialResult.SetState(check.Critical) + tmpPartialResult.SetState(check.Critical) tmpPartialResult.Output = fmt.Sprintf("Percentage of used inodes violates threshold: %.2f%%", fs.UsageStats.InodesUsedPercent) } } @@ -328,18 +327,17 @@ func computeFsCheckResultInodes(fs *filesystem.FilesystemType, config *filesyste returnResult.Perfdata.Add(&pdPercentageUsedInodes) } - return returnResult + return &returnResult } -func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem.CheckConfig) result.PartialResult { - returnResult := result.PartialResult{ - Output: "Space usage", - } - _ = returnResult.SetDefaultState(check.OK) +func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem.CheckConfig) *result.PartialResult { + returnResult := result.NewPartialResult() + returnResult.Output = "Space usage" + returnResult.SetDefaultState(check.OK) // Absolute numbers // One Perfdata point here with bytes free, warn, crit, total - pdAbsoluteFreeSpace := perfdata.Perfdata{ + pdAbsoluteFreeSpace := check.Perfdata{ Min: 0, Max: fs.UsageStats.Total, Uom: "B", @@ -348,15 +346,15 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem } if config.WarningAbsolutThreshold.Space.Free.IsSet || config.CriticalAbsolutThreshold.Space.Free.IsSet { - tmpPartialResult := result.PartialResult{} - _ = tmpPartialResult.SetDefaultState(check.OK) + tmpPartialResult := result.NewPartialResult() + tmpPartialResult.SetDefaultState(check.OK) if config.WarningAbsolutThreshold.Space.Free.IsSet { pdAbsoluteFreeSpace.Warn = &config.WarningAbsolutThreshold.Space.Free.Th if config.WarningAbsolutThreshold.Space.Free.Th.DoesViolate(float64(fs.UsageStats.Free)) { - _ = tmpPartialResult.SetState(check.Warning) - tmpPartialResult.Output = fmt.Sprintf("Absolute free space violates threshold: %s / %s", convert.BytesIEC(fs.UsageStats.Free).HumanReadable(), convert.BytesIEC(fs.UsageStats.Total).HumanReadable()) + tmpPartialResult.SetState(check.Warning) + tmpPartialResult.Output = fmt.Sprintf("Absolute free space violates threshold: %s / %s", convert.BytesIEC(fs.UsageStats.Free), convert.BytesIEC(fs.UsageStats.Total)) } } @@ -364,13 +362,13 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem pdAbsoluteFreeSpace.Crit = &config.CriticalAbsolutThreshold.Space.Free.Th if config.CriticalAbsolutThreshold.Space.Free.Th.DoesViolate(float64(fs.UsageStats.Free)) { - _ = tmpPartialResult.SetState(check.Critical) - tmpPartialResult.Output = fmt.Sprintf("Absolute free space violates threshold: %s / %s", convert.BytesIEC(fs.UsageStats.Free).HumanReadable(), convert.BytesIEC(fs.UsageStats.Total).HumanReadable()) + tmpPartialResult.SetState(check.Critical) + tmpPartialResult.Output = fmt.Sprintf("Absolute free space violates threshold: %s / %s", convert.BytesIEC(fs.UsageStats.Free), convert.BytesIEC(fs.UsageStats.Total)) } } if tmpPartialResult.GetStatus() == check.OK { - tmpPartialResult.Output = fmt.Sprintf("Absolute free space: %s / %s", convert.BytesIEC(fs.UsageStats.Free).HumanReadable(), convert.BytesIEC(fs.UsageStats.Total).HumanReadable()) + tmpPartialResult.Output = fmt.Sprintf("Absolute free space: %s / %s", convert.BytesIEC(fs.UsageStats.Free), convert.BytesIEC(fs.UsageStats.Total)) } tmpPartialResult.Perfdata.Add(&pdAbsoluteFreeSpace) @@ -380,7 +378,7 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem } // One Perfdata point here with bytes used, warn, crit, total - pdAbsoluteUsedSpace := perfdata.Perfdata{ + pdAbsoluteUsedSpace := check.Perfdata{ Min: 0, Max: fs.UsageStats.Total, Uom: "B", @@ -389,15 +387,15 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem } if config.WarningAbsolutThreshold.Space.Used.IsSet || config.CriticalAbsolutThreshold.Space.Used.IsSet { - tmpPartialResult := result.PartialResult{} - _ = tmpPartialResult.SetDefaultState(check.OK) + tmpPartialResult := result.NewPartialResult() + tmpPartialResult.SetDefaultState(check.OK) if config.WarningAbsolutThreshold.Space.Used.IsSet { pdAbsoluteUsedSpace.Warn = &config.WarningAbsolutThreshold.Space.Used.Th if config.WarningAbsolutThreshold.Space.Used.Th.DoesViolate(float64(fs.UsageStats.Used)) { - _ = tmpPartialResult.SetState(check.Warning) - tmpPartialResult.Output = fmt.Sprintf("Absolute used space violates threshold: %s / %s", convert.BytesIEC(fs.UsageStats.Used).HumanReadable(), convert.BytesIEC(fs.UsageStats.Total).HumanReadable()) + tmpPartialResult.SetState(check.Warning) + tmpPartialResult.Output = fmt.Sprintf("Absolute used space violates threshold: %s / %s", convert.BytesIEC(fs.UsageStats.Used), convert.BytesIEC(fs.UsageStats.Total)) } } @@ -405,13 +403,13 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem pdAbsoluteUsedSpace.Crit = &config.CriticalAbsolutThreshold.Space.Used.Th if config.CriticalAbsolutThreshold.Space.Used.Th.DoesViolate(float64(fs.UsageStats.Used)) { - _ = tmpPartialResult.SetState(check.Critical) - tmpPartialResult.Output = fmt.Sprintf("Absolute used space violates threshold: %s / %s", convert.BytesIEC(fs.UsageStats.Used).HumanReadable(), convert.BytesIEC(fs.UsageStats.Total).HumanReadable()) + tmpPartialResult.SetState(check.Critical) + tmpPartialResult.Output = fmt.Sprintf("Absolute used space violates threshold: %s / %s", convert.BytesIEC(fs.UsageStats.Used), convert.BytesIEC(fs.UsageStats.Total)) } } if tmpPartialResult.GetStatus() == check.OK { - tmpPartialResult.Output = fmt.Sprintf("Absolute used space: %s / %s", convert.BytesIEC(fs.UsageStats.Used).HumanReadable(), convert.BytesIEC(fs.UsageStats.Total).HumanReadable()) + tmpPartialResult.Output = fmt.Sprintf("Absolute used space: %s / %s", convert.BytesIEC(fs.UsageStats.Used), convert.BytesIEC(fs.UsageStats.Total)) } tmpPartialResult.Perfdata.Add(&pdAbsoluteUsedSpace) @@ -424,21 +422,21 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem // Space // One Perfdata point here with bytes free, warn, crit, total - pdPercentageFreeSpace := perfdata.Perfdata{ + pdPercentageFreeSpace := check.Perfdata{ Uom: "%", Label: fs.PartStats.Mountpoint + "_space_free_percentage", Value: 100 - fs.UsageStats.UsedPercent, } if config.WarningPercentThreshold.Space.Free.IsSet || config.CriticalPercentThreshold.Space.Free.IsSet { - tmpPartialResult := result.PartialResult{} - _ = tmpPartialResult.SetDefaultState(check.OK) + tmpPartialResult := result.NewPartialResult() + tmpPartialResult.SetDefaultState(check.OK) if config.WarningPercentThreshold.Space.Free.IsSet { pdPercentageFreeSpace.Warn = &config.WarningPercentThreshold.Space.Free.Th if config.WarningPercentThreshold.Space.Free.Th.DoesViolate(pdPercentageFreeSpace.Value.(float64)) { - _ = tmpPartialResult.SetState(check.Warning) + tmpPartialResult.SetState(check.Warning) tmpPartialResult.Output = fmt.Sprintf("Percentage of free space violates threshold: %.2f%%", pdPercentageFreeSpace.Value) } } @@ -447,7 +445,7 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem pdPercentageFreeSpace.Crit = &config.CriticalPercentThreshold.Space.Free.Th if config.CriticalPercentThreshold.Space.Free.Th.DoesViolate(pdPercentageFreeSpace.Value.(float64)) { - _ = tmpPartialResult.SetState(check.Critical) + tmpPartialResult.SetState(check.Critical) tmpPartialResult.Output = fmt.Sprintf("Percentage of free space violates threshold: %.2f%%", pdPercentageFreeSpace.Value) } } @@ -463,21 +461,21 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem } // One Perfdata point here with bytes used, warn, crit, total - pdPercentageUsedSpace := perfdata.Perfdata{ + pdPercentageUsedSpace := check.Perfdata{ Uom: "%", Label: fs.PartStats.Mountpoint + "_space_used_percentage", Value: fs.UsageStats.UsedPercent, } if config.WarningPercentThreshold.Space.Used.IsSet || config.CriticalPercentThreshold.Space.Used.IsSet { - tmpPartialResult := result.PartialResult{} - _ = tmpPartialResult.SetDefaultState(check.OK) + tmpPartialResult := result.NewPartialResult() + tmpPartialResult.SetDefaultState(check.OK) if config.WarningPercentThreshold.Space.Used.IsSet { pdPercentageUsedSpace.Warn = &config.WarningPercentThreshold.Space.Used.Th if config.WarningPercentThreshold.Space.Used.Th.DoesViolate(fs.UsageStats.UsedPercent) { - _ = tmpPartialResult.SetState(check.Warning) + tmpPartialResult.SetState(check.Warning) tmpPartialResult.Output = fmt.Sprintf("Percentage of used space violates threshold: %.2f%%", fs.UsageStats.UsedPercent) } } @@ -486,7 +484,7 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem pdPercentageUsedSpace.Crit = &config.CriticalPercentThreshold.Space.Used.Th if config.CriticalPercentThreshold.Space.Used.Th.DoesViolate(fs.UsageStats.UsedPercent) { - _ = tmpPartialResult.SetState(check.Critical) + tmpPartialResult.SetState(check.Critical) tmpPartialResult.Output = fmt.Sprintf("Percentage of used space violates threshold: %.2f%%", fs.UsageStats.UsedPercent) } } @@ -504,13 +502,13 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem return returnResult } -func computeFsCheckResult(fs *filesystem.FilesystemType, config *filesystem.CheckConfig) result.PartialResult { - returnResult := result.PartialResult{} +func computeFsCheckResult(fs *filesystem.FilesystemType, config *filesystem.CheckConfig) *result.PartialResult { + returnResult := result.NewPartialResult() returnResult.Output = fs.PartStats.Mountpoint - _ = returnResult.SetDefaultState(check.OK) + returnResult.SetDefaultState(check.OK) if fs.Error != nil { - _ = returnResult.SetState(check.Unknown) + returnResult.SetState(check.Unknown) returnResult.Output = fmt.Sprintf("Could not determine status of the filesystem mounted at %s (%s) stats due to: %s", fs.PartStats.Mountpoint, fs.PartStats.Device, fs.Error) return returnResult @@ -521,7 +519,8 @@ func computeFsCheckResult(fs *filesystem.FilesystemType, config *filesystem.Chec filesystemsWithFixedNumberOfInodes := filesystem.GetFilesystemsWithFixedNumberOfInodes() if slices.Contains(filesystemsWithFixedNumberOfInodes, fs.PartStats.Fstype) { - returnResult.AddSubcheck(computeFsCheckResultInodes(fs, config)) + tmp := computeFsCheckResultInodes(fs, config) + returnResult.AddSubcheck(tmp) } return returnResult diff --git a/cmd/load.go b/cmd/load.go index 60ecdcc..d2e4813 100644 --- a/cmd/load.go +++ b/cmd/load.go @@ -5,7 +5,6 @@ import ( "github.com/NETWAYS/check_system_basics/internal/load" "github.com/NETWAYS/go-check" - "github.com/NETWAYS/go-check/perfdata" "github.com/NETWAYS/go-check/result" "github.com/shirou/gopsutil/v3/cpu" "github.com/spf13/cobra" @@ -50,13 +49,13 @@ var loadCmd = &cobra.Command{ var overall result.Overall // 1 Minute average - var partialLoad1 result.PartialResult + partialLoad1 := result.NewPartialResult() - _ = partialLoad1.SetDefaultState(check.OK) + partialLoad1.SetDefaultState(check.OK) // TODO Use strings.Builder tmpOutput := fmt.Sprintf("1 minute average: %.2f", loadStats.LoadAvg.Load1) - tmpPerfdata := &perfdata.Perfdata{ + tmpPerfdata := &check.Perfdata{ Label: "load1", Value: loadStats.LoadAvg.Load1, Min: 0, @@ -66,17 +65,17 @@ var loadCmd = &cobra.Command{ if LoadConfig.Load1Th.Crit.IsSet { tmpPerfdata.Crit = &LoadConfig.Load1Th.Crit.Th if LoadConfig.Load1Th.Crit.Th.DoesViolate(loadStats.LoadAvg.Load1) { - _ = partialLoad1.SetState(check.Critical) + partialLoad1.SetState(check.Critical) tmpOutput += critThresMsg } } else if LoadConfig.Load1Th.Warn.IsSet { tmpPerfdata.Warn = &LoadConfig.Load1Th.Warn.Th if LoadConfig.Load1Th.Warn.Th.DoesViolate(loadStats.LoadAvg.Load1) { - _ = partialLoad1.SetState(check.Warning) + partialLoad1.SetState(check.Warning) tmpOutput += warnThresMsg } } else { - _ = partialLoad1.SetState(check.OK) + partialLoad1.SetState(check.OK) } if LoadConfig.PerCPU { @@ -87,12 +86,12 @@ var loadCmd = &cobra.Command{ partialLoad1.Perfdata.Add(tmpPerfdata) // 5 Minute average - var partialLoad5 result.PartialResult + partialLoad5 := result.NewPartialResult() - _ = partialLoad5.SetDefaultState(check.OK) + partialLoad5.SetDefaultState(check.OK) tmpOutput = fmt.Sprintf("5 minute average: %.2f", loadStats.LoadAvg.Load5) - tmpPerfdata = &perfdata.Perfdata{ + tmpPerfdata = &check.Perfdata{ Label: "load5", Value: loadStats.LoadAvg.Load5, Min: 0, @@ -102,17 +101,17 @@ var loadCmd = &cobra.Command{ if LoadConfig.Load5Th.Crit.IsSet { tmpPerfdata.Crit = &LoadConfig.Load5Th.Crit.Th if LoadConfig.Load5Th.Crit.Th.DoesViolate(loadStats.LoadAvg.Load5) { - _ = partialLoad5.SetState(check.Critical) + partialLoad5.SetState(check.Critical) tmpOutput += critThresMsg } } else if LoadConfig.Load5Th.Warn.IsSet { tmpPerfdata.Warn = &LoadConfig.Load5Th.Warn.Th if LoadConfig.Load5Th.Warn.Th.DoesViolate(loadStats.LoadAvg.Load5) { - _ = partialLoad5.SetState(check.Warning) + partialLoad5.SetState(check.Warning) tmpOutput += warnThresMsg } } else { - _ = partialLoad5.SetState(check.OK) + partialLoad5.SetState(check.OK) } if LoadConfig.PerCPU { @@ -123,12 +122,12 @@ var loadCmd = &cobra.Command{ partialLoad5.Perfdata.Add(tmpPerfdata) // 15 Minute average - var partialLoad15 result.PartialResult + partialLoad15 := result.NewPartialResult() - _ = partialLoad15.SetDefaultState(check.OK) + partialLoad15.SetDefaultState(check.OK) tmpOutput = fmt.Sprintf("15 minute average: %.2f", loadStats.LoadAvg.Load15) - tmpPerfdata = &perfdata.Perfdata{ + tmpPerfdata = &check.Perfdata{ Label: "load15", Value: loadStats.LoadAvg.Load15, Min: 0, @@ -138,17 +137,17 @@ var loadCmd = &cobra.Command{ if LoadConfig.Load15Th.Crit.IsSet { tmpPerfdata.Crit = &LoadConfig.Load15Th.Crit.Th if LoadConfig.Load15Th.Crit.Th.DoesViolate(loadStats.LoadAvg.Load15) { - _ = partialLoad15.SetState(check.Critical) + partialLoad15.SetState(check.Critical) tmpOutput += critThresMsg } } else if LoadConfig.Load15Th.Warn.IsSet { tmpPerfdata.Warn = &LoadConfig.Load15Th.Warn.Th if LoadConfig.Load15Th.Warn.Th.DoesViolate(loadStats.LoadAvg.Load15) { - _ = partialLoad15.SetState(check.Warning) + partialLoad15.SetState(check.Warning) tmpOutput += warnThresMsg } } else { - _ = partialLoad15.SetState(check.OK) + partialLoad15.SetState(check.OK) } if LoadConfig.PerCPU { @@ -162,7 +161,7 @@ var loadCmd = &cobra.Command{ overall.AddSubcheck(partialLoad5) overall.AddSubcheck(partialLoad15) - check.ExitRaw(overall.GetStatus(), overall.GetOutput()) + check.Exit(overall.GetStatus(), overall.GetOutput()) }, } diff --git a/cmd/memory.go b/cmd/memory.go index 6c3bd41..e007b58 100644 --- a/cmd/memory.go +++ b/cmd/memory.go @@ -7,7 +7,6 @@ import ( "github.com/NETWAYS/check_system_basics/internal/memory" "github.com/NETWAYS/go-check" "github.com/NETWAYS/go-check/convert" - "github.com/NETWAYS/go-check/perfdata" "github.com/NETWAYS/go-check/result" "github.com/spf13/cobra" ) @@ -43,31 +42,30 @@ var memoryCmd = &cobra.Command{ // Swap stuff if memStats.VirtMem.SwapTotal != 0 { partSwap := computeSwapResults(memStats) - overall.AddSubcheck(*partSwap) + overall.AddSubcheck(partSwap) } - check.ExitRaw(overall.GetStatus(), overall.GetOutput()) + check.Exit(overall.GetStatus(), overall.GetOutput()) }, } -func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.PartialResult { - partialMem := result.PartialResult{ - Output: "RAM", - } - _ = partialMem.SetDefaultState(check.OK) +func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) *result.PartialResult { + partialMem := result.NewPartialResult() + partialMem.Output = "RAM" + partialMem.SetDefaultState(check.OK) // # Available - var partialMemAvailable result.PartialResult + partialMemAvailable := result.NewPartialResult() - _ = partialMemAvailable.SetDefaultState(check.OK) + partialMemAvailable.SetDefaultState(check.OK) partialMemAvailable.Output = fmt.Sprintf("Available Memory (%s/%s, %.2f%%)", - convert.BytesIEC(memStats.VirtMem.Available).HumanReadable(), - convert.BytesIEC(memStats.VirtMem.Total).HumanReadable(), + convert.BytesIEC(memStats.VirtMem.Available), + convert.BytesIEC(memStats.VirtMem.Total), memStats.MemAvailablePercentage) // perfdata - pdMemAvailable := perfdata.Perfdata{ + pdMemAvailable := check.Perfdata{ Label: "available_memory", Value: memStats.VirtMem.Available, Uom: "B", @@ -75,7 +73,7 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa Max: memStats.VirtMem.Total, } - pdMemAvailablePrcnt := perfdata.Perfdata{ + pdMemAvailablePrcnt := check.Perfdata{ Label: "available_memory_percentage", Value: float64(memStats.VirtMem.Available) / float64(memStats.VirtMem.Total/100), Uom: "%", @@ -85,7 +83,7 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa pdMemAvailable.Warn = &config.MemAvailable.Warn.Th if config.MemAvailable.Warn.Th.DoesViolate(float64(memStats.VirtMem.Available)) { - _ = partialMemAvailable.SetState(check.Warning) + partialMemAvailable.SetState(check.Warning) } } @@ -93,7 +91,7 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa pdMemAvailablePrcnt.Warn = &config.MemAvailablePercentage.Warn.Th if config.MemAvailablePercentage.Warn.Th.DoesViolate(memStats.MemAvailablePercentage) { - _ = partialMemAvailable.SetState(check.Warning) + partialMemAvailable.SetState(check.Warning) } } @@ -101,7 +99,7 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa pdMemAvailable.Crit = &config.MemAvailable.Crit.Th if config.MemAvailable.Crit.Th.DoesViolate(float64(memStats.VirtMem.Available)) { - _ = partialMemAvailable.SetState(check.Critical) + partialMemAvailable.SetState(check.Critical) } } @@ -109,7 +107,7 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa pdMemAvailablePrcnt.Crit = &config.MemAvailablePercentage.Crit.Th if config.MemAvailablePercentage.Crit.Th.DoesViolate(memStats.MemAvailablePercentage) { - _ = partialMemAvailable.SetState(check.Critical) + partialMemAvailable.SetState(check.Critical) } } @@ -122,15 +120,15 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa if (partialMemAvailable.GetStatus() > partialMem.GetStatus()) && partialMemAvailable.GetStatus() != check.Unknown { - _ = partialMem.SetState(partialMemAvailable.GetStatus()) + partialMem.SetState(partialMemAvailable.GetStatus()) } // # Free - var partialMemFree result.PartialResult + partialMemFree := result.NewPartialResult() - _ = partialMemFree.SetDefaultState(check.OK) + partialMemFree.SetDefaultState(check.OK) - pdMemFree := perfdata.Perfdata{ + pdMemFree := check.Perfdata{ Label: "free_memory", Uom: "B", Value: memStats.VirtMem.Free, @@ -140,22 +138,22 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa MemFreePercentage := float64(memStats.VirtMem.Free) / (float64(memStats.VirtMem.Total) / 100) - pdMemFreePercentage := perfdata.Perfdata{ + pdMemFreePercentage := check.Perfdata{ Label: "free_memory_percentage", Value: MemFreePercentage, Uom: "%", } partialMemFree.Output = fmt.Sprintf("Free Memory (%s/%s, %.2f%%)", - convert.BytesIEC(memStats.VirtMem.Free).HumanReadable(), - convert.BytesIEC(memStats.VirtMem.Total).HumanReadable(), + convert.BytesIEC(memStats.VirtMem.Free), + convert.BytesIEC(memStats.VirtMem.Total), MemFreePercentage) if config.MemFree.Warn.IsSet { pdMemFree.Warn = &config.MemFree.Warn.Th if config.MemFree.Warn.Th.DoesViolate(float64(memStats.VirtMem.Free)) { - _ = partialMemFree.SetState(check.Warning) + partialMemFree.SetState(check.Warning) } } @@ -163,7 +161,7 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa pdMemFree.Crit = &config.MemFree.Crit.Th if config.MemFree.Crit.Th.DoesViolate(float64(memStats.VirtMem.Free)) { - _ = partialMemFree.SetState(check.Critical) + partialMemFree.SetState(check.Critical) } } @@ -171,7 +169,7 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa pdMemFreePercentage.Warn = &config.MemFreePercentage.Warn.Th if config.MemFreePercentage.Warn.Th.DoesViolate(MemFreePercentage) { - _ = partialMemFree.SetState(check.Warning) + partialMemFree.SetState(check.Warning) } } @@ -179,7 +177,7 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa pdMemFreePercentage.Crit = &config.MemFreePercentage.Crit.Th if config.MemFreePercentage.Crit.Th.DoesViolate(MemFreePercentage) { - _ = partialMemFree.SetState(check.Critical) + partialMemFree.SetState(check.Critical) } } @@ -193,20 +191,20 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa if (partialMemFree.GetStatus() > partialMem.GetStatus()) && partialMemFree.GetStatus() != check.Unknown { - _ = partialMem.SetState(partialMemFree.GetStatus()) + partialMem.SetState(partialMemFree.GetStatus()) } // Used Memory - var partialMemUsed result.PartialResult + partialMemUsed := result.NewPartialResult() - _ = partialMemUsed.SetDefaultState(check.OK) + partialMemUsed.SetDefaultState(check.OK) partialMemUsed.Output = fmt.Sprintf("Used Memory (%s/%s, %.2f%%)", - convert.BytesIEC(memStats.VirtMem.Used).HumanReadable(), - convert.BytesIEC(memStats.VirtMem.Total).HumanReadable(), + convert.BytesIEC(memStats.VirtMem.Used), + convert.BytesIEC(memStats.VirtMem.Total), memStats.VirtMem.UsedPercent) - pdMemUsed := perfdata.Perfdata{ + pdMemUsed := check.Perfdata{ Label: "used_memory", Uom: "B", Value: memStats.VirtMem.Used, @@ -215,7 +213,7 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa } MemUsedPercentage := float64(memStats.VirtMem.Used) / (float64(memStats.VirtMem.Total) / 100) - pdMemUsedPercentage := perfdata.Perfdata{ + pdMemUsedPercentage := check.Perfdata{ Label: "used_memory_percentage", Value: MemUsedPercentage, Uom: "%", @@ -225,7 +223,7 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa pdMemUsed.Warn = &config.MemUsed.Warn.Th if config.MemUsed.Warn.Th.DoesViolate(float64(memStats.VirtMem.Used)) { - _ = partialMemUsed.SetState(check.Warning) + partialMemUsed.SetState(check.Warning) } } @@ -233,7 +231,7 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa pdMemUsedPercentage.Warn = &config.MemUsedPercentage.Warn.Th if config.MemUsedPercentage.Warn.Th.DoesViolate(memStats.VirtMem.UsedPercent) { - _ = partialMemUsed.SetState(check.Warning) + partialMemUsed.SetState(check.Warning) } } @@ -241,7 +239,7 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa pdMemUsed.Crit = &config.MemUsed.Crit.Th if config.MemUsed.Crit.Th.DoesViolate(float64(memStats.VirtMem.Used)) { - _ = partialMemUsed.SetState(check.Critical) + partialMemUsed.SetState(check.Critical) } } @@ -249,7 +247,7 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa pdMemUsedPercentage.Crit = &config.MemUsedPercentage.Crit.Th if config.MemUsedPercentage.Crit.Th.DoesViolate(memStats.VirtMem.UsedPercent) { - _ = partialMemUsed.SetState(check.Critical) + partialMemUsed.SetState(check.Critical) } } @@ -263,7 +261,7 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa if (partialMemUsed.GetStatus() > partialMem.GetStatus()) && partialMemUsed.GetStatus() != check.Unknown { - _ = partialMem.SetState(partialMemUsed.GetStatus()) + partialMem.SetState(partialMemUsed.GetStatus()) } return partialMem @@ -414,20 +412,20 @@ func init() { func computeSwapResults(stats *memory.Mem) *result.PartialResult { var partialSwap result.PartialResult - _ = partialSwap.SetDefaultState(check.OK) + partialSwap.SetDefaultState(check.OK) - _ = partialSwap.SetDefaultState(check.OK) + partialSwap.SetDefaultState(check.OK) if stats.VirtMem.SwapTotal == 0 { - _ = partialSwap.SetState(check.Critical) + partialSwap.SetState(check.Critical) partialSwap.Output = "Swap size is 0." return &partialSwap } - partialSwap.Output = fmt.Sprintf("Swap Usage %.2f%% (%s / %s)", stats.SwapInfo.UsedPercent, convert.BytesIEC(stats.SwapInfo.Used).HumanReadable(), convert.BytesIEC(stats.SwapInfo.Total).HumanReadable()) + partialSwap.Output = fmt.Sprintf("Swap Usage %.2f%% (%s / %s)", stats.SwapInfo.UsedPercent, convert.BytesIEC(stats.SwapInfo.Used), convert.BytesIEC(stats.SwapInfo.Total)) - pdSwapUsed := perfdata.Perfdata{ + pdSwapUsed := check.Perfdata{ Label: "swap_used", Value: stats.SwapInfo.Used, Uom: "B", @@ -435,7 +433,7 @@ func computeSwapResults(stats *memory.Mem) *result.PartialResult { Max: stats.SwapInfo.Total, } - pdSwapPrcnt := perfdata.Perfdata{ + pdSwapPrcnt := check.Perfdata{ Label: "swap_usage_percent", Value: stats.SwapInfo.UsedPercent, Uom: "%", @@ -444,13 +442,13 @@ func computeSwapResults(stats *memory.Mem) *result.PartialResult { // Warning if MemoryConfig.SwapFree.Warn.IsSet { if MemoryConfig.SwapFree.Warn.Th.DoesViolate(float64(stats.SwapInfo.Free)) { - _ = partialSwap.SetState(check.Warning) + partialSwap.SetState(check.Warning) } } if MemoryConfig.SwapFreePercentage.Warn.IsSet { if MemoryConfig.SwapFreePercentage.Warn.Th.DoesViolate(1 - stats.SwapInfo.UsedPercent) { - _ = partialSwap.SetState(check.Warning) + partialSwap.SetState(check.Warning) } } @@ -458,7 +456,7 @@ func computeSwapResults(stats *memory.Mem) *result.PartialResult { pdSwapUsed.Warn = &MemoryConfig.SwapUsed.Warn.Th if MemoryConfig.SwapUsed.Warn.Th.DoesViolate(float64(stats.SwapInfo.Used)) { - _ = partialSwap.SetState(check.Warning) + partialSwap.SetState(check.Warning) } } @@ -466,20 +464,20 @@ func computeSwapResults(stats *memory.Mem) *result.PartialResult { pdSwapPrcnt.Warn = &MemoryConfig.SwapUsedPercentage.Warn.Th if MemoryConfig.SwapUsedPercentage.Warn.Th.DoesViolate(stats.SwapInfo.UsedPercent) { - _ = partialSwap.SetState(check.Warning) + partialSwap.SetState(check.Warning) } } // Critical if MemoryConfig.SwapFree.Crit.IsSet { if MemoryConfig.SwapFree.Crit.Th.DoesViolate(float64(stats.SwapInfo.Free)) { - _ = partialSwap.SetState(check.Critical) + partialSwap.SetState(check.Critical) } } if MemoryConfig.SwapFreePercentage.Crit.IsSet { if MemoryConfig.SwapFreePercentage.Crit.Th.DoesViolate(1 - stats.SwapInfo.UsedPercent) { - _ = partialSwap.SetState(check.Critical) + partialSwap.SetState(check.Critical) } } @@ -487,7 +485,7 @@ func computeSwapResults(stats *memory.Mem) *result.PartialResult { pdSwapUsed.Crit = &MemoryConfig.SwapUsed.Crit.Th if MemoryConfig.SwapUsed.Warn.Th.DoesViolate(float64(stats.SwapInfo.Used)) { - _ = partialSwap.SetState(check.Warning) + partialSwap.SetState(check.Warning) } } @@ -495,7 +493,7 @@ func computeSwapResults(stats *memory.Mem) *result.PartialResult { pdSwapPrcnt.Crit = &MemoryConfig.SwapUsedPercentage.Crit.Th if MemoryConfig.SwapUsedPercentage.Crit.Th.DoesViolate(stats.SwapInfo.UsedPercent) { - _ = partialSwap.SetState(check.Critical) + partialSwap.SetState(check.Critical) } } diff --git a/cmd/netdev.go b/cmd/netdev.go index 5e36bc5..c2694bc 100644 --- a/cmd/netdev.go +++ b/cmd/netdev.go @@ -3,7 +3,6 @@ package cmd import ( "github.com/NETWAYS/check_system_basics/internal/netdev" "github.com/NETWAYS/go-check" - "github.com/NETWAYS/go-check/perfdata" "github.com/NETWAYS/go-check/result" "github.com/spf13/cobra" ) @@ -58,34 +57,34 @@ func NetdevCheck(_ *cobra.Command, _ []string) { } for i := range interfaces { - sc := result.PartialResult{} - _ = sc.SetDefaultState(check.OK) + sc := result.NewPartialResult() + sc.SetDefaultState(check.OK) sc.Output = interfaces[i].Name + " is " + netdev.TranslateIfaceState(interfaces[i].Operstate) if !NetdevConfig.NotUpIsOK { switch interfaces[i].Operstate { case netdev.Up: - _ = sc.SetState(check.OK) + sc.SetState(check.OK) case netdev.Down: if NetdevConfig.DownIsCritical { - _ = sc.SetState(check.Critical) + sc.SetState(check.Critical) } else { - _ = sc.SetState(check.Warning) + sc.SetState(check.Warning) } case netdev.Unknown: if NetdevConfig.UnknownIsOk { - _ = sc.SetState(check.OK) + sc.SetState(check.OK) } else { - _ = sc.SetState(check.Warning) + sc.SetState(check.Warning) } default: - _ = sc.SetState(check.Warning) + sc.SetState(check.Warning) } } for j := range interfaces[i].Metrics { - pd := perfdata.Perfdata{} + pd := check.Perfdata{} pd.Label = interfaces[i].Name + "_" + netdev.GetIfaceStatNames()[j] pd.Value = interfaces[i].Metrics[j] @@ -95,5 +94,5 @@ func NetdevCheck(_ *cobra.Command, _ []string) { overall.AddSubcheck(sc) } - check.ExitRaw(overall.GetStatus(), overall.GetOutput()) + check.Exit(overall.GetStatus(), overall.GetOutput()) } diff --git a/cmd/psi.go b/cmd/psi.go index a49372a..499d926 100644 --- a/cmd/psi.go +++ b/cmd/psi.go @@ -163,7 +163,7 @@ var psiCmd = &cobra.Command{ overall.AddSubcheck(checkPsiMemoryPressure(&config)) } - check.ExitRaw(overall.GetStatus(), overall.GetOutput()) + check.Exit(overall.GetStatus(), overall.GetOutput()) }, } @@ -234,16 +234,16 @@ func init() { psiFs.BoolVar(&config.IncludeIO, "include-io", false, "Include IO values explicitly (by default all are included)") } -func checkPsiCPUPressure(config *psiConfig) result.PartialResult { - var cpuCheck result.PartialResult +func checkPsiCPUPressure(config *psiConfig) *result.PartialResult { + cpuCheck := result.NewPartialResult() - _ = cpuCheck.SetDefaultState(check.OK) + cpuCheck.SetDefaultState(check.OK) cpuCheck.Output = "CPU" psiCPU, err := psi.ReadCPUPressure() if err != nil { if errors.Is(err, os.ErrNotExist) { - _ = cpuCheck.SetState(check.Unknown) + cpuCheck.SetState(check.Unknown) cpuCheck.Output = "CPU pressure file not found. Perhaps the PSI interface is not active on this system? It might be necessary to change the kernel config" return cpuCheck @@ -294,19 +294,19 @@ func checkPsiCPUPressure(config *psiConfig) result.PartialResult { cpuCheck.Perfdata[psi.CPUFullAvg300].Crit = &config.CriticalCPUAvg.Th } - cpuFullSc := result.PartialResult{} - _ = cpuFullSc.SetDefaultState(check.OK) + cpuFullSc := result.NewPartialResult() + cpuFullSc.SetDefaultState(check.OK) if cpuCheck.Perfdata[psi.CPUFullAvg10].Warn.DoesViolate(psiCPU.Full.Avg10) || cpuCheck.Perfdata[psi.CPUFullAvg60].Warn.DoesViolate(psiCPU.Full.Avg60) || cpuCheck.Perfdata[psi.CPUFullAvg300].Warn.DoesViolate(psiCPU.Full.Avg300) { - _ = cpuFullSc.SetState(check.Warning) + cpuFullSc.SetState(check.Warning) } if cpuCheck.Perfdata[psi.CPUFullAvg10].Crit.DoesViolate(psiCPU.Full.Avg10) || cpuCheck.Perfdata[psi.CPUFullAvg60].Crit.DoesViolate(psiCPU.Full.Avg60) || cpuCheck.Perfdata[psi.CPUFullAvg300].Crit.DoesViolate(psiCPU.Full.Avg300) { - _ = cpuFullSc.SetState(check.Critical) + cpuFullSc.SetState(check.Critical) } cpuFullSc.Output = fmt.Sprintf("Full - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiCPU.Full.Avg10, psiCPU.Full.Avg60, psiCPU.Full.Avg300) @@ -350,14 +350,14 @@ func checkPsiCPUPressure(config *psiConfig) result.PartialResult { cpuCheck.Perfdata[psi.CPUSomeAvg300].Crit = &config.CriticalCPUAvg.Th } - cpuSomeSc := result.PartialResult{} - _ = cpuSomeSc.SetDefaultState(check.OK) + cpuSomeSc := result.NewPartialResult() + cpuSomeSc.SetDefaultState(check.OK) if (cpuCheck.GetStatus() != check.Critical) && (cpuCheck.GetStatus() != check.Warning) { if cpuCheck.Perfdata[psi.CPUSomeAvg10].Warn.DoesViolate(psiCPU.Some.Avg10) || cpuCheck.Perfdata[psi.CPUSomeAvg60].Warn.DoesViolate(psiCPU.Some.Avg60) || cpuCheck.Perfdata[psi.CPUSomeAvg300].Warn.DoesViolate(psiCPU.Some.Avg300) { - _ = cpuSomeSc.SetState(check.Warning) + cpuSomeSc.SetState(check.Warning) } } @@ -365,7 +365,7 @@ func checkPsiCPUPressure(config *psiConfig) result.PartialResult { if cpuCheck.Perfdata[psi.CPUSomeAvg10].Crit.DoesViolate(psiCPU.Some.Avg10) || cpuCheck.Perfdata[psi.CPUSomeAvg60].Crit.DoesViolate(psiCPU.Some.Avg60) || cpuCheck.Perfdata[psi.CPUSomeAvg300].Crit.DoesViolate(psiCPU.Some.Avg300) { - _ = cpuSomeSc.SetState(check.Critical) + cpuSomeSc.SetState(check.Critical) } } @@ -375,16 +375,16 @@ func checkPsiCPUPressure(config *psiConfig) result.PartialResult { return cpuCheck } -func checkPsiIoPressure(config *psiConfig) result.PartialResult { - var ioCheck result.PartialResult +func checkPsiIoPressure(config *psiConfig) *result.PartialResult { + ioCheck := result.NewPartialResult() - _ = ioCheck.SetDefaultState(check.OK) + ioCheck.SetDefaultState(check.OK) ioCheck.Output = "IO" psiIo, err := psi.ReadIoPressure() if err != nil { if errors.Is(err, os.ErrNotExist) { - _ = ioCheck.SetState(check.Unknown) + ioCheck.SetState(check.Unknown) ioCheck.Output = "IO pressure file not found. Perhaps the PSI interface is not active on this system? It might be necessary to change the kernel config" return ioCheck @@ -435,19 +435,19 @@ func checkPsiIoPressure(config *psiConfig) result.PartialResult { ioCheck.Perfdata[psi.IoFullAvg300].Crit = &config.CriticalIoAvg.Th } - ioFullSc := result.PartialResult{} - _ = ioFullSc.SetDefaultState(check.OK) + ioFullSc := result.NewPartialResult() + ioFullSc.SetDefaultState(check.OK) if ioCheck.Perfdata[psi.IoFullAvg10].Warn.DoesViolate(psiIo.Full.Avg10) || ioCheck.Perfdata[psi.IoFullAvg60].Warn.DoesViolate(psiIo.Full.Avg60) || ioCheck.Perfdata[psi.IoFullAvg300].Warn.DoesViolate(psiIo.Full.Avg300) { - _ = ioFullSc.SetState(check.Warning) + ioFullSc.SetState(check.Warning) } if ioCheck.Perfdata[psi.IoFullAvg10].Crit.DoesViolate(psiIo.Full.Avg10) || ioCheck.Perfdata[psi.IoFullAvg60].Crit.DoesViolate(psiIo.Full.Avg60) || ioCheck.Perfdata[psi.IoFullAvg300].Crit.DoesViolate(psiIo.Full.Avg300) { - _ = ioFullSc.SetState(check.Critical) + ioFullSc.SetState(check.Critical) } ioFullSc.Output = fmt.Sprintf("Full - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiIo.Full.Avg10, psiIo.Full.Avg60, psiIo.Full.Avg300) @@ -490,14 +490,14 @@ func checkPsiIoPressure(config *psiConfig) result.PartialResult { ioCheck.Perfdata[psi.IoSomeAvg300].Crit = &config.CriticalIoAvg.Th } - ioSomeSc := result.PartialResult{} - _ = ioSomeSc.SetDefaultState(check.OK) + ioSomeSc := result.NewPartialResult() + ioSomeSc.SetDefaultState(check.OK) if (ioCheck.GetStatus() != check.Critical) && (ioCheck.GetStatus() != check.Warning) { if ioCheck.Perfdata[psi.IoSomeAvg10].Warn.DoesViolate(psiIo.Some.Avg10) || ioCheck.Perfdata[psi.IoSomeAvg60].Warn.DoesViolate(psiIo.Some.Avg60) || ioCheck.Perfdata[psi.IoSomeAvg300].Warn.DoesViolate(psiIo.Some.Avg300) { - _ = ioSomeSc.SetState(check.Warning) + ioSomeSc.SetState(check.Warning) } } @@ -505,7 +505,7 @@ func checkPsiIoPressure(config *psiConfig) result.PartialResult { if ioCheck.Perfdata[psi.IoSomeAvg10].Crit.DoesViolate(psiIo.Some.Avg10) || ioCheck.Perfdata[psi.IoSomeAvg60].Crit.DoesViolate(psiIo.Some.Avg60) || ioCheck.Perfdata[psi.IoSomeAvg300].Crit.DoesViolate(psiIo.Some.Avg300) { - _ = ioSomeSc.SetState(check.Critical) + ioSomeSc.SetState(check.Critical) } } @@ -515,16 +515,16 @@ func checkPsiIoPressure(config *psiConfig) result.PartialResult { return ioCheck } -func checkPsiMemoryPressure(config *psiConfig) result.PartialResult { - var memoryCheck result.PartialResult +func checkPsiMemoryPressure(config *psiConfig) *result.PartialResult { + memoryCheck := result.NewPartialResult() - _ = memoryCheck.SetDefaultState(check.OK) + memoryCheck.SetDefaultState(check.OK) memoryCheck.Output = "Memory" psiMemory, err := psi.ReadMemoryPressure() if err != nil { if errors.Is(err, os.ErrNotExist) { - _ = memoryCheck.SetState(check.Unknown) + memoryCheck.SetState(check.Unknown) memoryCheck.Output = "IO pressure file not found. Perhaps the PSI interface is not active on this system? It might be necessary to change the kernel config" return memoryCheck @@ -575,19 +575,19 @@ func checkPsiMemoryPressure(config *psiConfig) result.PartialResult { memoryCheck.Perfdata[psi.MemoryFullAvg300].Crit = &config.CriticalMemoryAvg.Th } - memoryFullSc := result.PartialResult{} - _ = memoryFullSc.SetDefaultState(check.OK) + memoryFullSc := result.NewPartialResult() + memoryFullSc.SetDefaultState(check.OK) if memoryCheck.Perfdata[psi.MemoryFullAvg10].Warn.DoesViolate(psiMemory.Full.Avg10) || memoryCheck.Perfdata[psi.MemoryFullAvg60].Warn.DoesViolate(psiMemory.Full.Avg60) || memoryCheck.Perfdata[psi.MemoryFullAvg300].Warn.DoesViolate(psiMemory.Full.Avg300) { - _ = memoryFullSc.SetState(check.Warning) + memoryFullSc.SetState(check.Warning) } if memoryCheck.Perfdata[psi.MemoryFullAvg10].Crit.DoesViolate(psiMemory.Full.Avg10) || memoryCheck.Perfdata[psi.MemoryFullAvg60].Crit.DoesViolate(psiMemory.Full.Avg60) || memoryCheck.Perfdata[psi.MemoryFullAvg300].Crit.DoesViolate(psiMemory.Full.Avg300) { - _ = memoryFullSc.SetState(check.Critical) + memoryFullSc.SetState(check.Critical) } memoryFullSc.Output = fmt.Sprintf("Full - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiMemory.Full.Avg10, psiMemory.Full.Avg60, psiMemory.Full.Avg300) @@ -631,14 +631,14 @@ func checkPsiMemoryPressure(config *psiConfig) result.PartialResult { memoryCheck.Perfdata[psi.MemorySomeAvg300].Crit = &config.CriticalMemoryAvg.Th } - memorySomeSc := result.PartialResult{} - _ = memorySomeSc.SetDefaultState(check.OK) + memorySomeSc := result.NewPartialResult() + memorySomeSc.SetDefaultState(check.OK) if (memoryCheck.GetStatus() != check.Critical) && (memoryCheck.GetStatus() != check.Warning) { if memoryCheck.Perfdata[psi.MemorySomeAvg10].Warn.DoesViolate(psiMemory.Some.Avg10) || memoryCheck.Perfdata[psi.MemorySomeAvg60].Warn.DoesViolate(psiMemory.Some.Avg60) || memoryCheck.Perfdata[psi.MemorySomeAvg300].Warn.DoesViolate(psiMemory.Some.Avg300) { - _ = memorySomeSc.SetState(check.Warning) + memorySomeSc.SetState(check.Warning) } } @@ -646,7 +646,7 @@ func checkPsiMemoryPressure(config *psiConfig) result.PartialResult { if memoryCheck.Perfdata[psi.MemorySomeAvg10].Crit.DoesViolate(psiMemory.Some.Avg10) || memoryCheck.Perfdata[psi.MemorySomeAvg60].Crit.DoesViolate(psiMemory.Some.Avg60) || memoryCheck.Perfdata[psi.MemorySomeAvg300].Crit.DoesViolate(psiMemory.Some.Avg300) { - _ = memorySomeSc.SetState(check.Critical) + memorySomeSc.SetState(check.Critical) } } diff --git a/cmd/root.go b/cmd/root.go index cc58699..284e43b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -67,7 +67,7 @@ func RunFunction(cmd *cobra.Command, args []string) { if dumpConfig { ConfigDump(cmd, cmd.CommandPath()) - os.Exit(check.OK) + os.Exit(0) } Help(cmd, args) @@ -76,7 +76,7 @@ func RunFunction(cmd *cobra.Command, args []string) { func Help(cmd *cobra.Command, _ []string) { _ = cmd.Usage() - os.Exit(check.Unknown) + os.Exit(3) } func ConfigDump(cmd *cobra.Command, executableName string) { diff --git a/cmd/sensors.go b/cmd/sensors.go index 470986d..29816ef 100644 --- a/cmd/sensors.go +++ b/cmd/sensors.go @@ -45,7 +45,7 @@ thresholds respecting the sensor type and the respective specialities`, if len(devices) == 0 { overall.Add(check.Unknown, "No devices found") - check.ExitRaw(overall.GetStatus(), overall.GetOutput()) + check.Exit(overall.GetStatus(), overall.GetOutput()) } var ( @@ -53,24 +53,24 @@ thresholds respecting the sensor type and the respective specialities`, ) for _, device := range devices { - var devicePartial result.PartialResult + devicePartial := result.NewPartialResult() - _ = devicePartial.SetDefaultState(check.OK) + devicePartial.SetDefaultState(check.OK) devicePartial.Output = device.Name for idx, sensor := range device.Sensors { - var ssc result.PartialResult + ssc := result.NewPartialResult() - _ = ssc.SetDefaultState(check.OK) + ssc.SetDefaultState(check.OK) ssc.Perfdata.Add(&(device.Sensors[idx]).Perfdata) if sensor.Alarm { ssc.Output = "Alarm!" - _ = ssc.SetState(check.Critical) + ssc.SetState(check.Critical) alarms++ } else { ssc.Output = "Ok" - _ = ssc.SetState(check.OK) + ssc.SetState(check.OK) } // Add perfdata label (sensor name) to ouptput to make it more descriptive @@ -84,7 +84,7 @@ thresholds respecting the sensor type and the respective specialities`, overall.AddSubcheck(devicePartial) } - check.ExitRaw(overall.GetStatus(), overall.GetOutput()) + check.Exit(overall.GetStatus(), overall.GetOutput()) }, } diff --git a/go.mod b/go.mod index 6acd313..c496062 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/NETWAYS/check_system_basics go 1.25.0 require ( - github.com/NETWAYS/go-check v0.6.4 + github.com/NETWAYS/go-check v1.0.0-rc4 github.com/NETWAYS/go-icingadsl v0.1.2 github.com/shirou/gopsutil/v3 v3.24.5 github.com/spf13/cobra v1.10.2 diff --git a/go.sum b/go.sum index 17d8a2d..927e99b 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/NETWAYS/go-check v0.6.4 h1:4WETSVNZNEP0Yudcp5xlvxq6RGn920cmUKq4fz/P1GQ= github.com/NETWAYS/go-check v0.6.4/go.mod h1:8/GWnq8SirreAixgRmcp82JG16NnEl38rHq9phICy9s= +github.com/NETWAYS/go-check v1.0.0-rc4 h1:L+yS7wklUz/eUzkGndSKpi3DqCXmCAOSEQtBWkxF+7k= +github.com/NETWAYS/go-check v1.0.0-rc4/go.mod h1:8/GWnq8SirreAixgRmcp82JG16NnEl38rHq9phICy9s= github.com/NETWAYS/go-icingadsl v0.1.2 h1:F25Y7HAw9VF8GC4eJFbhXzA4TBUwA/0R/n2vbTz6qsQ= github.com/NETWAYS/go-icingadsl v0.1.2/go.mod h1:CE74xcjOUHxYpltsooRTimANss5H2VZHFlme5138Cqw= github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= diff --git a/internal/load/load.go b/internal/load/load.go index b40e29a..ec555b2 100644 --- a/internal/load/load.go +++ b/internal/load/load.go @@ -3,7 +3,7 @@ package load import ( "fmt" - "github.com/NETWAYS/go-check/perfdata" + "github.com/NETWAYS/go-check" "github.com/shirou/gopsutil/v3/load" ) @@ -34,8 +34,8 @@ func (l *Load) GetOutput() (output string) { return output } -func (l *Load) GetPerfData() perfdata.PerfdataList { - perfList := perfdata.PerfdataList{ +func (l *Load) GetPerfData() check.PerfdataList { + perfList := check.PerfdataList{ { Label: "load1", Value: l.LoadAvg.Load1, diff --git a/internal/psi/psi.go b/internal/psi/psi.go index 64fcd28..43a594f 100644 --- a/internal/psi/psi.go +++ b/internal/psi/psi.go @@ -6,7 +6,7 @@ import ( "strconv" "strings" - "github.com/NETWAYS/go-check/perfdata" + "github.com/NETWAYS/go-check" ) const ( @@ -64,10 +64,10 @@ const ( io ) -func (p *PressureValue) Perfdata(prefix string) *perfdata.PerfdataList { - var ret perfdata.PerfdataList +func (p *PressureValue) Perfdata(prefix string) *check.PerfdataList { + var ret check.PerfdataList - avg10 := perfdata.Perfdata{} + avg10 := check.Perfdata{} avg10.Label = prefix + "avg10" avg10.Value = p.Avg10 avg10.Uom = "%" @@ -75,7 +75,7 @@ func (p *PressureValue) Perfdata(prefix string) *perfdata.PerfdataList { avg10.Max = 100 ret.Add(&avg10) - avg60 := perfdata.Perfdata{} + avg60 := check.Perfdata{} avg60.Label = prefix + "avg60" avg60.Value = p.Avg60 avg60.Uom = "%" @@ -83,7 +83,7 @@ func (p *PressureValue) Perfdata(prefix string) *perfdata.PerfdataList { avg60.Max = 100 ret.Add(&avg60) - avg300 := perfdata.Perfdata{} + avg300 := check.Perfdata{} avg300.Label = prefix + "avg300" avg300.Value = p.Avg300 avg300.Uom = "%" @@ -91,7 +91,7 @@ func (p *PressureValue) Perfdata(prefix string) *perfdata.PerfdataList { avg300.Max = 100 ret.Add(&avg300) - total := perfdata.Perfdata{} + total := check.Perfdata{} total.Label = prefix + "total" total.Value = p.Total total.Min = 0 @@ -101,7 +101,7 @@ func (p *PressureValue) Perfdata(prefix string) *perfdata.PerfdataList { return &ret } -func (p *PressureElement) Perfdata() *perfdata.PerfdataList { +func (p *PressureElement) Perfdata() *check.PerfdataList { switch p.Type { case cpu: tmp := *p.Some.Perfdata("cpu-some-") diff --git a/internal/psi/psi_test.go b/internal/psi/psi_test.go index 671c188..5a01a5c 100644 --- a/internal/psi/psi_test.go +++ b/internal/psi/psi_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/NETWAYS/go-check/perfdata" + "github.com/NETWAYS/go-check" ) func TestPressureValueString(t *testing.T) { @@ -15,11 +15,11 @@ func TestPressureValueString(t *testing.T) { } // Expected - expected := perfdata.PerfdataList{} - expected.Add(&perfdata.Perfdata{Label: "preavg10", Value: 1.5, Min: 0, Max: 100, Uom: "%"}) - expected.Add(&perfdata.Perfdata{Label: "preavg60", Value: 2.5, Min: 0, Max: 100, Uom: "%"}) - expected.Add(&perfdata.Perfdata{Label: "preavg300", Value: 3.5, Min: 0, Max: 100, Uom: "%"}) - expected.Add(&perfdata.Perfdata{Label: "pretotal", Value: uint64(0), Min: 0, Uom: "c"}) + expected := check.PerfdataList{} + expected.Add(&check.Perfdata{Label: "preavg10", Value: 1.5, Min: 0, Max: 100, Uom: "%"}) + expected.Add(&check.Perfdata{Label: "preavg60", Value: 2.5, Min: 0, Max: 100, Uom: "%"}) + expected.Add(&check.Perfdata{Label: "preavg300", Value: 3.5, Min: 0, Max: 100, Uom: "%"}) + expected.Add(&check.Perfdata{Label: "pretotal", Value: uint64(0), Min: 0, Uom: "c"}) if !reflect.DeepEqual(&expected, pv.Perfdata("pre")) { t.Fatalf("expected %v, got %v", &expected, pv.Perfdata("pre")) @@ -35,15 +35,15 @@ func TestPressureElementString(t *testing.T) { } // Expected - pecpuexpected := perfdata.PerfdataList{} - pecpuexpected.Add(&perfdata.Perfdata{Label: "cpu-some-avg10", Value: float64(0.1), Min: 0, Max: 100, Uom: "%"}) - pecpuexpected.Add(&perfdata.Perfdata{Label: "cpu-some-avg60", Value: float64(0.6), Min: 0, Max: 100, Uom: "%"}) - pecpuexpected.Add(&perfdata.Perfdata{Label: "cpu-some-avg300", Value: float64(0.3), Min: 0, Max: 100, Uom: "%"}) - pecpuexpected.Add(&perfdata.Perfdata{Label: "cpu-some-total", Value: uint64(0), Min: 0, Uom: "c"}) - pecpuexpected.Add(&perfdata.Perfdata{Label: "cpu-full-avg10", Value: float64(0.1), Min: 0, Max: 100, Uom: "%"}) - pecpuexpected.Add(&perfdata.Perfdata{Label: "cpu-full-avg60", Value: float64(0.6), Min: 0, Max: 100, Uom: "%"}) - pecpuexpected.Add(&perfdata.Perfdata{Label: "cpu-full-avg300", Value: float64(0.3), Min: 0, Max: 100, Uom: "%"}) - pecpuexpected.Add(&perfdata.Perfdata{Label: "cpu-full-total", Value: uint64(0), Min: 0, Uom: "c"}) + pecpuexpected := check.PerfdataList{} + pecpuexpected.Add(&check.Perfdata{Label: "cpu-some-avg10", Value: float64(0.1), Min: 0, Max: 100, Uom: "%"}) + pecpuexpected.Add(&check.Perfdata{Label: "cpu-some-avg60", Value: float64(0.6), Min: 0, Max: 100, Uom: "%"}) + pecpuexpected.Add(&check.Perfdata{Label: "cpu-some-avg300", Value: float64(0.3), Min: 0, Max: 100, Uom: "%"}) + pecpuexpected.Add(&check.Perfdata{Label: "cpu-some-total", Value: uint64(0), Min: 0, Uom: "c"}) + pecpuexpected.Add(&check.Perfdata{Label: "cpu-full-avg10", Value: float64(0.1), Min: 0, Max: 100, Uom: "%"}) + pecpuexpected.Add(&check.Perfdata{Label: "cpu-full-avg60", Value: float64(0.6), Min: 0, Max: 100, Uom: "%"}) + pecpuexpected.Add(&check.Perfdata{Label: "cpu-full-avg300", Value: float64(0.3), Min: 0, Max: 100, Uom: "%"}) + pecpuexpected.Add(&check.Perfdata{Label: "cpu-full-total", Value: uint64(0), Min: 0, Uom: "c"}) if !reflect.DeepEqual(&pecpuexpected, pecpu.Perfdata()) { t.Fatalf("expected %v, got %v", &pecpuexpected, pecpu.Perfdata()) @@ -57,11 +57,11 @@ func TestPressureElementString(t *testing.T) { } // Expected - peioexpected := perfdata.PerfdataList{} - peioexpected.Add(&perfdata.Perfdata{Label: "io-some-avg10", Value: float64(0.1), Min: 0, Max: 100, Uom: "%"}) - peioexpected.Add(&perfdata.Perfdata{Label: "io-some-avg60", Value: float64(0.6), Min: 0, Max: 100, Uom: "%"}) - peioexpected.Add(&perfdata.Perfdata{Label: "io-some-avg300", Value: float64(0.3), Min: 0, Max: 100, Uom: "%"}) - peioexpected.Add(&perfdata.Perfdata{Label: "io-some-total", Value: uint64(0), Min: 0, Uom: "c"}) + peioexpected := check.PerfdataList{} + peioexpected.Add(&check.Perfdata{Label: "io-some-avg10", Value: float64(0.1), Min: 0, Max: 100, Uom: "%"}) + peioexpected.Add(&check.Perfdata{Label: "io-some-avg60", Value: float64(0.6), Min: 0, Max: 100, Uom: "%"}) + peioexpected.Add(&check.Perfdata{Label: "io-some-avg300", Value: float64(0.3), Min: 0, Max: 100, Uom: "%"}) + peioexpected.Add(&check.Perfdata{Label: "io-some-total", Value: uint64(0), Min: 0, Uom: "c"}) if !reflect.DeepEqual(&peioexpected, peio.Perfdata()) { t.Fatalf("expected %v, got %v", &peioexpected, peio.Perfdata()) diff --git a/internal/sensors/sensors.go b/internal/sensors/sensors.go index e76d5f2..947bc43 100644 --- a/internal/sensors/sensors.go +++ b/internal/sensors/sensors.go @@ -9,7 +9,6 @@ import ( "strings" "github.com/NETWAYS/go-check" - "github.com/NETWAYS/go-check/perfdata" ) /* @@ -21,7 +20,7 @@ type Sensor struct { Name string Path string Alarm bool - Perfdata perfdata.Perfdata + Perfdata check.Perfdata } type Device struct { diff --git a/internal/sensors/sensors_test.go b/internal/sensors/sensors_test.go index 8c7d1bc..eb3f2f7 100644 --- a/internal/sensors/sensors_test.go +++ b/internal/sensors/sensors_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/NETWAYS/go-check" - "github.com/NETWAYS/go-check/perfdata" ) func TestSensorAndDeviceString(t *testing.T) { @@ -12,7 +11,7 @@ func TestSensorAndDeviceString(t *testing.T) { Name: "testname", Path: "testpath", Alarm: false, - Perfdata: perfdata.Perfdata{ + Perfdata: check.Perfdata{ Label: "test", Value: 10.0, Uom: "%", From acaeff91927d3f93b7cf7766c6ec57a2f7490626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Wed, 24 Jun 2026 17:24:37 +0200 Subject: [PATCH 2/3] Linter spacing fixes --- cmd/load.go | 6 ++++++ cmd/sensors.go | 1 + 2 files changed, 7 insertions(+) diff --git a/cmd/load.go b/cmd/load.go index d2e4813..9b3cddf 100644 --- a/cmd/load.go +++ b/cmd/load.go @@ -66,12 +66,14 @@ var loadCmd = &cobra.Command{ tmpPerfdata.Crit = &LoadConfig.Load1Th.Crit.Th if LoadConfig.Load1Th.Crit.Th.DoesViolate(loadStats.LoadAvg.Load1) { partialLoad1.SetState(check.Critical) + tmpOutput += critThresMsg } } else if LoadConfig.Load1Th.Warn.IsSet { tmpPerfdata.Warn = &LoadConfig.Load1Th.Warn.Th if LoadConfig.Load1Th.Warn.Th.DoesViolate(loadStats.LoadAvg.Load1) { partialLoad1.SetState(check.Warning) + tmpOutput += warnThresMsg } } else { @@ -102,12 +104,14 @@ var loadCmd = &cobra.Command{ tmpPerfdata.Crit = &LoadConfig.Load5Th.Crit.Th if LoadConfig.Load5Th.Crit.Th.DoesViolate(loadStats.LoadAvg.Load5) { partialLoad5.SetState(check.Critical) + tmpOutput += critThresMsg } } else if LoadConfig.Load5Th.Warn.IsSet { tmpPerfdata.Warn = &LoadConfig.Load5Th.Warn.Th if LoadConfig.Load5Th.Warn.Th.DoesViolate(loadStats.LoadAvg.Load5) { partialLoad5.SetState(check.Warning) + tmpOutput += warnThresMsg } } else { @@ -138,12 +142,14 @@ var loadCmd = &cobra.Command{ tmpPerfdata.Crit = &LoadConfig.Load15Th.Crit.Th if LoadConfig.Load15Th.Crit.Th.DoesViolate(loadStats.LoadAvg.Load15) { partialLoad15.SetState(check.Critical) + tmpOutput += critThresMsg } } else if LoadConfig.Load15Th.Warn.IsSet { tmpPerfdata.Warn = &LoadConfig.Load15Th.Warn.Th if LoadConfig.Load15Th.Warn.Th.DoesViolate(loadStats.LoadAvg.Load15) { partialLoad15.SetState(check.Warning) + tmpOutput += warnThresMsg } } else { diff --git a/cmd/sensors.go b/cmd/sensors.go index 29816ef..13ce9fb 100644 --- a/cmd/sensors.go +++ b/cmd/sensors.go @@ -67,6 +67,7 @@ thresholds respecting the sensor type and the respective specialities`, if sensor.Alarm { ssc.Output = "Alarm!" ssc.SetState(check.Critical) + alarms++ } else { ssc.Output = "Ok" From 7221d2a64e4c125dd40e4416e80d75b59ba905d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Wed, 24 Jun 2026 17:25:10 +0200 Subject: [PATCH 3/3] Improve some option descriptions --- cmd/memory.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cmd/memory.go b/cmd/memory.go index e007b58..e89b5d1 100644 --- a/cmd/memory.go +++ b/cmd/memory.go @@ -288,7 +288,7 @@ func init() { { Th: &MemoryConfig.MemFreePercentage.Crit, FlagString: "memory-free-critical-percentage", - Description: "Critical threshold for free memory", + Description: "Critical threshold for free memory (percentage)", }, { Th: &MemoryConfig.MemUsed.Warn, @@ -303,12 +303,12 @@ func init() { { Th: &MemoryConfig.MemUsedPercentage.Warn, FlagString: "memory-used-warning-percentage", - Description: "Warning threshold for used memory", + Description: "Warning threshold for used memory (percentage)", }, { Th: &MemoryConfig.MemUsedPercentage.Crit, FlagString: "memory-used-critical-percentage", - Description: "Critical threshold for used memory", + Description: "Critical threshold for used memory (percentage)", }, { Th: &MemoryConfig.MemAvailable.Warn, @@ -323,7 +323,7 @@ func init() { { Th: &MemoryConfig.MemAvailablePercentage.Warn, FlagString: "memory-available-warning-percentage", - Description: "Warning threshold for available memory", + Description: "Warning threshold for available memory (percentage)", Default: thresholds.ThresholdWrapper{ IsSet: true, Th: check.Threshold{ @@ -335,7 +335,7 @@ func init() { { Th: &MemoryConfig.MemAvailablePercentage.Crit, FlagString: "memory-available-critical-percentage", - Description: "Critical threshold for available memory", + Description: "Critical threshold for available memory (percentage)", Default: thresholds.ThresholdWrapper{ IsSet: true, Th: check.Threshold{ @@ -347,38 +347,38 @@ func init() { { Th: &MemoryConfig.SwapFree.Warn, FlagString: "swap-free-warning", - Description: "Warning threshold for free memory", + Description: "Warning threshold for free swap memory", }, { Th: &MemoryConfig.SwapFree.Crit, FlagString: "swap-free-critical", - Description: "Critical threshold for free memory", + Description: "Critical threshold for free swap memory", }, { Th: &MemoryConfig.SwapFreePercentage.Warn, FlagString: "swap-free-warning-percentage", - Description: "Warning threshold for free memory", + Description: "Warning threshold for free swap memory (percentage)", }, { Th: &MemoryConfig.SwapFreePercentage.Crit, FlagString: "swap-free-critical-percentage", - Description: "Critical threshold for free memory", + Description: "Critical threshold for free swap memory (percentage)", }, { Th: &MemoryConfig.SwapUsed.Warn, FlagString: "swap-used-warning", - Description: "Warning threshold for used memory", + Description: "Warning threshold for used swap memory", }, { Th: &MemoryConfig.SwapUsed.Crit, FlagString: "swap-used-critical", - Description: "Critical threshold for used memory", + Description: "Critical threshold for used swap memory", }, { Th: &MemoryConfig.SwapUsedPercentage.Warn, FlagString: "swap-used-warning-percentage", - Description: "Warning threshold for used memory", + Description: "Warning threshold for used swap memory (percentage)", Default: thresholds.ThresholdWrapper{ IsSet: true, Th: check.Threshold{ @@ -390,7 +390,7 @@ func init() { { Th: &MemoryConfig.SwapUsedPercentage.Crit, FlagString: "swap-used-critical-percentage", - Description: "Critical threshold for used memory", + Description: "Critical threshold for used swap memory (percentage)", Default: thresholds.ThresholdWrapper{ IsSet: true, Th: check.Threshold{