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/5] 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/5] 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/5] 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{ From db1a242b78d0c9ffe52fbdc3bf0ede4dafe80ac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Tue, 30 Jun 2026 13:41:22 +0200 Subject: [PATCH 4/5] Migrate to go-check 1.0.0 --- cmd/filesystem.go | 112 ++++++++++---------- cmd/load.go | 12 +-- cmd/memory.go | 34 +++--- cmd/netdev.go | 4 +- cmd/psi.go | 258 ++++++++++++++++++++++++---------------------- cmd/sensors.go | 18 ++-- go.mod | 2 +- go.sum | 2 + 8 files changed, 232 insertions(+), 210 deletions(-) diff --git a/cmd/filesystem.go b/cmd/filesystem.go index 1007e07..71c3322 100644 --- a/cmd/filesystem.go +++ b/cmd/filesystem.go @@ -111,27 +111,32 @@ var diskCmd = &cobra.Command{ countResult := result.NewPartialResult() countResult.SetDefaultState(check.OK) + tmpOutput := "" if len(filesystemList) == 1 { - countResult.Output = "Found one matching filesystem" + tmpOutput = "Found one matching filesystem" } else { - countResult.Output = "Found " + strconv.Itoa(len(filesystemList)) + " matching filesystems" + tmpOutput = "Found " + strconv.Itoa(len(filesystemList)) + " matching filesystems" } if FsConfig.CriticalTotalCountOfFs.IsSet && FsConfig.CriticalTotalCountOfFs.Th.DoesViolate(float64(len(filesystemList))) { countResult.SetState(check.Critical) - countResult.Output += ". This violates the threshold of " + FsConfig.CriticalTotalCountOfFs.String() + + tmpOutput += ". 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.Output += ". This violates the threshold of " + FsConfig.WarningTotalCountOfFs.String() + + tmpOutput += ". This violates the threshold of " + FsConfig.WarningTotalCountOfFs.String() } else { - countResult.Output += ". This number resides within the given thresholds" + tmpOutput += ". This number resides within the given thresholds" } + countResult.SetOutput(tmpOutput) + overall.AddSubcheck(countResult) } else if len(filesystemList) == 0 { nullResult := result.NewPartialResult() nullResult.SetState(check.OK) - nullResult.Output = "No filesystems remaining after applying filter expressions. Therefore all are OK" + nullResult.SetOutput("No filesystems remaining after applying filter expressions. Therefore all are OK") overall.AddSubcheck(nullResult) check.Exit(overall.GetStatus(), overall.GetOutput()) } @@ -150,7 +155,7 @@ var diskCmd = &cobra.Command{ sc := computeFsCheckResult(&filesystemList[index], &FsConfig) 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) + sc.SetOutput(fmt.Sprintf("%s (%.2f%% used space, %.2f%% free inodes)", filesystemList[index].PartStats.Mountpoint, filesystemList[index].UsageStats.UsedPercent, 100-filesystemList[index].UsageStats.InodesUsedPercent)) } overall.AddSubcheck(sc) @@ -162,9 +167,8 @@ var diskCmd = &cobra.Command{ } func computeFsCheckResultInodes(fs *filesystem.FilesystemType, config *filesystem.CheckConfig) *result.PartialResult { - returnResult := result.PartialResult{ - Output: "Inodes", - } + returnResult := result.NewPartialResult() + returnResult.SetOutput("Inodes") returnResult.SetDefaultState(check.OK) // One Perfdata point here with inodes free, warn, crit, total @@ -185,7 +189,7 @@ func computeFsCheckResultInodes(fs *filesystem.FilesystemType, config *filesyste if config.WarningAbsolutThreshold.Inodes.Free.Th.DoesViolate(float64(fs.UsageStats.InodesFree)) { tmpPartialResult.SetState(check.Warning) - tmpPartialResult.Output = fmt.Sprintf("Absolute free inode number violates threshold: %d / %d", fs.UsageStats.InodesFree, fs.UsageStats.InodesTotal) + tmpPartialResult.SetOutput(fmt.Sprintf("Absolute free inode number violates threshold: %d / %d", fs.UsageStats.InodesFree, fs.UsageStats.InodesTotal)) } } @@ -194,18 +198,18 @@ func computeFsCheckResultInodes(fs *filesystem.FilesystemType, config *filesyste if config.CriticalAbsolutThreshold.Inodes.Free.Th.DoesViolate(float64(fs.UsageStats.InodesFree)) { tmpPartialResult.SetState(check.Critical) - tmpPartialResult.Output = fmt.Sprintf("Absolute free inode number violates threshold: %d / %d", fs.UsageStats.InodesFree, fs.UsageStats.InodesTotal) + tmpPartialResult.SetOutput(fmt.Sprintf("Absolute free inode number violates threshold: %d / %d", fs.UsageStats.InodesFree, fs.UsageStats.InodesTotal)) } } if tmpPartialResult.GetStatus() == check.OK { - tmpPartialResult.Output = fmt.Sprintf("Absolute number of free inodes: %d / %d", fs.UsageStats.InodesFree, fs.UsageStats.InodesTotal) + tmpPartialResult.SetOutput(fmt.Sprintf("Absolute number of free inodes: %d / %d", fs.UsageStats.InodesFree, fs.UsageStats.InodesTotal)) } - tmpPartialResult.Perfdata.Add(&pdAbsoluteFreeInodes) + tmpPartialResult.AddPerfdata(&pdAbsoluteFreeInodes) returnResult.AddSubcheck(tmpPartialResult) } else { - returnResult.Perfdata.Add(&pdAbsoluteFreeInodes) + returnResult.AddPerfdata(&pdAbsoluteFreeInodes) } // One Perfdata point here with inodes used, warn, crit, total @@ -226,7 +230,7 @@ func computeFsCheckResultInodes(fs *filesystem.FilesystemType, config *filesyste if config.WarningAbsolutThreshold.Inodes.Used.Th.DoesViolate(float64(fs.UsageStats.InodesUsed)) { tmpPartialResult.SetState(check.Warning) - tmpPartialResult.Output = fmt.Sprintf("Absolute used inode number violates threshold: %d / %d", fs.UsageStats.InodesUsed, fs.UsageStats.InodesTotal) + tmpPartialResult.SetOutput(fmt.Sprintf("Absolute used inode number violates threshold: %d / %d", fs.UsageStats.InodesUsed, fs.UsageStats.InodesTotal)) } } @@ -235,18 +239,18 @@ func computeFsCheckResultInodes(fs *filesystem.FilesystemType, config *filesyste if config.CriticalAbsolutThreshold.Inodes.Used.Th.DoesViolate(float64(fs.UsageStats.InodesUsed)) { tmpPartialResult.SetState(check.Critical) - tmpPartialResult.Output = fmt.Sprintf("Absolute used inode number violates threshold: %d / %d", fs.UsageStats.InodesUsed, fs.UsageStats.InodesTotal) + tmpPartialResult.SetOutput(fmt.Sprintf("Absolute used inode number violates threshold: %d / %d", fs.UsageStats.InodesUsed, fs.UsageStats.InodesTotal)) } } if tmpPartialResult.GetStatus() == check.OK { - tmpPartialResult.Output = fmt.Sprintf("Absolute number of used inodes: %d / %d", fs.UsageStats.InodesUsed, fs.UsageStats.InodesTotal) + tmpPartialResult.SetOutput(fmt.Sprintf("Absolute number of used inodes: %d / %d", fs.UsageStats.InodesUsed, fs.UsageStats.InodesTotal)) } - tmpPartialResult.Perfdata.Add(&pdAbsoluteUsedInodes) + tmpPartialResult.AddPerfdata(&pdAbsoluteUsedInodes) returnResult.AddSubcheck(tmpPartialResult) } else { - returnResult.Perfdata.Add(&pdAbsoluteUsedInodes) + returnResult.AddPerfdata(&pdAbsoluteUsedInodes) } // One Perfdata point here with inodes free, warn, crit, total @@ -265,7 +269,7 @@ func computeFsCheckResultInodes(fs *filesystem.FilesystemType, config *filesyste if config.WarningPercentThreshold.Inodes.Free.Th.DoesViolate(pdPercentageFreeInodes.Value.(float64)) { tmpPartialResult.SetState(check.Warning) - tmpPartialResult.Output = fmt.Sprintf("Percentage of free inodes violates threshold: %.2f%%", pdPercentageFreeInodes.Value) + tmpPartialResult.SetOutput(fmt.Sprintf("Percentage of free inodes violates threshold: %.2f%%", pdPercentageFreeInodes.Value)) } } @@ -274,18 +278,18 @@ func computeFsCheckResultInodes(fs *filesystem.FilesystemType, config *filesyste if config.CriticalPercentThreshold.Inodes.Free.Th.DoesViolate(pdPercentageFreeInodes.Value.(float64)) { tmpPartialResult.SetState(check.Critical) - tmpPartialResult.Output = fmt.Sprintf("Percentage of free inodes violates threshold: %.2f%%", pdPercentageFreeInodes.Value) + tmpPartialResult.SetOutput(fmt.Sprintf("Percentage of free inodes violates threshold: %.2f%%", pdPercentageFreeInodes.Value)) } } if tmpPartialResult.GetStatus() == check.OK { - tmpPartialResult.Output = fmt.Sprintf("Percentage of free inodes: %.2f%%", pdPercentageFreeInodes.Value) + tmpPartialResult.SetOutput(fmt.Sprintf("Percentage of free inodes: %.2f%%", pdPercentageFreeInodes.Value)) } - tmpPartialResult.Perfdata.Add(&pdPercentageFreeInodes) + tmpPartialResult.AddPerfdata(&pdPercentageFreeInodes) returnResult.AddSubcheck(tmpPartialResult) } else { - returnResult.Perfdata.Add(&pdPercentageFreeInodes) + returnResult.AddPerfdata(&pdPercentageFreeInodes) } // One Perfdata point here with inodes used, warn, crit, total @@ -304,7 +308,7 @@ func computeFsCheckResultInodes(fs *filesystem.FilesystemType, config *filesyste if config.WarningPercentThreshold.Inodes.Used.Th.DoesViolate(fs.UsageStats.InodesUsedPercent) { tmpPartialResult.SetState(check.Warning) - tmpPartialResult.Output = fmt.Sprintf("Percentage of used inodes violates threshold: %.2f%%", fs.UsageStats.InodesUsedPercent) + tmpPartialResult.SetOutput(fmt.Sprintf("Percentage of used inodes violates threshold: %.2f%%", fs.UsageStats.InodesUsedPercent)) } } @@ -313,26 +317,26 @@ func computeFsCheckResultInodes(fs *filesystem.FilesystemType, config *filesyste if config.CriticalPercentThreshold.Inodes.Used.Th.DoesViolate(fs.UsageStats.InodesUsedPercent) { tmpPartialResult.SetState(check.Critical) - tmpPartialResult.Output = fmt.Sprintf("Percentage of used inodes violates threshold: %.2f%%", fs.UsageStats.InodesUsedPercent) + tmpPartialResult.SetOutput(fmt.Sprintf("Percentage of used inodes violates threshold: %.2f%%", fs.UsageStats.InodesUsedPercent)) } } if tmpPartialResult.GetStatus() == check.OK { - tmpPartialResult.Output = fmt.Sprintf("Percentage of used inodes: %.2f%%", fs.UsageStats.InodesUsedPercent) + tmpPartialResult.SetOutput(fmt.Sprintf("Percentage of used inodes: %.2f%%", fs.UsageStats.InodesUsedPercent)) } - tmpPartialResult.Perfdata.Add(&pdPercentageUsedInodes) + tmpPartialResult.AddPerfdata(&pdPercentageUsedInodes) returnResult.AddSubcheck(tmpPartialResult) } else { - returnResult.Perfdata.Add(&pdPercentageUsedInodes) + returnResult.AddPerfdata(&pdPercentageUsedInodes) } - return &returnResult + return returnResult } func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem.CheckConfig) *result.PartialResult { returnResult := result.NewPartialResult() - returnResult.Output = "Space usage" + returnResult.SetOutput("Space usage") returnResult.SetDefaultState(check.OK) // Absolute numbers @@ -354,7 +358,7 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem 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), convert.BytesIEC(fs.UsageStats.Total)) + tmpPartialResult.SetOutput(fmt.Sprintf("Absolute free space violates threshold: %s / %s", convert.BytesIEC(fs.UsageStats.Free), convert.BytesIEC(fs.UsageStats.Total))) } } @@ -363,18 +367,18 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem 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), convert.BytesIEC(fs.UsageStats.Total)) + tmpPartialResult.SetOutput(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), convert.BytesIEC(fs.UsageStats.Total)) + tmpPartialResult.SetOutput(fmt.Sprintf("Absolute free space: %s / %s", convert.BytesIEC(fs.UsageStats.Free), convert.BytesIEC(fs.UsageStats.Total))) } - tmpPartialResult.Perfdata.Add(&pdAbsoluteFreeSpace) + tmpPartialResult.AddPerfdata(&pdAbsoluteFreeSpace) returnResult.AddSubcheck(tmpPartialResult) } else { - returnResult.Perfdata.Add(&pdAbsoluteFreeSpace) + returnResult.AddPerfdata(&pdAbsoluteFreeSpace) } // One Perfdata point here with bytes used, warn, crit, total @@ -395,7 +399,7 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem 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), convert.BytesIEC(fs.UsageStats.Total)) + tmpPartialResult.SetOutput(fmt.Sprintf("Absolute used space violates threshold: %s / %s", convert.BytesIEC(fs.UsageStats.Used), convert.BytesIEC(fs.UsageStats.Total))) } } @@ -404,18 +408,18 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem 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), convert.BytesIEC(fs.UsageStats.Total)) + tmpPartialResult.SetOutput(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), convert.BytesIEC(fs.UsageStats.Total)) + tmpPartialResult.SetOutput(fmt.Sprintf("Absolute used space: %s / %s", convert.BytesIEC(fs.UsageStats.Used), convert.BytesIEC(fs.UsageStats.Total))) } - tmpPartialResult.Perfdata.Add(&pdAbsoluteUsedSpace) + tmpPartialResult.AddPerfdata(&pdAbsoluteUsedSpace) returnResult.AddSubcheck(tmpPartialResult) } else { - returnResult.Perfdata.Add(&pdAbsoluteUsedSpace) + returnResult.AddPerfdata(&pdAbsoluteUsedSpace) } // Percentage numbers @@ -437,7 +441,7 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem if config.WarningPercentThreshold.Space.Free.Th.DoesViolate(pdPercentageFreeSpace.Value.(float64)) { tmpPartialResult.SetState(check.Warning) - tmpPartialResult.Output = fmt.Sprintf("Percentage of free space violates threshold: %.2f%%", pdPercentageFreeSpace.Value) + tmpPartialResult.SetOutput(fmt.Sprintf("Percentage of free space violates threshold: %.2f%%", pdPercentageFreeSpace.Value)) } } @@ -446,18 +450,18 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem if config.CriticalPercentThreshold.Space.Free.Th.DoesViolate(pdPercentageFreeSpace.Value.(float64)) { tmpPartialResult.SetState(check.Critical) - tmpPartialResult.Output = fmt.Sprintf("Percentage of free space violates threshold: %.2f%%", pdPercentageFreeSpace.Value) + tmpPartialResult.SetOutput(fmt.Sprintf("Percentage of free space violates threshold: %.2f%%", pdPercentageFreeSpace.Value)) } } if tmpPartialResult.GetStatus() == check.OK { - tmpPartialResult.Output = fmt.Sprintf("Percentage of free space: %.2f%%", pdPercentageFreeSpace.Value) + tmpPartialResult.SetOutput(fmt.Sprintf("Percentage of free space: %.2f%%", pdPercentageFreeSpace.Value)) } - tmpPartialResult.Perfdata.Add(&pdPercentageFreeSpace) + tmpPartialResult.AddPerfdata(&pdPercentageFreeSpace) returnResult.AddSubcheck(tmpPartialResult) } else { - returnResult.Perfdata.Add(&pdPercentageFreeSpace) + returnResult.AddPerfdata(&pdPercentageFreeSpace) } // One Perfdata point here with bytes used, warn, crit, total @@ -476,7 +480,7 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem if config.WarningPercentThreshold.Space.Used.Th.DoesViolate(fs.UsageStats.UsedPercent) { tmpPartialResult.SetState(check.Warning) - tmpPartialResult.Output = fmt.Sprintf("Percentage of used space violates threshold: %.2f%%", fs.UsageStats.UsedPercent) + tmpPartialResult.SetOutput(fmt.Sprintf("Percentage of used space violates threshold: %.2f%%", fs.UsageStats.UsedPercent)) } } @@ -485,18 +489,18 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem if config.CriticalPercentThreshold.Space.Used.Th.DoesViolate(fs.UsageStats.UsedPercent) { tmpPartialResult.SetState(check.Critical) - tmpPartialResult.Output = fmt.Sprintf("Percentage of used space violates threshold: %.2f%%", fs.UsageStats.UsedPercent) + tmpPartialResult.SetOutput(fmt.Sprintf("Percentage of used space violates threshold: %.2f%%", fs.UsageStats.UsedPercent)) } } if tmpPartialResult.GetStatus() == check.OK { - tmpPartialResult.Output = fmt.Sprintf("Percentage of used space: %.2f%%", fs.UsageStats.UsedPercent) + tmpPartialResult.SetOutput(fmt.Sprintf("Percentage of used space: %.2f%%", fs.UsageStats.UsedPercent)) } - tmpPartialResult.Perfdata.Add(&pdPercentageUsedSpace) + tmpPartialResult.AddPerfdata(&pdPercentageUsedSpace) returnResult.AddSubcheck(tmpPartialResult) } else { - returnResult.Perfdata.Add(&pdPercentageUsedSpace) + returnResult.AddPerfdata(&pdPercentageUsedSpace) } return returnResult @@ -504,12 +508,12 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem func computeFsCheckResult(fs *filesystem.FilesystemType, config *filesystem.CheckConfig) *result.PartialResult { returnResult := result.NewPartialResult() - returnResult.Output = fs.PartStats.Mountpoint + returnResult.SetOutput(fs.PartStats.Mountpoint) returnResult.SetDefaultState(check.OK) if fs.Error != nil { 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) + returnResult.SetOutput(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 } diff --git a/cmd/load.go b/cmd/load.go index 9b3cddf..8945e16 100644 --- a/cmd/load.go +++ b/cmd/load.go @@ -84,8 +84,8 @@ var loadCmd = &cobra.Command{ tmpOutput += fmt.Sprintf(", system total: %.2f", originalLoad[0]) } - partialLoad1.Output = tmpOutput - partialLoad1.Perfdata.Add(tmpPerfdata) + partialLoad1.SetOutput(tmpOutput) + partialLoad1.AddPerfdata(tmpPerfdata) // 5 Minute average partialLoad5 := result.NewPartialResult() @@ -122,8 +122,8 @@ var loadCmd = &cobra.Command{ tmpOutput += fmt.Sprintf(", system total: %.2f", originalLoad[1]) } - partialLoad5.Output = tmpOutput - partialLoad5.Perfdata.Add(tmpPerfdata) + partialLoad5.SetOutput(tmpOutput) + partialLoad5.AddPerfdata(tmpPerfdata) // 15 Minute average partialLoad15 := result.NewPartialResult() @@ -160,8 +160,8 @@ var loadCmd = &cobra.Command{ tmpOutput += fmt.Sprintf(", system total: %.2f", originalLoad[2]) } - partialLoad15.Output = tmpOutput - partialLoad15.Perfdata.Add(tmpPerfdata) + partialLoad15.SetOutput(tmpOutput) + partialLoad15.AddPerfdata(tmpPerfdata) overall.AddSubcheck(partialLoad1) overall.AddSubcheck(partialLoad5) diff --git a/cmd/memory.go b/cmd/memory.go index e89b5d1..bd37886 100644 --- a/cmd/memory.go +++ b/cmd/memory.go @@ -51,7 +51,7 @@ var memoryCmd = &cobra.Command{ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) *result.PartialResult { partialMem := result.NewPartialResult() - partialMem.Output = "RAM" + partialMem.SetOutput("RAM") partialMem.SetDefaultState(check.OK) // # Available @@ -59,10 +59,10 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) *result.P partialMemAvailable.SetDefaultState(check.OK) - partialMemAvailable.Output = fmt.Sprintf("Available Memory (%s/%s, %.2f%%)", + partialMemAvailable.SetOutput(fmt.Sprintf("Available Memory (%s/%s, %.2f%%)", convert.BytesIEC(memStats.VirtMem.Available), convert.BytesIEC(memStats.VirtMem.Total), - memStats.MemAvailablePercentage) + memStats.MemAvailablePercentage)) // perfdata pdMemAvailable := check.Perfdata{ @@ -112,10 +112,10 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) *result.P } if config.PercentageInPerfdata { - partialMemAvailable.Perfdata.Add(&pdMemAvailablePrcnt) + partialMemAvailable.AddPerfdata(&pdMemAvailablePrcnt) } - partialMemAvailable.Perfdata.Add(&pdMemAvailable) + partialMemAvailable.AddPerfdata(&pdMemAvailable) partialMem.AddSubcheck(partialMemAvailable) if (partialMemAvailable.GetStatus() > partialMem.GetStatus()) && @@ -144,10 +144,10 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) *result.P Uom: "%", } - partialMemFree.Output = fmt.Sprintf("Free Memory (%s/%s, %.2f%%)", + partialMemFree.SetOutput(fmt.Sprintf("Free Memory (%s/%s, %.2f%%)", convert.BytesIEC(memStats.VirtMem.Free), convert.BytesIEC(memStats.VirtMem.Total), - MemFreePercentage) + MemFreePercentage)) if config.MemFree.Warn.IsSet { pdMemFree.Warn = &config.MemFree.Warn.Th @@ -181,10 +181,10 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) *result.P } } - partialMemFree.Perfdata.Add(&pdMemFree) + partialMemFree.AddPerfdata(&pdMemFree) if config.PercentageInPerfdata { - partialMemFree.Perfdata.Add(&pdMemFreePercentage) + partialMemFree.AddPerfdata(&pdMemFreePercentage) } partialMem.AddSubcheck(partialMemFree) @@ -199,10 +199,10 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) *result.P partialMemUsed.SetDefaultState(check.OK) - partialMemUsed.Output = fmt.Sprintf("Used Memory (%s/%s, %.2f%%)", + partialMemUsed.SetOutput(fmt.Sprintf("Used Memory (%s/%s, %.2f%%)", convert.BytesIEC(memStats.VirtMem.Used), convert.BytesIEC(memStats.VirtMem.Total), - memStats.VirtMem.UsedPercent) + memStats.VirtMem.UsedPercent)) pdMemUsed := check.Perfdata{ Label: "used_memory", @@ -251,10 +251,10 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) *result.P } } - partialMemUsed.Perfdata.Add(&pdMemUsed) + partialMemUsed.AddPerfdata(&pdMemUsed) if config.PercentageInPerfdata { - partialMemUsed.Perfdata.Add(&pdMemUsedPercentage) + partialMemUsed.AddPerfdata(&pdMemUsedPercentage) } partialMem.AddSubcheck(partialMemUsed) @@ -418,12 +418,12 @@ func computeSwapResults(stats *memory.Mem) *result.PartialResult { if stats.VirtMem.SwapTotal == 0 { partialSwap.SetState(check.Critical) - partialSwap.Output = "Swap size is 0." + partialSwap.SetOutput("Swap size is 0.") return &partialSwap } - partialSwap.Output = fmt.Sprintf("Swap Usage %.2f%% (%s / %s)", stats.SwapInfo.UsedPercent, convert.BytesIEC(stats.SwapInfo.Used), convert.BytesIEC(stats.SwapInfo.Total)) + partialSwap.SetOutput(fmt.Sprintf("Swap Usage %.2f%% (%s / %s)", stats.SwapInfo.UsedPercent, convert.BytesIEC(stats.SwapInfo.Used), convert.BytesIEC(stats.SwapInfo.Total))) pdSwapUsed := check.Perfdata{ Label: "swap_used", @@ -499,10 +499,10 @@ func computeSwapResults(stats *memory.Mem) *result.PartialResult { // Percentage to Perfdata if MemoryConfig.PercentageInPerfdata { - partialSwap.Perfdata.Add(&pdSwapPrcnt) + partialSwap.AddPerfdata(&pdSwapPrcnt) } - partialSwap.Perfdata.Add(&pdSwapUsed) + partialSwap.AddPerfdata(&pdSwapUsed) return &partialSwap } diff --git a/cmd/netdev.go b/cmd/netdev.go index c2694bc..475fff6 100644 --- a/cmd/netdev.go +++ b/cmd/netdev.go @@ -60,7 +60,7 @@ func NetdevCheck(_ *cobra.Command, _ []string) { sc := result.NewPartialResult() sc.SetDefaultState(check.OK) - sc.Output = interfaces[i].Name + " is " + netdev.TranslateIfaceState(interfaces[i].Operstate) + sc.SetOutput(interfaces[i].Name + " is " + netdev.TranslateIfaceState(interfaces[i].Operstate)) if !NetdevConfig.NotUpIsOK { switch interfaces[i].Operstate { @@ -88,7 +88,7 @@ func NetdevCheck(_ *cobra.Command, _ []string) { pd.Label = interfaces[i].Name + "_" + netdev.GetIfaceStatNames()[j] pd.Value = interfaces[i].Metrics[j] - sc.Perfdata.Add(&pd) + sc.AddPerfdata(&pd) } overall.AddSubcheck(sc) diff --git a/cmd/psi.go b/cmd/psi.go index 499d926..4a7bdcc 100644 --- a/cmd/psi.go +++ b/cmd/psi.go @@ -238,13 +238,13 @@ func checkPsiCPUPressure(config *psiConfig) *result.PartialResult { cpuCheck := result.NewPartialResult() cpuCheck.SetDefaultState(check.OK) - cpuCheck.Output = "CPU" + cpuCheck.SetOutput("CPU") psiCPU, err := psi.ReadCPUPressure() if err != nil { if errors.Is(err, os.ErrNotExist) { 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" + cpuCheck.SetOutput("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 } @@ -252,126 +252,130 @@ func checkPsiCPUPressure(config *psiConfig) *result.PartialResult { check.ExitError(err) } - cpuCheck.Perfdata = *psiCPU.Perfdata() + cpuCheckPerfdata := *psiCPU.Perfdata() //nolint:nestif if psiCPU.FullPresent { // Warn thresholds if config.WarningCPUFullAvg10.IsSet { - cpuCheck.Perfdata[psi.CPUFullAvg10].Warn = &config.WarningCPUFullAvg10.Th + cpuCheckPerfdata[psi.CPUFullAvg10].Warn = &config.WarningCPUFullAvg10.Th } else { - cpuCheck.Perfdata[psi.CPUFullAvg10].Warn = &config.WarningCPUAvg.Th + cpuCheckPerfdata[psi.CPUFullAvg10].Warn = &config.WarningCPUAvg.Th } if config.WarningCPUFullAvg60.IsSet { - cpuCheck.Perfdata[psi.CPUFullAvg60].Warn = &config.WarningCPUFullAvg60.Th + cpuCheckPerfdata[psi.CPUFullAvg60].Warn = &config.WarningCPUFullAvg60.Th } else { - cpuCheck.Perfdata[psi.CPUFullAvg60].Warn = &config.WarningCPUAvg.Th + cpuCheckPerfdata[psi.CPUFullAvg60].Warn = &config.WarningCPUAvg.Th } if config.WarningCPUFullAvg300.IsSet { - cpuCheck.Perfdata[psi.CPUFullAvg300].Warn = &config.WarningCPUFullAvg300.Th + cpuCheckPerfdata[psi.CPUFullAvg300].Warn = &config.WarningCPUFullAvg300.Th } else { - cpuCheck.Perfdata[psi.CPUFullAvg300].Warn = &config.WarningCPUAvg.Th + cpuCheckPerfdata[psi.CPUFullAvg300].Warn = &config.WarningCPUAvg.Th } // Critical thresholds if config.CriticalCPUFullAvg10.IsSet { - cpuCheck.Perfdata[psi.CPUFullAvg10].Crit = &config.CriticalCPUFullAvg10.Th + cpuCheckPerfdata[psi.CPUFullAvg10].Crit = &config.CriticalCPUFullAvg10.Th } else { - cpuCheck.Perfdata[psi.CPUFullAvg10].Crit = &config.CriticalCPUAvg.Th + cpuCheckPerfdata[psi.CPUFullAvg10].Crit = &config.CriticalCPUAvg.Th } if config.CriticalCPUFullAvg60.IsSet { - cpuCheck.Perfdata[psi.CPUFullAvg60].Crit = &config.CriticalCPUFullAvg60.Th + cpuCheckPerfdata[psi.CPUFullAvg60].Crit = &config.CriticalCPUFullAvg60.Th } else { - cpuCheck.Perfdata[psi.CPUFullAvg60].Crit = &config.CriticalCPUAvg.Th + cpuCheckPerfdata[psi.CPUFullAvg60].Crit = &config.CriticalCPUAvg.Th } if config.CriticalCPUFullAvg300.IsSet { - cpuCheck.Perfdata[psi.CPUFullAvg300].Crit = &config.CriticalCPUFullAvg300.Th + cpuCheckPerfdata[psi.CPUFullAvg300].Crit = &config.CriticalCPUFullAvg300.Th } else { - cpuCheck.Perfdata[psi.CPUFullAvg300].Crit = &config.CriticalCPUAvg.Th + cpuCheckPerfdata[psi.CPUFullAvg300].Crit = &config.CriticalCPUAvg.Th } 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) { + if cpuCheckPerfdata[psi.CPUFullAvg10].Warn.DoesViolate(psiCPU.Full.Avg10) || + cpuCheckPerfdata[psi.CPUFullAvg60].Warn.DoesViolate(psiCPU.Full.Avg60) || + cpuCheckPerfdata[psi.CPUFullAvg300].Warn.DoesViolate(psiCPU.Full.Avg300) { 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) { + if cpuCheckPerfdata[psi.CPUFullAvg10].Crit.DoesViolate(psiCPU.Full.Avg10) || + cpuCheckPerfdata[psi.CPUFullAvg60].Crit.DoesViolate(psiCPU.Full.Avg60) || + cpuCheckPerfdata[psi.CPUFullAvg300].Crit.DoesViolate(psiCPU.Full.Avg300) { cpuFullSc.SetState(check.Critical) } - cpuFullSc.Output = fmt.Sprintf("Full - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiCPU.Full.Avg10, psiCPU.Full.Avg60, psiCPU.Full.Avg300) + cpuFullSc.SetOutput(fmt.Sprintf("Full - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiCPU.Full.Avg10, psiCPU.Full.Avg60, psiCPU.Full.Avg300)) cpuCheck.AddSubcheck(cpuFullSc) } if config.WarningCPUSomeAvg10.IsSet { - cpuCheck.Perfdata[psi.CPUSomeAvg10].Warn = &config.WarningCPUSomeAvg10.Th + cpuCheckPerfdata[psi.CPUSomeAvg10].Warn = &config.WarningCPUSomeAvg10.Th } else { - cpuCheck.Perfdata[psi.CPUSomeAvg10].Warn = &config.WarningCPUAvg.Th + cpuCheckPerfdata[psi.CPUSomeAvg10].Warn = &config.WarningCPUAvg.Th } if config.WarningCPUSomeAvg60.IsSet { - cpuCheck.Perfdata[psi.CPUSomeAvg60].Warn = &config.WarningCPUSomeAvg60.Th + cpuCheckPerfdata[psi.CPUSomeAvg60].Warn = &config.WarningCPUSomeAvg60.Th } else { - cpuCheck.Perfdata[psi.CPUSomeAvg60].Warn = &config.WarningCPUAvg.Th + cpuCheckPerfdata[psi.CPUSomeAvg60].Warn = &config.WarningCPUAvg.Th } if config.WarningCPUSomeAvg300.IsSet { - cpuCheck.Perfdata[psi.CPUSomeAvg300].Warn = &config.WarningCPUSomeAvg300.Th + cpuCheckPerfdata[psi.CPUSomeAvg300].Warn = &config.WarningCPUSomeAvg300.Th } else { - cpuCheck.Perfdata[psi.CPUSomeAvg300].Warn = &config.WarningCPUAvg.Th + cpuCheckPerfdata[psi.CPUSomeAvg300].Warn = &config.WarningCPUAvg.Th } // Critical thresholds if config.CriticalCPUSomeAvg10.IsSet { - cpuCheck.Perfdata[psi.CPUSomeAvg10].Crit = &config.CriticalCPUSomeAvg10.Th + cpuCheckPerfdata[psi.CPUSomeAvg10].Crit = &config.CriticalCPUSomeAvg10.Th } else { - cpuCheck.Perfdata[psi.CPUSomeAvg10].Crit = &config.CriticalCPUAvg.Th + cpuCheckPerfdata[psi.CPUSomeAvg10].Crit = &config.CriticalCPUAvg.Th } if config.CriticalCPUSomeAvg60.IsSet { - cpuCheck.Perfdata[psi.CPUSomeAvg60].Crit = &config.CriticalCPUSomeAvg60.Th + cpuCheckPerfdata[psi.CPUSomeAvg60].Crit = &config.CriticalCPUSomeAvg60.Th } else { - cpuCheck.Perfdata[psi.CPUSomeAvg60].Crit = &config.CriticalCPUAvg.Th + cpuCheckPerfdata[psi.CPUSomeAvg60].Crit = &config.CriticalCPUAvg.Th } if config.CriticalCPUSomeAvg300.IsSet { - cpuCheck.Perfdata[psi.CPUSomeAvg300].Crit = &config.CriticalCPUSomeAvg300.Th + cpuCheckPerfdata[psi.CPUSomeAvg300].Crit = &config.CriticalCPUSomeAvg300.Th } else { - cpuCheck.Perfdata[psi.CPUSomeAvg300].Crit = &config.CriticalCPUAvg.Th + cpuCheckPerfdata[psi.CPUSomeAvg300].Crit = &config.CriticalCPUAvg.Th } 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) { + if cpuCheckPerfdata[psi.CPUSomeAvg10].Warn.DoesViolate(psiCPU.Some.Avg10) || + cpuCheckPerfdata[psi.CPUSomeAvg60].Warn.DoesViolate(psiCPU.Some.Avg60) || + cpuCheckPerfdata[psi.CPUSomeAvg300].Warn.DoesViolate(psiCPU.Some.Avg300) { cpuSomeSc.SetState(check.Warning) } } if cpuCheck.GetStatus() != check.Critical { - 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) { + if cpuCheckPerfdata[psi.CPUSomeAvg10].Crit.DoesViolate(psiCPU.Some.Avg10) || + cpuCheckPerfdata[psi.CPUSomeAvg60].Crit.DoesViolate(psiCPU.Some.Avg60) || + cpuCheckPerfdata[psi.CPUSomeAvg300].Crit.DoesViolate(psiCPU.Some.Avg300) { cpuSomeSc.SetState(check.Critical) } } - cpuSomeSc.Output = fmt.Sprintf("Some - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiCPU.Some.Avg10, psiCPU.Some.Avg60, psiCPU.Some.Avg300) + cpuSomeSc.SetOutput(fmt.Sprintf("Some - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiCPU.Some.Avg10, psiCPU.Some.Avg60, psiCPU.Some.Avg300)) cpuCheck.AddSubcheck(cpuSomeSc) + for _, item := range cpuCheckPerfdata { + cpuCheck.AddPerfdata(item) + } + return cpuCheck } @@ -379,13 +383,13 @@ func checkPsiIoPressure(config *psiConfig) *result.PartialResult { ioCheck := result.NewPartialResult() ioCheck.SetDefaultState(check.OK) - ioCheck.Output = "IO" + ioCheck.SetOutput("IO") psiIo, err := psi.ReadIoPressure() if err != nil { if errors.Is(err, os.ErrNotExist) { 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" + ioCheck.SetOutput("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 } @@ -393,125 +397,129 @@ func checkPsiIoPressure(config *psiConfig) *result.PartialResult { check.ExitError(err) } - ioCheck.Perfdata = *psiIo.Perfdata() + ioCheckPerfdata := *psiIo.Perfdata() //nolint:nestif if psiIo.FullPresent { // Warn thresholds if config.WarningIoFullAvg10.IsSet { - ioCheck.Perfdata[psi.IoFullAvg10].Warn = &config.WarningIoFullAvg10.Th + ioCheckPerfdata[psi.IoFullAvg10].Warn = &config.WarningIoFullAvg10.Th } else { - ioCheck.Perfdata[psi.IoFullAvg10].Warn = &config.WarningIoAvg.Th + ioCheckPerfdata[psi.IoFullAvg10].Warn = &config.WarningIoAvg.Th } if config.WarningIoFullAvg60.IsSet { - ioCheck.Perfdata[psi.IoFullAvg60].Warn = &config.WarningIoFullAvg60.Th + ioCheckPerfdata[psi.IoFullAvg60].Warn = &config.WarningIoFullAvg60.Th } else { - ioCheck.Perfdata[psi.IoFullAvg60].Warn = &config.WarningIoAvg.Th + ioCheckPerfdata[psi.IoFullAvg60].Warn = &config.WarningIoAvg.Th } if config.WarningIoFullAvg300.IsSet { - ioCheck.Perfdata[psi.IoFullAvg300].Warn = &config.WarningIoFullAvg300.Th + ioCheckPerfdata[psi.IoFullAvg300].Warn = &config.WarningIoFullAvg300.Th } else { - ioCheck.Perfdata[psi.IoFullAvg300].Warn = &config.WarningIoAvg.Th + ioCheckPerfdata[psi.IoFullAvg300].Warn = &config.WarningIoAvg.Th } // Critical thresholds if config.CriticalIoFullAvg10.IsSet { - ioCheck.Perfdata[psi.IoFullAvg10].Crit = &config.CriticalIoFullAvg10.Th + ioCheckPerfdata[psi.IoFullAvg10].Crit = &config.CriticalIoFullAvg10.Th } else { - ioCheck.Perfdata[psi.IoFullAvg10].Crit = &config.CriticalIoAvg.Th + ioCheckPerfdata[psi.IoFullAvg10].Crit = &config.CriticalIoAvg.Th } if config.CriticalIoFullAvg60.IsSet { - ioCheck.Perfdata[psi.IoFullAvg60].Crit = &config.CriticalIoFullAvg60.Th + ioCheckPerfdata[psi.IoFullAvg60].Crit = &config.CriticalIoFullAvg60.Th } else { - ioCheck.Perfdata[psi.IoFullAvg60].Crit = &config.CriticalIoAvg.Th + ioCheckPerfdata[psi.IoFullAvg60].Crit = &config.CriticalIoAvg.Th } if config.CriticalIoFullAvg300.IsSet { - ioCheck.Perfdata[psi.IoFullAvg300].Crit = &config.CriticalIoFullAvg300.Th + ioCheckPerfdata[psi.IoFullAvg300].Crit = &config.CriticalIoFullAvg300.Th } else { - ioCheck.Perfdata[psi.IoFullAvg300].Crit = &config.CriticalIoAvg.Th + ioCheckPerfdata[psi.IoFullAvg300].Crit = &config.CriticalIoAvg.Th } 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) { + if ioCheckPerfdata[psi.IoFullAvg10].Warn.DoesViolate(psiIo.Full.Avg10) || + ioCheckPerfdata[psi.IoFullAvg60].Warn.DoesViolate(psiIo.Full.Avg60) || + ioCheckPerfdata[psi.IoFullAvg300].Warn.DoesViolate(psiIo.Full.Avg300) { 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) { + if ioCheckPerfdata[psi.IoFullAvg10].Crit.DoesViolate(psiIo.Full.Avg10) || + ioCheckPerfdata[psi.IoFullAvg60].Crit.DoesViolate(psiIo.Full.Avg60) || + ioCheckPerfdata[psi.IoFullAvg300].Crit.DoesViolate(psiIo.Full.Avg300) { ioFullSc.SetState(check.Critical) } - ioFullSc.Output = fmt.Sprintf("Full - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiIo.Full.Avg10, psiIo.Full.Avg60, psiIo.Full.Avg300) + ioFullSc.SetOutput(fmt.Sprintf("Full - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiIo.Full.Avg10, psiIo.Full.Avg60, psiIo.Full.Avg300)) ioCheck.AddSubcheck(ioFullSc) } if config.WarningIoSomeAvg10.IsSet { - ioCheck.Perfdata[psi.IoSomeAvg10].Warn = &config.WarningIoSomeAvg10.Th + ioCheckPerfdata[psi.IoSomeAvg10].Warn = &config.WarningIoSomeAvg10.Th } else { - ioCheck.Perfdata[psi.IoSomeAvg10].Warn = &config.WarningIoAvg.Th + ioCheckPerfdata[psi.IoSomeAvg10].Warn = &config.WarningIoAvg.Th } if config.WarningIoSomeAvg60.IsSet { - ioCheck.Perfdata[psi.IoSomeAvg60].Warn = &config.WarningIoSomeAvg60.Th + ioCheckPerfdata[psi.IoSomeAvg60].Warn = &config.WarningIoSomeAvg60.Th } else { - ioCheck.Perfdata[psi.IoSomeAvg60].Warn = &config.WarningIoAvg.Th + ioCheckPerfdata[psi.IoSomeAvg60].Warn = &config.WarningIoAvg.Th } if config.WarningIoSomeAvg300.IsSet { - ioCheck.Perfdata[psi.IoSomeAvg300].Warn = &config.WarningIoSomeAvg300.Th + ioCheckPerfdata[psi.IoSomeAvg300].Warn = &config.WarningIoSomeAvg300.Th } else { - ioCheck.Perfdata[psi.IoSomeAvg300].Warn = &config.WarningIoAvg.Th + ioCheckPerfdata[psi.IoSomeAvg300].Warn = &config.WarningIoAvg.Th } if config.CriticalIoSomeAvg10.IsSet { - ioCheck.Perfdata[psi.IoSomeAvg10].Crit = &config.CriticalIoSomeAvg10.Th + ioCheckPerfdata[psi.IoSomeAvg10].Crit = &config.CriticalIoSomeAvg10.Th } else { - ioCheck.Perfdata[psi.IoSomeAvg10].Crit = &config.CriticalIoAvg.Th + ioCheckPerfdata[psi.IoSomeAvg10].Crit = &config.CriticalIoAvg.Th } if config.CriticalIoSomeAvg60.IsSet { - ioCheck.Perfdata[psi.IoSomeAvg60].Crit = &config.CriticalIoSomeAvg60.Th + ioCheckPerfdata[psi.IoSomeAvg60].Crit = &config.CriticalIoSomeAvg60.Th } else { - ioCheck.Perfdata[psi.IoSomeAvg60].Crit = &config.CriticalIoAvg.Th + ioCheckPerfdata[psi.IoSomeAvg60].Crit = &config.CriticalIoAvg.Th } if config.CriticalIoSomeAvg300.IsSet { - ioCheck.Perfdata[psi.IoSomeAvg300].Crit = &config.CriticalIoSomeAvg300.Th + ioCheckPerfdata[psi.IoSomeAvg300].Crit = &config.CriticalIoSomeAvg300.Th } else { - ioCheck.Perfdata[psi.IoSomeAvg300].Crit = &config.CriticalIoAvg.Th + ioCheckPerfdata[psi.IoSomeAvg300].Crit = &config.CriticalIoAvg.Th } 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) { + if ioCheckPerfdata[psi.IoSomeAvg10].Warn.DoesViolate(psiIo.Some.Avg10) || + ioCheckPerfdata[psi.IoSomeAvg60].Warn.DoesViolate(psiIo.Some.Avg60) || + ioCheckPerfdata[psi.IoSomeAvg300].Warn.DoesViolate(psiIo.Some.Avg300) { ioSomeSc.SetState(check.Warning) } } if ioCheck.GetStatus() != check.Critical { - 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) { + if ioCheckPerfdata[psi.IoSomeAvg10].Crit.DoesViolate(psiIo.Some.Avg10) || + ioCheckPerfdata[psi.IoSomeAvg60].Crit.DoesViolate(psiIo.Some.Avg60) || + ioCheckPerfdata[psi.IoSomeAvg300].Crit.DoesViolate(psiIo.Some.Avg300) { ioSomeSc.SetState(check.Critical) } } - ioSomeSc.Output = fmt.Sprintf("Some - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiIo.Some.Avg10, psiIo.Some.Avg60, psiIo.Some.Avg300) + ioSomeSc.SetOutput(fmt.Sprintf("Some - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiIo.Some.Avg10, psiIo.Some.Avg60, psiIo.Some.Avg300)) ioCheck.AddSubcheck(ioSomeSc) + for _, item := range ioCheckPerfdata { + ioCheck.AddPerfdata(item) + } + return ioCheck } @@ -519,13 +527,13 @@ func checkPsiMemoryPressure(config *psiConfig) *result.PartialResult { memoryCheck := result.NewPartialResult() memoryCheck.SetDefaultState(check.OK) - memoryCheck.Output = "Memory" + memoryCheck.SetOutput("Memory") psiMemory, err := psi.ReadMemoryPressure() if err != nil { if errors.Is(err, os.ErrNotExist) { 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" + memoryCheck.SetOutput("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 } @@ -533,125 +541,129 @@ func checkPsiMemoryPressure(config *psiConfig) *result.PartialResult { check.ExitError(err) } - memoryCheck.Perfdata = *psiMemory.Perfdata() + memoryCheckPerfdata := *psiMemory.Perfdata() //nolint:nestif if psiMemory.FullPresent { // Warn thresholds if config.WarningMemoryFullAvg10.IsSet { - memoryCheck.Perfdata[psi.MemoryFullAvg10].Warn = &config.WarningMemoryFullAvg10.Th + memoryCheckPerfdata[psi.MemoryFullAvg10].Warn = &config.WarningMemoryFullAvg10.Th } else { - memoryCheck.Perfdata[psi.MemoryFullAvg10].Warn = &config.WarningMemoryAvg.Th + memoryCheckPerfdata[psi.MemoryFullAvg10].Warn = &config.WarningMemoryAvg.Th } if config.WarningMemoryFullAvg60.IsSet { - memoryCheck.Perfdata[psi.MemoryFullAvg60].Warn = &config.WarningMemoryFullAvg60.Th + memoryCheckPerfdata[psi.MemoryFullAvg60].Warn = &config.WarningMemoryFullAvg60.Th } else { - memoryCheck.Perfdata[psi.MemoryFullAvg60].Warn = &config.WarningMemoryAvg.Th + memoryCheckPerfdata[psi.MemoryFullAvg60].Warn = &config.WarningMemoryAvg.Th } if config.WarningMemoryFullAvg300.IsSet { - memoryCheck.Perfdata[psi.MemoryFullAvg300].Warn = &config.WarningMemoryFullAvg300.Th + memoryCheckPerfdata[psi.MemoryFullAvg300].Warn = &config.WarningMemoryFullAvg300.Th } else { - memoryCheck.Perfdata[psi.MemoryFullAvg300].Warn = &config.WarningMemoryAvg.Th + memoryCheckPerfdata[psi.MemoryFullAvg300].Warn = &config.WarningMemoryAvg.Th } // Critical thresholds if config.CriticalMemoryFullAvg10.IsSet { - memoryCheck.Perfdata[psi.MemoryFullAvg10].Crit = &config.CriticalMemoryFullAvg10.Th + memoryCheckPerfdata[psi.MemoryFullAvg10].Crit = &config.CriticalMemoryFullAvg10.Th } else { - memoryCheck.Perfdata[psi.MemoryFullAvg10].Crit = &config.CriticalMemoryAvg.Th + memoryCheckPerfdata[psi.MemoryFullAvg10].Crit = &config.CriticalMemoryAvg.Th } if config.CriticalMemoryFullAvg60.IsSet { - memoryCheck.Perfdata[psi.MemoryFullAvg60].Crit = &config.CriticalMemoryFullAvg60.Th + memoryCheckPerfdata[psi.MemoryFullAvg60].Crit = &config.CriticalMemoryFullAvg60.Th } else { - memoryCheck.Perfdata[psi.MemoryFullAvg60].Crit = &config.CriticalMemoryAvg.Th + memoryCheckPerfdata[psi.MemoryFullAvg60].Crit = &config.CriticalMemoryAvg.Th } if config.CriticalMemoryFullAvg300.IsSet { - memoryCheck.Perfdata[psi.MemoryFullAvg300].Crit = &config.CriticalMemoryFullAvg300.Th + memoryCheckPerfdata[psi.MemoryFullAvg300].Crit = &config.CriticalMemoryFullAvg300.Th } else { - memoryCheck.Perfdata[psi.MemoryFullAvg300].Crit = &config.CriticalMemoryAvg.Th + memoryCheckPerfdata[psi.MemoryFullAvg300].Crit = &config.CriticalMemoryAvg.Th } 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) { + if memoryCheckPerfdata[psi.MemoryFullAvg10].Warn.DoesViolate(psiMemory.Full.Avg10) || + memoryCheckPerfdata[psi.MemoryFullAvg60].Warn.DoesViolate(psiMemory.Full.Avg60) || + memoryCheckPerfdata[psi.MemoryFullAvg300].Warn.DoesViolate(psiMemory.Full.Avg300) { 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) { + if memoryCheckPerfdata[psi.MemoryFullAvg10].Crit.DoesViolate(psiMemory.Full.Avg10) || + memoryCheckPerfdata[psi.MemoryFullAvg60].Crit.DoesViolate(psiMemory.Full.Avg60) || + memoryCheckPerfdata[psi.MemoryFullAvg300].Crit.DoesViolate(psiMemory.Full.Avg300) { memoryFullSc.SetState(check.Critical) } - memoryFullSc.Output = fmt.Sprintf("Full - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiMemory.Full.Avg10, psiMemory.Full.Avg60, psiMemory.Full.Avg300) + memoryFullSc.SetOutput(fmt.Sprintf("Full - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiMemory.Full.Avg10, psiMemory.Full.Avg60, psiMemory.Full.Avg300)) memoryCheck.AddSubcheck(memoryFullSc) } if config.WarningMemorySomeAvg10.IsSet { - memoryCheck.Perfdata[psi.MemorySomeAvg10].Warn = &config.WarningMemorySomeAvg10.Th + memoryCheckPerfdata[psi.MemorySomeAvg10].Warn = &config.WarningMemorySomeAvg10.Th } else { - memoryCheck.Perfdata[psi.MemorySomeAvg10].Warn = &config.WarningMemoryAvg.Th + memoryCheckPerfdata[psi.MemorySomeAvg10].Warn = &config.WarningMemoryAvg.Th } if config.WarningMemorySomeAvg60.IsSet { - memoryCheck.Perfdata[psi.MemorySomeAvg60].Warn = &config.WarningMemorySomeAvg60.Th + memoryCheckPerfdata[psi.MemorySomeAvg60].Warn = &config.WarningMemorySomeAvg60.Th } else { - memoryCheck.Perfdata[psi.MemorySomeAvg60].Warn = &config.WarningMemoryAvg.Th + memoryCheckPerfdata[psi.MemorySomeAvg60].Warn = &config.WarningMemoryAvg.Th } if config.WarningMemorySomeAvg300.IsSet { - memoryCheck.Perfdata[psi.MemorySomeAvg300].Warn = &config.WarningMemorySomeAvg300.Th + memoryCheckPerfdata[psi.MemorySomeAvg300].Warn = &config.WarningMemorySomeAvg300.Th } else { - memoryCheck.Perfdata[psi.MemorySomeAvg300].Warn = &config.WarningMemoryAvg.Th + memoryCheckPerfdata[psi.MemorySomeAvg300].Warn = &config.WarningMemoryAvg.Th } // Critical thresholds if config.CriticalMemorySomeAvg10.IsSet { - memoryCheck.Perfdata[psi.MemorySomeAvg10].Crit = &config.CriticalMemorySomeAvg10.Th + memoryCheckPerfdata[psi.MemorySomeAvg10].Crit = &config.CriticalMemorySomeAvg10.Th } else { - memoryCheck.Perfdata[psi.MemorySomeAvg10].Crit = &config.CriticalMemoryAvg.Th + memoryCheckPerfdata[psi.MemorySomeAvg10].Crit = &config.CriticalMemoryAvg.Th } if config.CriticalMemorySomeAvg60.IsSet { - memoryCheck.Perfdata[psi.MemorySomeAvg60].Crit = &config.CriticalMemorySomeAvg60.Th + memoryCheckPerfdata[psi.MemorySomeAvg60].Crit = &config.CriticalMemorySomeAvg60.Th } else { - memoryCheck.Perfdata[psi.MemorySomeAvg60].Crit = &config.CriticalMemoryAvg.Th + memoryCheckPerfdata[psi.MemorySomeAvg60].Crit = &config.CriticalMemoryAvg.Th } if config.CriticalMemorySomeAvg300.IsSet { - memoryCheck.Perfdata[psi.MemorySomeAvg300].Crit = &config.CriticalMemorySomeAvg300.Th + memoryCheckPerfdata[psi.MemorySomeAvg300].Crit = &config.CriticalMemorySomeAvg300.Th } else { - memoryCheck.Perfdata[psi.MemorySomeAvg300].Crit = &config.CriticalMemoryAvg.Th + memoryCheckPerfdata[psi.MemorySomeAvg300].Crit = &config.CriticalMemoryAvg.Th } 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) { + if memoryCheckPerfdata[psi.MemorySomeAvg10].Warn.DoesViolate(psiMemory.Some.Avg10) || + memoryCheckPerfdata[psi.MemorySomeAvg60].Warn.DoesViolate(psiMemory.Some.Avg60) || + memoryCheckPerfdata[psi.MemorySomeAvg300].Warn.DoesViolate(psiMemory.Some.Avg300) { memorySomeSc.SetState(check.Warning) } } if memoryCheck.GetStatus() != check.Critical { - 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) { + if memoryCheckPerfdata[psi.MemorySomeAvg10].Crit.DoesViolate(psiMemory.Some.Avg10) || + memoryCheckPerfdata[psi.MemorySomeAvg60].Crit.DoesViolate(psiMemory.Some.Avg60) || + memoryCheckPerfdata[psi.MemorySomeAvg300].Crit.DoesViolate(psiMemory.Some.Avg300) { memorySomeSc.SetState(check.Critical) } } - memorySomeSc.Output = fmt.Sprintf("Some - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiMemory.Some.Avg10, psiMemory.Some.Avg60, psiMemory.Some.Avg300) + memorySomeSc.SetOutput(fmt.Sprintf("Some - Avg10: %.2f, Avg60: %.2f, Avg300: %.2f", psiMemory.Some.Avg10, psiMemory.Some.Avg60, psiMemory.Some.Avg300)) memoryCheck.AddSubcheck(memorySomeSc) + for _, item := range memoryCheckPerfdata { + memoryCheck.AddPerfdata(item) + } + return memoryCheck } diff --git a/cmd/sensors.go b/cmd/sensors.go index 13ce9fb..a2d2cf2 100644 --- a/cmd/sensors.go +++ b/cmd/sensors.go @@ -57,27 +57,31 @@ thresholds respecting the sensor type and the respective specialities`, devicePartial.SetDefaultState(check.OK) - devicePartial.Output = device.Name + devicePartial.SetOutput(device.Name) + for idx, sensor := range device.Sensors { ssc := result.NewPartialResult() ssc.SetDefaultState(check.OK) - ssc.Perfdata.Add(&(device.Sensors[idx]).Perfdata) + sensorPerfdata := &(device.Sensors[idx]).Perfdata + ssc.AddPerfdata(sensorPerfdata) + + preliminaryOutput := "" if sensor.Alarm { - ssc.Output = "Alarm!" + preliminaryOutput = "Alarm!" + ssc.SetState(check.Critical) alarms++ } else { - ssc.Output = "Ok" + preliminaryOutput = "Ok" + ssc.SetState(check.OK) } // Add perfdata label (sensor name) to ouptput to make it more descriptive - if len(ssc.Perfdata) == 1 { - ssc.Output = fmt.Sprintf("%s: %s - %v%s", ssc.Perfdata[0].Label, ssc.Output, ssc.Perfdata[0].Value, ssc.Perfdata[0].Uom) - } + ssc.SetOutput(fmt.Sprintf("%s: %s - %v%s", sensorPerfdata.Label, preliminaryOutput, sensorPerfdata.Value, sensorPerfdata.Uom)) devicePartial.AddSubcheck(ssc) } diff --git a/go.mod b/go.mod index c496062..abf70d2 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 v1.0.0-rc4 + github.com/NETWAYS/go-check v1.0.0 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 927e99b..2aea79e 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ github.com/NETWAYS/go-check v0.6.4 h1:4WETSVNZNEP0Yudcp5xlvxq6RGn920cmUKq4fz/P1G 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-check v1.0.0 h1:YkzTwFfGR+Z+mK3Wsqpnu8wibzsB30im19iPNfCOsMQ= +github.com/NETWAYS/go-check v1.0.0/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= From 1b76451bb77b02eed04231602a34df026b9fc683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Tue, 30 Jun 2026 13:47:15 +0200 Subject: [PATCH 5/5] Adapt tests --- cmd/filesystem_test.go | 4 ---- cmd/memory_test.go | 8 -------- 2 files changed, 12 deletions(-) diff --git a/cmd/filesystem_test.go b/cmd/filesystem_test.go index e7891e3..1125462 100644 --- a/cmd/filesystem_test.go +++ b/cmd/filesystem_test.go @@ -42,10 +42,6 @@ func TestFsCheckResult0(t *testing.T) { if check.OK != result.GetStatus() { t.Fatalf("expected %v, got %v", check.OK, result.GetStatus()) } - - if "/testMountpoint" != result.Output { - t.Fatalf("expected %v, got %v", "/testMountpoint", result.Output) - } } func TestFsCheckResult1(t *testing.T) { diff --git a/cmd/memory_test.go b/cmd/memory_test.go index 91af729..307889c 100644 --- a/cmd/memory_test.go +++ b/cmd/memory_test.go @@ -37,10 +37,6 @@ func TestComputeMemResultsWithoutThresholds(t *testing.T) { if check.OK != memPartial.GetStatus() { t.Fatalf("expected %v, got %v", check.OK, memPartial.GetStatus()) } - - if 3 != len(memPartial.PartialResults) { - t.Fatalf("expected %v, got %v", 3, len(memPartial.PartialResults)) - } } func TestComputeMemResultsWithThresholds(t *testing.T) { @@ -63,8 +59,4 @@ func TestComputeMemResultsWithThresholds(t *testing.T) { if check.Warning != memPartial.GetStatus() { t.Fatalf("expected %v, got %v", check.Warning, memPartial.GetStatus()) } - - if 3 != len(memPartial.PartialResults) { - t.Fatalf("expected %v, got %v", 3, len(memPartial.PartialResults)) - } }