-
Notifications
You must be signed in to change notification settings - Fork 1
Add netgear plugin #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DsgnrFH
wants to merge
20
commits into
main
Choose a base branch
from
feature/restructure-into-several-packages-3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c1a14b0
Add netgear plugin
DsgnrFH ee0c4b6
Addressed some more comments and advises
DsgnrFH f59579e
Addressed even more suggestions
DsgnrFH 16bec4c
Fixed main
DsgnrFH 59fc002
Removed unused import
DsgnrFH 21a2504
Addressed more comments
DsgnrFH abaf5d6
change types to reflect what is actually sent by the switch
TheSyscall 560b872
add error handling
TheSyscall 2061cce
move getting of values to where we know that we actually need them
TheSyscall 83d9f22
Use "basic" mode as default, but allow others to override it
TheSyscall 287064a
explicitly require username and password
TheSyscall 4372e2f
fix typo "Temperatuer"
TheSyscall e2d39c7
rename "hostName" to "baseUrl"
TheSyscall 71b19fe
move modes into their own functions
TheSyscall 0623be8
check array length before access
TheSyscall 9864e20
add notice for missing pagination
TheSyscall 17efd16
combine all checks into a single overall output
TheSyscall 9643ed1
make perfdata optional
TheSyscall cacd4de
show an error when no mode was executed
TheSyscall 97cbfc2
Apply suggestions from code review
TheSyscall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| module github.com/icinga/check-netgear | ||
|
|
||
| go 1.25 | ||
|
|
||
| require github.com/NETWAYS/go-check v0.6.3 | ||
|
|
||
| require github.com/spf13/pflag v1.0.10 // indirect |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| github.com/NETWAYS/go-check v0.6.3 h1:Rcunu4JvlulbKjIef1H4pUiFO88atANpJ1YAqIwcJxI= | ||
| github.com/NETWAYS/go-check v0.6.3/go.mod h1:8/GWnq8SirreAixgRmcp82JG16NnEl38rHq9phICy9s= | ||
| github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= | ||
| github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,197 @@ | ||
| package checks | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "slices" | ||
|
|
||
| "github.com/NETWAYS/go-check" | ||
| "github.com/NETWAYS/go-check/perfdata" | ||
| "github.com/NETWAYS/go-check/result" | ||
| "github.com/icinga/check-netgear/internal/utils" | ||
| "github.com/icinga/check-netgear/netgear" | ||
| ) | ||
|
|
||
| // CheckCPU creates a partialResult with the CPU information | ||
| func CheckCPU(cpuUsage float64, noPerfdata bool, warn float64, crit float64) (*result.PartialResult, error) { | ||
| status := utils.StatusByThreshold(cpuUsage, warn, crit) | ||
| partial := result.PartialResult{ | ||
| Output: fmt.Sprintf("CPU Usage: %.2f%%", cpuUsage), | ||
| } | ||
| if err := partial.SetState(status); err != nil { | ||
| return nil, err | ||
| } | ||
| if !noPerfdata { | ||
| partial.Perfdata.Add(&perfdata.Perfdata{Label: "CPU", Value: cpuUsage, Min: 0, Max: 100}) | ||
| } | ||
| return &partial, nil | ||
| } | ||
|
|
||
| // CheckMemory creates a partialResult with the memory information | ||
| func CheckMemory(memUsage float64, noPerfdata bool, warn float64, crit float64) (*result.PartialResult, error) { | ||
| status := utils.StatusByThreshold(memUsage, warn, crit) | ||
| partial := result.PartialResult{ | ||
| Output: fmt.Sprintf("RAM Usage: %.2f%%", memUsage), | ||
| } | ||
| if err := partial.SetState(status); err != nil { | ||
| return nil, err | ||
| } | ||
| if !noPerfdata { | ||
| partial.Perfdata.Add(&perfdata.Perfdata{Label: "RAM", Value: memUsage, Min: 0, Max: 100}) | ||
| } | ||
| return &partial, nil | ||
| } | ||
|
|
||
| // CheckTemperature creates a partialResult with the temperature information | ||
| func CheckTemperature(sensors []netgear.SensorDetail, noPerfdata bool, warn float64, crit float64) (*result.PartialResult, error) { | ||
| partial := result.PartialResult{Output: "Temperature"} | ||
| worst := check.OK | ||
|
|
||
| for _, s := range sensors { | ||
| status := utils.StatusByThreshold(s.Temperature, warn, crit) | ||
| if status > worst { | ||
| worst = status | ||
| } | ||
|
|
||
| sub := result.PartialResult{ | ||
| Output: fmt.Sprintf("%s: %.1f°C", s.Description, s.Temperature), | ||
| } | ||
| if err := sub.SetState(status); err != nil { | ||
| return nil, err | ||
| } | ||
| if !noPerfdata { | ||
| sub.Perfdata.Add(&perfdata.Perfdata{Label: s.Description, Value: s.Temperature, Min: 0}) | ||
| } | ||
| partial.AddSubcheck(sub) | ||
| } | ||
|
|
||
| if err := partial.SetState(worst); err != nil { | ||
| return nil, err | ||
| } | ||
| return &partial, nil | ||
| } | ||
|
|
||
| // CheckFans creates a partialResult with the fans information | ||
| func CheckFans(noPerfdata bool, fanName string, fanSpeed float64, warn float64, crit float64) (*result.PartialResult, error) { | ||
| status := utils.StatusByThreshold(fanSpeed, warn, crit) | ||
|
|
||
| partial := result.PartialResult{Output: "Fans"} | ||
| sub := result.PartialResult{ | ||
| Output: fmt.Sprintf("%s: %.0f RPM", fanName, fanSpeed), | ||
| } | ||
| if err := sub.SetState(status); err != nil { | ||
| return nil, err | ||
| } | ||
| if !noPerfdata { | ||
| sub.Perfdata.Add(&perfdata.Perfdata{Label: "Fan Speed", Value: fanSpeed, Min: 0}) | ||
| } | ||
| partial.AddSubcheck(sub) | ||
| if err := partial.SetState(status); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return &partial, nil | ||
| } | ||
|
|
||
| // CheckPorts creates a partialResult with the port information | ||
| func CheckPorts(inRows, outRows []netgear.PortStatisticRow, portsToCheck []int, noPerfdata bool, warn float64, crit float64) (*result.PartialResult, error) { | ||
| overall := result.PartialResult{Output: "Ports Statistics"} | ||
| worst := check.OK | ||
|
|
||
| for i := range inRows { | ||
| in := inRows[i] | ||
| out := outRows[i] | ||
|
|
||
| if !slices.Contains(portsToCheck, in.Port) { | ||
| continue | ||
| } | ||
|
|
||
| portCheck := result.PartialResult{Output: fmt.Sprintf("Port %v", in.Port)} | ||
|
|
||
| inLoss := utils.LossPercent(in.InDropPkts, in.InTotalPkts) | ||
| outLoss := utils.LossPercent(out.OutDropPkts, out.OutTotalPkts) | ||
|
|
||
| inStatus := utils.StatusByThreshold(inLoss, warn, crit) | ||
| outStatus := utils.StatusByThreshold(outLoss, warn, crit) | ||
|
|
||
| portStatus := max(inStatus, outStatus) | ||
| worst = max(worst, portStatus) | ||
|
|
||
| addPerfSubcheck := func(label string, loss float64, status int) error { | ||
| sub := result.PartialResult{ | ||
| Output: fmt.Sprintf("%s: %.2f%% loss", label, loss), | ||
| } | ||
| if err := sub.SetState(status); err != nil { | ||
| return err | ||
| } | ||
| if !noPerfdata { | ||
| sub.Perfdata.Add(&perfdata.Perfdata{ | ||
| Label: fmt.Sprintf("port %v %s loss", in.Port, label), | ||
| Value: loss, Min: 0, Max: 100, | ||
| }) | ||
| } | ||
| portCheck.AddSubcheck(sub) | ||
| return nil | ||
| } | ||
|
|
||
| if err := addPerfSubcheck("IN", inLoss, inStatus); err != nil { | ||
| return nil, err | ||
| } | ||
| if err := addPerfSubcheck("OUT", outLoss, outStatus); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| if err := portCheck.SetState(portStatus); err != nil { | ||
| return nil, err | ||
| } | ||
| overall.AddSubcheck(portCheck) | ||
| } | ||
|
|
||
| if err := overall.SetState(worst); err != nil { | ||
| return nil, err | ||
| } | ||
| return &overall, nil | ||
| } | ||
|
|
||
| // CheckPoe creates a partialResult with information about every port's POE status | ||
| func CheckPoe(ports []netgear.PoePort, noPerfdata bool) (*result.PartialResult, error) { | ||
| partial := result.PartialResult{Output: "Power over Ethernet Statistics"} | ||
| worst := check.OK | ||
|
|
||
| for _, port := range ports { | ||
| state := "disabled" | ||
| if port.Enable { | ||
| state = "enabled" | ||
| } | ||
|
|
||
| status := check.OK | ||
| if port.CurrentPower > port.PowerLimit { | ||
| status = check.Critical | ||
| } else if port.CurrentPower == port.PowerLimit { | ||
| status = check.Warning | ||
| } | ||
|
|
||
| worst = max(worst, status) | ||
|
|
||
| poeCheck := result.PartialResult{ | ||
| Output: fmt.Sprintf( | ||
| "Port %v is %v. Current power: %.2f/%.2fV", | ||
| port.Port, state, port.CurrentPower/1000, port.PowerLimit/1000, | ||
| ), | ||
| } | ||
| if err := poeCheck.SetState(status); err != nil { | ||
| return nil, err | ||
| } | ||
| if !noPerfdata { | ||
| poeCheck.Perfdata.Add(&perfdata.Perfdata{ | ||
| Label: fmt.Sprintf("port %v power", port.Port), | ||
| Value: port.CurrentPower, Min: 0, Max: port.PowerLimit, | ||
| }) | ||
| } | ||
| partial.AddSubcheck(poeCheck) | ||
| } | ||
|
|
||
| if err := partial.SetState(worst); err != nil { | ||
| return nil, err | ||
| } | ||
| return &partial, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package utils | ||
|
|
||
| import "github.com/NETWAYS/go-check" | ||
|
|
||
| func StatusByThreshold(value, warn, crit float64) int { | ||
| switch { | ||
| case value >= crit: | ||
| return check.Critical | ||
| case value >= warn: | ||
| return check.Warning | ||
| default: | ||
| return check.OK | ||
| } | ||
| } | ||
|
|
||
| func LossPercent(drop, total float64) float64 { | ||
| if total <= 0 { | ||
| return 0 | ||
| } | ||
| return drop / total * 100 | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.