Skip to content

Commit

Permalink
Fix various golint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
martialblog committed Feb 22, 2024
1 parent c27adca commit 5d3ea36
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 29 deletions.
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ issues:
- path: 'snmp/snmpwalk.go'
linters:
- funlen
- path: 'hp/mib/cpq_sm_cntrl.go'
linters:
- golint

linters:
enable-all: true
disable:
- golint # TODO fix
- revive
- cyclop
- depguard
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ so we can provide you with a secure upload link, that won't be shared with publi

## Technical Details

Supported hardware is split into modules: [hp/cntlr](hp/cntlr) [hp/phy_drv](hp/phy_drv) [hp/ilo](hp/ilo)
Supported hardware is split into modules: [hp/cntlr](hp/cntlr) [hp/drive](hp/drive) [hp/ilo](hp/ilo)

Known models and affected firmware is documented in: [hp/cntlr/firmware_data.go](hp/cntlr/firmware_data.go) [hp/phy_drv/firmware_data.go](hp/phy_drv/firmware_data.go) [hp/ilo/firmware_data.go](hp/ilo/firmware_data.go)

Expand Down
6 changes: 3 additions & 3 deletions hp/cntlr/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

type Controller struct {
Id string
ID string
Model string
FwRev string
Serial string
Expand All @@ -24,7 +24,7 @@ func NewControllerFromTable(t *CpqDaCntlrTable, id string) (*Controller, error)
var err error

controller := &Controller{}
controller.Id = id
controller.ID = id

modelI, err := t.GetIntValue(id, mib.CpqDaCntlrModel)
if err != nil {
Expand Down Expand Up @@ -78,7 +78,7 @@ func GetControllersFromTable(t *CpqDaCntlrTable) ([]*Controller, error) {

func (d *Controller) GetNagiosStatus() (int, string) {
description := fmt.Sprintf("controller (%s) model=%s serial=%s firmware=%s",
d.Id, d.Model, strings.TrimSpace(d.Serial), d.FwRev)
d.ID, d.Model, strings.TrimSpace(d.Serial), d.FwRev)

if d.Status != "ok" {
return check.Critical, description + " - status: " + d.Status
Expand Down
3 changes: 2 additions & 1 deletion hp/cntlr/firmware_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cntlr

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

type testInfo struct {
Expand Down
8 changes: 4 additions & 4 deletions hp/phy_drv/drive.go → hp/drive/drive.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package phy_drv
package drive

import (
"fmt"
Expand All @@ -8,7 +8,7 @@ import (
)

type PhysicalDrive struct {
Id string
ID string
Model string
FwRev string
Serial string
Expand All @@ -24,7 +24,7 @@ func NewPhysicalDriveFromTable(t *CpqDaPhyDrvTable, id string) (*PhysicalDrive,
var err error

drive := &PhysicalDrive{
Id: id,
ID: id,
}

drive.Model, err = t.GetStringValue(id, mib.CpqDaPhyDrvModel)
Expand Down Expand Up @@ -78,7 +78,7 @@ func GetPhysicalDrivesFromTable(t *CpqDaPhyDrvTable) ([]*PhysicalDrive, error) {

func (d *PhysicalDrive) GetNagiosStatus() (int, string) {
description := fmt.Sprintf("physical drive (%-4s) model=%s serial=%s firmware=%s hours=%d",
d.Id, d.Model, d.Serial, d.FwRev, d.Hours)
d.ID, d.Model, d.Serial, d.FwRev, d.Hours)

if d.Status != "ok" {
return check.Critical, description + " - status: " + d.Status
Expand Down
7 changes: 4 additions & 3 deletions hp/phy_drv/drive_test.go → hp/drive/drive_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package phy_drv
package drive

import (
"testing"

"github.com/NETWAYS/go-check"
"github.com/stretchr/testify/assert"
"testing"
)

const affectedDrive = "VO0480JFDGT"
const affectedDriveFixed = "HPD8"

func TestPhysicalDrive_GetNagiosStatus(t *testing.T) {
drive := &PhysicalDrive{
Id: "1.1",
ID: "1.1",
Model: "OTHERDRIVE",
FwRev: "HPD1",
Serial: "ABC123",
Expand Down
2 changes: 1 addition & 1 deletion hp/phy_drv/drives.go → hp/drive/drives.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package phy_drv
package drive

import (
"github.com/NETWAYS/check_hp_firmware/hp/mib"
Expand Down
2 changes: 1 addition & 1 deletion hp/phy_drv/firmware.go → hp/drive/firmware.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package phy_drv
package drive

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion hp/phy_drv/firmware_data.go → hp/drive/firmware_data.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package phy_drv
package drive

// Source A: https://support.hpe.com/hpsc/doc/public/display?docId=emr_na-a00092491en_us
// Version: 2
Expand Down
5 changes: 3 additions & 2 deletions hp/phy_drv/firmware_test.go → hp/drive/firmware_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package phy_drv
package drive

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

const testModelA = "VO0480JFDGT"
Expand Down
3 changes: 2 additions & 1 deletion hp/ilo/firmware_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package ilo

import (
"testing"

"github.com/NETWAYS/go-check"
"github.com/stretchr/testify/assert"
"testing"
)

func TestIlo_GetNagiosStatus(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"time"

"github.com/NETWAYS/check_hp_firmware/hp/cntlr"
"github.com/NETWAYS/check_hp_firmware/hp/drive"
"github.com/NETWAYS/check_hp_firmware/hp/ilo"
"github.com/NETWAYS/check_hp_firmware/hp/phy_drv"
"github.com/NETWAYS/check_hp_firmware/snmp"
"github.com/NETWAYS/go-check"
"github.com/NETWAYS/go-check/result"
Expand Down Expand Up @@ -63,7 +63,7 @@ func main() {
var (
client gosnmp.Handler
cntlrTable *cntlr.CpqDaCntlrTable
driveTable *phy_drv.CpqDaPhyDrvTable
driveTable *drive.CpqDaPhyDrvTable
)

var err error
Expand Down Expand Up @@ -112,7 +112,7 @@ func main() {
}

// Load drive data
driveTable, err = phy_drv.GetCpqDaPhyDrvTable(client)
driveTable, err = drive.GetCpqDaPhyDrvTable(client)
if err != nil {
check.ExitError(err)
}
Expand All @@ -130,7 +130,7 @@ func main() {
check.ExitRaw(3, "No HP drive data found!")
}

drives, err := phy_drv.GetPhysicalDrivesFromTable(driveTable)
drives, err := drive.GetPhysicalDrivesFromTable(driveTable)
if err != nil {
check.ExitError(err)
}
Expand All @@ -154,7 +154,7 @@ func main() {

overall.Add(controllerStatus, desc)

countControllers += 1
countControllers++
}

countDrives := 0
Expand All @@ -164,7 +164,7 @@ func main() {

overall.Add(driveStatus, desc)

countDrives += 1
countDrives++
}

var summary string
Expand Down
3 changes: 2 additions & 1 deletion snmp/file_handler_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package snmp

import (
"testing"

"github.com/gosnmp/gosnmp"
"github.com/stretchr/testify/assert"
"testing"
)

func TestNewFileHandlerFromFile(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion snmp/snmpwalk_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package snmp

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

const testWalkLength = 242
Expand Down
5 changes: 3 additions & 2 deletions snmp/util_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package snmp

import (
"github.com/gosnmp/gosnmp"
"github.com/stretchr/testify/assert"
"os"
"testing"

"github.com/gosnmp/gosnmp"
"github.com/stretchr/testify/assert"
)

func TestIsOid(t *testing.T) {
Expand Down

0 comments on commit 5d3ea36

Please sign in to comment.