Skip to content

Conversation

@DsgnrFH
Copy link
Collaborator

@DsgnrFH DsgnrFH commented Nov 6, 2025

Squashed commits from main and from before

@DsgnrFH DsgnrFH requested review from oxzi and yhabteab November 6, 2025 11:22
@DsgnrFH DsgnrFH self-assigned this Nov 6, 2025
@cla-bot cla-bot bot added the cla/signed CLA is signed by all contributors of a PR label Nov 6, 2025
@yhabteab
Copy link
Member

yhabteab commented Nov 6, 2025

Sorry @oxzi, it's my fault :)! After force purshing to the main branch GitHub automatically closed #4 and can't also be reopened.

@oxzi
Copy link
Member

oxzi commented Nov 6, 2025

Sorry @oxzi, it's my fault :)! After force purshing to the main branch GitHub automatically closed #4 and can't also be reopened.

Happens, I guess (:

@DsgnrFH: By having a new PR, all my old comments are now kinda void. Could you nevertheless comment under each of my comments in the other PR #4 if you have addressed it? I am going to take a closer look at this PR within this week, most likely tomorrow.

@DsgnrFH
Copy link
Collaborator Author

DsgnrFH commented Nov 7, 2025

Sorry @oxzi, it's my fault :)! After force purshing to the main branch GitHub automatically closed #4 and can't also be reopened.

Happens, I guess (:

@DsgnrFH: By having a new PR, all my old comments are now kinda void. Could you nevertheless comment under each of my comments in the other PR #4 if you have addressed it? I am going to take a closer look at this PR within this week, most likely tomorrow.

I believe I have addressed everything you suggested

@DsgnrFH DsgnrFH requested a review from yhabteab November 7, 2025 14:42
Copy link
Member

@yhabteab yhabteab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oxzi these are my last review comments, so you can also have look at this, I won't intervene further :-)

Comment on lines +129 to +130
addPerfSubcheck("IN", inLoss, inStatus)
addPerfSubcheck("OUT", outLoss, outStatus)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
addPerfSubcheck("IN", inLoss, inStatus)
addPerfSubcheck("OUT", outLoss, outStatus)
if err := addPerfSubcheck("IN", inLoss, inStatus); err != nil {
return nil, err
}
if err := addPerfSubcheck("OUT", outLoss, outStatus); err != nil {
return nil, err
}

hidetemp := flag.Bool("notemp", false, "Hide the Temperature info")
hidefans := flag.Bool("nofans", false, "Hide the Fans info")

var mode stringSliceFlag = []string{"basic"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var mode stringSliceFlag = []string{"basic"}
mode := stringSliceFlag{"basic"}

statsWarn := flag.Float64("stats-warning", 5, "Port stats warning threshold")
statsCrit := flag.Float64("stats-critical", 20, "Port stats critical threshold")

var portsToCheck intSliceFlag = []int{1, 2, 3, 4, 5, 6, 7, 8}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var portsToCheck intSliceFlag = []int{1, 2, 3, 4, 5, 6, 7, 8}
portsToCheck := intSliceFlag{1, 2, 3, 4, 5, 6, 7, 8}

Comment on lines +108 to +109
cpuUsage, _ := netgear.StringPercentToFloat(deviceInfo.DeviceInfo.Cpu[0].Usage)
memUsage, _ := netgear.StringPercentToFloat(deviceInfo.DeviceInfo.Memory[0].Usage)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're still ignoring errors.

Comment on lines +77 to +80
if *help || *username == "" || *password == "" {
flag.Usage()
return
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would split these up in two cases. If someone request the help, it's okay. However, if someone forgets to set credentials - or they somehow get lost along the way -, it is an error.

Suggested change
if *help || *username == "" || *password == "" {
flag.Usage()
return
}
if *help {
flag.Usage()
return
}
if *username == "" || *password == "" {
fmt.Println("Both username and password are required")
os.Exit(check.Unknown)
}

Comment on lines +107 to +113
upTime := deviceInfo.DeviceInfo.Details[0].Uptime
cpuUsage, _ := netgear.StringPercentToFloat(deviceInfo.DeviceInfo.Cpu[0].Usage)
memUsage, _ := netgear.StringPercentToFloat(deviceInfo.DeviceInfo.Memory[0].Usage)
fan := deviceInfo.DeviceInfo.Fan[0].Details[0]
fanName := fan.Description
fanSpeed := fan.Speed
sensorDetails := deviceInfo.DeviceInfo.Sensor[0].Details
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that there is always an element at index 0? What if the API slightly changes or something along the way has a bad day.

Please consider checking if the slice is long enough before accessing something. Otherwise, if you say that this MUST work, consider adding a deferred recover() call, which prints the error and exits with UNKNOWN.

tempPartial, err := checks.CheckTemperature(sensorDetails, *tempWarn, *tempCrit)
if err != nil {
errRes := result.NewPartialResult()
errRes.Output = fmt.Sprintf("Temperatuer check error: %v", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
errRes.Output = fmt.Sprintf("Temperatuer check error: %v", err)
errRes.Output = fmt.Sprintf("Temperature check error: %v", err)

Comment on lines +116 to +123
const defaultPageIndex = 1
const defaultPageSize = 25

u := n.baseUrl.JoinPath("port_statistics")
q := u.Query()
q.Set("type", statType)
q.Set("indexPage", strconv.Itoa(defaultPageIndex))
q.Set("pageSize", strconv.Itoa(defaultPageSize))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As commented in the old PR, this pagination looks a bit weird.

What about ports on page 2? Can there be a second page? Does this mean we are only getting information about 25 ports? If so, lots of switches would miss information.

Comment on lines +26 to +27
func NewNetgear(hostName, username, password string) (*Netgear, error) {
u, err := url.Parse(strings.TrimSpace(hostName))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#4 (comment)

Suggested change
func NewNetgear(hostName, username, password string) (*Netgear, error) {
u, err := url.Parse(strings.TrimSpace(hostName))
func NewNetgear(baseUrl, username, password string) (*Netgear, error) {
u, err := url.Parse(strings.TrimSpace(baseUrl))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla/signed CLA is signed by all contributors of a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants