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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: 1.24
go-version: stable
check-latest: true

- name: Test
run: go test -v ./...
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.11.2
version: v2.12.2
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ run:
tests: false
linters:
default: all
enable:
- wsl_v5
- gomodguard_v2
disable:
- wsl
- gomodguard
- cyclop
- depguard
- dupl
Expand Down
19 changes: 9 additions & 10 deletions cmd/cpu.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package cmd

import (
"fmt"

"github.com/NETWAYS/check_vspheredb_data/internal"

"github.com/NETWAYS/go-check"
"github.com/NETWAYS/go-check/perfdata"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -66,25 +68,25 @@ func queryCPU() {

// Add Perfdata.
// total usage.
pl.Add(&perfdata.Perfdata{
pl.Add(&check.Perfdata{
Label: "usage",
Value: overallCPUUsage,
})
// usage in percent, including thresholds.
pl.Add(&perfdata.Perfdata{
pl.Add(&check.Perfdata{
Label: "usage_percent",
Value: cpuUsagePercent,
Uom: "%",
Warn: cpuWarnThreshold,
Crit: cpuCritThreshold,
})
// mhz.
pl.Add(&perfdata.Perfdata{
pl.Add(&check.Perfdata{
Label: "mhz",
Value: hardwareCPUMHz,
})
// cores.
pl.Add(&perfdata.Perfdata{
pl.Add(&check.Perfdata{
Label: "cores",
Value: hardwareCPUCores,
})
Expand All @@ -101,9 +103,6 @@ func queryCPU() {
}

dbConnection.Close()
check.Exitf(statusCode,
"Total CPU usage is %dGHz (%d%%) | %s",
overallCPUUsage/1024,
cpuUsagePercent,
pl.String())

check.ExitWithPerfdata(statusCode, pl, fmt.Sprintf("Total CPU usage is %dGHz (%d%%)", overallCPUUsage/1024, cpuUsagePercent))
}
28 changes: 9 additions & 19 deletions cmd/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"

"github.com/NETWAYS/check_vspheredb_data/internal"

"github.com/NETWAYS/go-check"
"github.com/NETWAYS/go-check/perfdata"
"github.com/NETWAYS/go-check/result"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -78,11 +78,7 @@ func queryDatastore() {
pl.Add(&perfData)

dbConnection.Close()
check.Exitf(statusCode,
"Used storage space for datastore %s: %d%% | %s",
datastore,
perfData.Value, // this is the used capacity in %
pl.String())
check.ExitWithPerfdata(statusCode, pl, fmt.Sprintf("Used storage space for datastore %s: %d%%", datastore, perfData.Value))
}

func queryDatastores() {
Expand Down Expand Up @@ -135,27 +131,21 @@ func queryDatastores() {
perfData, state := processQueryResults(datastoreName, capacity, freeSpace)

// Create PartialResult and add to Overall result.
pr := result.PartialResult{
Output: fmt.Sprintf("Used storage for datastore %s: %d%%", datastoreName, perfData.Value),
}

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

pr.Perfdata.Add(&perfData)
pr := result.NewPartialResult()
pr.SetOutput(fmt.Sprintf("Used storage for datastore %s: %d%%", datastoreName, perfData.Value))
pr.SetState(state)
pr.AddPerfdata(&perfData)

aggregatedResult.AddSubcheck(pr)
}

dbConnection.Close()

check.ExitRaw(aggregatedResult.GetStatus(), aggregatedResult.GetOutput()) // ExitRaw because of 'nested formatting issues' otherwise.
check.Exit(aggregatedResult.GetStatus(), aggregatedResult.GetOutput())
}

// Computes Perfdata, check result based on the queried data.
func processQueryResults(datastore string, capacity, freeSpace int64) (perfdata.Perfdata, int) {
func processQueryResults(datastore string, capacity, freeSpace int64) (check.Perfdata, check.Status) {
// calculate percentage usage for check result decision.
datastoreUsagePercent := int64(0)
if capacity != 0 {
Expand All @@ -164,7 +154,7 @@ func processQueryResults(datastore string, capacity, freeSpace int64) (perfdata.

// Add Perfdata.
// percentage usage.
perfData := perfdata.Perfdata{
perfData := check.Perfdata{
Label: datastore + "_used",
Value: datastoreUsagePercent,
Uom: "%",
Expand Down
11 changes: 5 additions & 6 deletions cmd/hba.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package cmd

import (
"fmt"

"github.com/NETWAYS/check_vspheredb_data/internal"

"github.com/NETWAYS/go-check"
"github.com/NETWAYS/go-check/perfdata"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -55,7 +57,7 @@ func queryHba() {
check.ExitError(err)
}

pl.Add(&perfdata.Perfdata{
pl.Add(&check.Perfdata{
Label: "hbas",
Value: hardwareNumHBAs,
Warn: hbaWarnThreshold,
Expand All @@ -74,8 +76,5 @@ func queryHba() {
}

dbConnection.Close()
check.Exitf(statusCode,
"Number of HBAs: %d | %s",
hardwareNumHBAs,
pl.String())
check.ExitWithPerfdata(statusCode, pl, fmt.Sprintf("Number of HBAs: %d", hardwareNumHBAs))
}
14 changes: 6 additions & 8 deletions cmd/memory.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package cmd

import (
"fmt"

"github.com/NETWAYS/check_vspheredb_data/internal"

"github.com/NETWAYS/go-check"
"github.com/NETWAYS/go-check/perfdata"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -65,13 +67,13 @@ func queryMemory() {

// Add Perfdata.
// total usage.
pl.Add(&perfdata.Perfdata{
pl.Add(&check.Perfdata{
Label: "usage",
Value: overallMemoryUsageMB * 1024 * 1024, // Report in Bytes.
Uom: "B",
})
// percentage usage.
pl.Add(&perfdata.Perfdata{
pl.Add(&check.Perfdata{
Label: "usage_percent",
Value: memoryUsagePercent,
Uom: "%",
Expand All @@ -91,9 +93,5 @@ func queryMemory() {
}

dbConnection.Close()
check.Exitf(statusCode,
"Total Memory usage is %dGB (%d%%) | %s",
overallMemoryUsageMB/1024,
memoryUsagePercent,
pl.String())
check.ExitWithPerfdata(statusCode, pl, fmt.Sprintf("Total Memory usage is %dGB (%d%%)", overallMemoryUsageMB/1024, memoryUsagePercent))
}
11 changes: 5 additions & 6 deletions cmd/nic.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package cmd

import (
"fmt"

"github.com/NETWAYS/check_vspheredb_data/internal"

"github.com/NETWAYS/go-check"
"github.com/NETWAYS/go-check/perfdata"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -55,7 +57,7 @@ func queryNic() {
check.ExitError(err)
}

pl.Add(&perfdata.Perfdata{
pl.Add(&check.Perfdata{
Label: "nics",
Value: hardwareNumNICs,
Warn: nicWarnThreshold,
Expand All @@ -74,8 +76,5 @@ func queryNic() {
}

dbConnection.Close()
check.Exitf(statusCode,
"Number of NICs: %d | %s",
hardwareNumNICs,
pl.String())
check.ExitWithPerfdata(statusCode, pl, fmt.Sprintf("Number of NICs: %d)", hardwareNumNICs))
}
8 changes: 4 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package cmd

import (
"github.com/NETWAYS/check_vspheredb_data/internal"

"github.com/NETWAYS/go-check"
"github.com/NETWAYS/go-check/perfdata"
"github.com/spf13/cobra"
)

Expand All @@ -17,7 +17,7 @@ var password string
var credentialsFile string

// Helper vars.
var pl perfdata.PerfdataList
var pl check.PerfdataList

// rootCmd represents the base command when called without any subcommands.
var rootCmd = &cobra.Command{
Expand All @@ -36,13 +36,13 @@ Icinga2 admins to trigger alerts on their side of the monitoring.`,
if machine == "" {
cmd.DisableAutoGenTag = true

check.Exitf(check.Unknown, "Error: --machine flag is required")
check.Exit(check.Unknown, "Error: --machine flag is required")
}

if host == "" {
cmd.DisableAutoGenTag = true

check.Exitf(check.Unknown, "Error: --host flag is required")
check.Exit(check.Unknown, "Error: --host flag is required")
}
// Parse credentials file.
if credentialsFile != "" {
Expand Down
11 changes: 5 additions & 6 deletions cmd/temperature.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package cmd

import (
"fmt"

"github.com/NETWAYS/check_vspheredb_data/internal"

"github.com/NETWAYS/go-check"
"github.com/NETWAYS/go-check/perfdata"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -58,7 +60,7 @@ func queryTemperature() {
check.ExitError(err)
}

pl.Add(&perfdata.Perfdata{
pl.Add(&check.Perfdata{
Label: "temp",
Value: currentReading,
Uom: "C",
Expand All @@ -78,8 +80,5 @@ func queryTemperature() {
}

dbConnection.Close()
check.Exitf(statusCode,
"Temperature is %d°C | %s",
currentReading,
pl.String())
check.ExitWithPerfdata(statusCode, pl, fmt.Sprintf("Temperature is %d°C", currentReading))
}
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
module github.com/NETWAYS/check_vspheredb_data

go 1.24.0
go 1.26

require github.com/NETWAYS/go-check v0.6.4
require (
github.com/NETWAYS/go-check v1.0.0
github.com/go-sql-driver/mysql v1.10.0
github.com/spf13/cobra v1.10.2
)

require (
filippo.io/edwards25519 v1.2.0 // indirect
github.com/go-sql-driver/mysql v1.10.0
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.10 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
filippo.io/edwards25519 v1.2.0 h1:crnVqOiS4jqYleHd9vaKZ+HKtHfllngJIiOpNpoJsjo=
filippo.io/edwards25519 v1.2.0/go.mod h1:xzAOLCNug/yB62zG1bQ8uziwrIqIuxhctzJT18Q77mc=
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 h1:YkzTwFfGR+Z+mK3Wsqpnu8wibzsB30im19iPNfCOsMQ=
github.com/NETWAYS/go-check v1.0.0/go.mod h1:8/GWnq8SirreAixgRmcp82JG16NnEl38rHq9phICy9s=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/go-sql-driver/mysql v1.10.0 h1:Q+1LV8DkHJvSYAdR83XzuhDaTykuDx0l6fkXxoWCWfw=
github.com/go-sql-driver/mysql v1.10.0/go.mod h1:M+cqaI7+xxXGG9swrdeUIoPG3Y3KCkF0pZej+SK+nWk=
Expand Down