From ed561050deebff14f224982b06125702153861b6 Mon Sep 17 00:00:00 2001 From: Markus Opolka Date: Mon, 2 Oct 2023 10:31:36 +0200 Subject: [PATCH 1/4] Update goreleaser config --- .goreleaser.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 7eeb780..c4ff871 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -17,16 +17,18 @@ builds: -X main.commit={{.Commit}} -X main.date={{.CommitDate}} release: + draft: true github: owner: NETWAYS name: check_hp_firmware archives: - format: binary - replacements: - darwin: Darwin - linux: Linux - windows: Windows - amd64: x86_64 + name_template: >- + {{ .ProjectName }}_{{ .Tag }}_ + {{- if eq .Os "linux" }}Linux{{ end }} + {{- if eq .Os "windows" }}Windows{{ end }} + {{- if eq .Os "darwin" }}Darwin{{ end }} + {{- if eq .Arch "amd64" }}_x86_64{{ end }} checksum: name_template: 'checksums.txt' snapshot: From c1457679d2f5701a461e66b2fe3921cc9335bc04 Mon Sep 17 00:00:00 2001 From: Markus Opolka Date: Mon, 2 Oct 2023 10:31:45 +0200 Subject: [PATCH 2/4] Move icinga.conf to contrib/ --- icinga2.conf => contrib/icinga2.conf | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename icinga2.conf => contrib/icinga2.conf (100%) diff --git a/icinga2.conf b/contrib/icinga2.conf similarity index 100% rename from icinga2.conf rename to contrib/icinga2.conf From 18558526fa3b45097bf45734235d1e9b54f03d87 Mon Sep 17 00:00:00 2001 From: Markus Opolka Date: Mon, 2 Oct 2023 10:50:26 +0200 Subject: [PATCH 3/4] Update golangci config and fix issues --- .github/workflows/build.yml | 2 +- .github/workflows/golangci-lint.yml | 2 +- .golangci.yml | 64 +++++++++++++++++++++-------- hp/cntlr/controller.go | 5 ++- hp/cntlr/firmware_data.go | 2 +- hp/ilo/firmware.go | 1 + hp/mib/cpq_da_cntrl.go | 1 - hp/mib/cpq_da_phy_drv.go | 1 - hp/mib/cpq_sm_cntrl.go | 1 - hp/phy_drv/drive.go | 6 ++- hp/phy_drv/firmware.go | 2 +- hp/phy_drv/firmware_data.go | 4 +- main.go | 5 ++- snmp/file_handler.go | 6 ++- snmp/snmpwalk.go | 5 ++- snmp/table.go | 8 ++-- snmp/util.go | 7 +--- 17 files changed, 80 insertions(+), 42 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f9acc10..188277a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: 1.19 + go-version: 1.21 - name: Vet run: go vet ./... diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index a83d6c4..b4c46db 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -17,4 +17,4 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.51 + version: v1.54 diff --git a/.golangci.yml b/.golangci.yml index c50846a..d83a858 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,19 +1,51 @@ run: - deadline: 1m + timeout: 5m + tests: false + +issues: + exclude-rules: + - path: 'hp/' + linters: + - nosnakecase + - stylecheck + - path: 'main.go' + linters: + - nosnakecase + - path: 'hp/ilo/firmware.go' + linters: + - wastedassign linters: - disable-all: false - enable: - # - funlen - - dogsled - - dupl - - lll - - whitespace - - wsl - disable: - - govet # temporary - presets: - - bugs - - unused - # - style - fast: false + enable-all: true + disable: + - golint # TODO fix + - revive + - cyclop + - depguard + - dupl + - exhaustivestruct + - exhaustruct + - forbidigo + - forcetypeassert + - gci + - gochecknoglobals + - gochecknoinits + - godot + - godox + - goerr113 + - gofumpt + - gomnd + - lll + - musttag + - nakedret + - nlreturn + - nolintlint + - nonamedreturns + - tagliatelle + - varnamelen + - wrapcheck +linters-settings: + estif: + min-complexity: 4 + maligned: + suggest-new: true diff --git a/hp/cntlr/controller.go b/hp/cntlr/controller.go index 667f170..0cca4b5 100644 --- a/hp/cntlr/controller.go +++ b/hp/cntlr/controller.go @@ -2,9 +2,10 @@ package cntlr import ( "fmt" + "strings" + "github.com/NETWAYS/check_hp_firmware/hp/mib" "github.com/NETWAYS/go-check" - "strings" ) type Controller struct { @@ -61,7 +62,7 @@ func NewControllerFromTable(t *CpqDaCntlrTable, id string) (*Controller, error) } func GetControllersFromTable(t *CpqDaCntlrTable) ([]*Controller, error) { - var controllers []*Controller + controllers := make([]*Controller, 0, len(t.ListIds())) for _, id := range t.ListIds() { controller, err := NewControllerFromTable(t, id) diff --git a/hp/cntlr/firmware_data.go b/hp/cntlr/firmware_data.go index d971969..f84705a 100644 --- a/hp/cntlr/firmware_data.go +++ b/hp/cntlr/firmware_data.go @@ -11,7 +11,7 @@ var VersionAffectedRaid5 = []string{"1.98", "1.99", "2.02", "2.03"} const VersionFixed = "2.65" -//AffectedModelList list of model numbers for controllers +// AffectedModelList list of model numbers for controllers var AffectedModelList = []*AffectedModel{ {"e208i-p"}, {"e208i-a"}, diff --git a/hp/ilo/firmware.go b/hp/ilo/firmware.go index 4f8cf01..b74a382 100644 --- a/hp/ilo/firmware.go +++ b/hp/ilo/firmware.go @@ -2,6 +2,7 @@ package ilo import ( "fmt" + "github.com/NETWAYS/check_hp_firmware/hp/mib" "github.com/NETWAYS/go-check" "github.com/gosnmp/gosnmp" diff --git a/hp/mib/cpq_da_cntrl.go b/hp/mib/cpq_da_cntrl.go index 8177613..7001bf1 100644 --- a/hp/mib/cpq_da_cntrl.go +++ b/hp/mib/cpq_da_cntrl.go @@ -1,6 +1,5 @@ package mib -//noinspection GoUnusedConst,SpellCheckingInspection const ( CpqDaCntlrTable = `.1.3.6.1.4.1.232.3.2.2.1` CpqDaCntlrEntry = `.1.3.6.1.4.1.232.3.2.2.1.1` diff --git a/hp/mib/cpq_da_phy_drv.go b/hp/mib/cpq_da_phy_drv.go index c30be7e..25a2199 100644 --- a/hp/mib/cpq_da_phy_drv.go +++ b/hp/mib/cpq_da_phy_drv.go @@ -1,6 +1,5 @@ package mib -//noinspection GoUnusedConst,SpellCheckingInspection const ( CpqDaPhyDrvTable = `.1.3.6.1.4.1.232.3.2.5.1` CpqDaPhyDrvCntlrIndex = `.1.3.6.1.4.1.232.3.2.5.1.1.1` diff --git a/hp/mib/cpq_sm_cntrl.go b/hp/mib/cpq_sm_cntrl.go index 3e4e7e9..3358f84 100644 --- a/hp/mib/cpq_sm_cntrl.go +++ b/hp/mib/cpq_sm_cntrl.go @@ -1,6 +1,5 @@ package mib -//noinspection GoUnusedConst,SpellCheckingInspection const ( CpqSm2Cntlr = `.1.3.6.1.4.1.232.9.2.2` CpqSm2CntlrRomDate = `.1.3.6.1.4.1.232.9.2.2.1` diff --git a/hp/phy_drv/drive.go b/hp/phy_drv/drive.go index 3e6ceca..cdd27e3 100644 --- a/hp/phy_drv/drive.go +++ b/hp/phy_drv/drive.go @@ -2,6 +2,7 @@ package phy_drv import ( "fmt" + "github.com/NETWAYS/check_hp_firmware/hp/mib" "github.com/NETWAYS/go-check" ) @@ -16,7 +17,7 @@ type PhysicalDrive struct { } func NewPhysicalDriveFromTable(t *CpqDaPhyDrvTable, id string) (*PhysicalDrive, error) { - if _, ok := t.Snmp.Values[id];!ok { + if _, ok := t.Snmp.Values[id]; !ok { return nil, fmt.Errorf("could not find drive %s in table", id) } @@ -61,7 +62,7 @@ func NewPhysicalDriveFromTable(t *CpqDaPhyDrvTable, id string) (*PhysicalDrive, } func GetPhysicalDrivesFromTable(t *CpqDaPhyDrvTable) ([]*PhysicalDrive, error) { - var drives []*PhysicalDrive + drives := make([]*PhysicalDrive, 0, len(t.ListIds())) for _, id := range t.ListIds() { drive, err := NewPhysicalDriveFromTable(t, id) @@ -85,6 +86,7 @@ func (d *PhysicalDrive) GetNagiosStatus() (int, string) { if model, affected := AffectedModels[d.Model]; affected { ok, err := IsFirmwareFixed(model, d.FwRev) + // nolint: gocritic if err != nil { return check.Unknown, description + " - error: " + err.Error() } else if ok { diff --git a/hp/phy_drv/firmware.go b/hp/phy_drv/firmware.go index dba2700..2a0a046 100644 --- a/hp/phy_drv/firmware.go +++ b/hp/phy_drv/firmware.go @@ -16,7 +16,7 @@ type AffectedIndex map[string]*AffectedModel var ( AffectedModels = AffectedIndex{} - versionRE = regexp.MustCompile(`^([A-Z]+)([0-9]+)$`) + versionRE = regexp.MustCompile(`^([A-Z]+)([0-9]+)$`) ) func init() { diff --git a/hp/phy_drv/firmware_data.go b/hp/phy_drv/firmware_data.go index 01523d2..d26cdd9 100644 --- a/hp/phy_drv/firmware_data.go +++ b/hp/phy_drv/firmware_data.go @@ -12,7 +12,7 @@ const FixedA = "HPD8" const FixedB = "HPD7" -//AffectedModelList list of model numbers for drives that are affected with their description as value +// AffectedModelList list of model numbers for drives that are affected with their description as value var AffectedModelList = []*AffectedModel{ // Drives from bulletin A {"VO0480JFDGT", "HP 480 GB 12 Gbit SAS 2.5\" RI PLP SC SSD", FixedA}, @@ -33,7 +33,7 @@ var AffectedModelList = []*AffectedModel{ {"VK001920JWSSR", "HPE 1,92 TB SAS RI SFF SC DS SSD", FixedA}, {"VK003840JWSST", "HPE 3,84 TB SAS RI SFF SC DS SSD", FixedA}, // duplicate - //{"VK003840JWSST", "HPE 3,84 TB SAS RI LFF SCC DS SPL SSD", FixedA}, + // {"VK003840JWSST", "HPE 3,84 TB SAS RI LFF SCC DS SPL SSD", FixedA}, {"VK007680JWSSU", "HPE 7,68 TB SAS RI SFF SC DS SSD", FixedA}, {"VO015300JWSSV", "HPE 15,3 TB SAS RI SFF SC DS SSD", FixedA}, diff --git a/main.go b/main.go index e26d73a..24eefb8 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,8 @@ package main import ( "fmt" + "time" + "github.com/NETWAYS/check_hp_firmware/hp/cntlr" "github.com/NETWAYS/check_hp_firmware/hp/ilo" "github.com/NETWAYS/check_hp_firmware/hp/phy_drv" @@ -9,7 +11,6 @@ import ( "github.com/NETWAYS/go-check" "github.com/NETWAYS/go-check/result" "github.com/gosnmp/gosnmp" - "time" ) const Readme = ` @@ -66,6 +67,7 @@ affected hardware. There is ABSOLUTELY NO WARRANTY, see the license! ` // Check for HP Controller CVEs via SNMP +// nolint: funlen func main() { config := check.NewConfig() config.Name = "check_hp_firmware" @@ -117,6 +119,7 @@ func main() { } // Initialize connection + // nolint: gocritic if *ipv4 { err = client.ConnectIPv4() } else if *ipv6 { diff --git a/snmp/file_handler.go b/snmp/file_handler.go index ed086dd..5c709cd 100644 --- a/snmp/file_handler.go +++ b/snmp/file_handler.go @@ -2,15 +2,17 @@ package snmp import ( "fmt" - "github.com/gosnmp/gosnmp" "io" "os" + + "github.com/gosnmp/gosnmp" ) // Provides a GoSNMP like data interface, but with data from a snmpwalk output // // Anyone can generate an output by running: -// snmpwalk -c public -v2c -On HOST .1.3.6.1 >snmp-data.txt +// +// snmpwalk -c public -v2c -On HOST .1.3.6.1 >snmp-data.txt // // Warning: This does not implement all functions of gosnmp.Handler type FileHandler struct { diff --git a/snmp/snmpwalk.go b/snmp/snmpwalk.go index 2532a89..5173323 100644 --- a/snmp/snmpwalk.go +++ b/snmp/snmpwalk.go @@ -4,11 +4,12 @@ import ( "bufio" "encoding/hex" "fmt" - "github.com/gosnmp/gosnmp" "io" "regexp" "strconv" "strings" + + "github.com/gosnmp/gosnmp" ) var ( @@ -49,12 +50,12 @@ func ReadWalk(r io.Reader) (pduList WalkData, err error) { return } +// nolint: funlen func ParseWalkLine(line string) (pdu *gosnmp.SnmpPDU, err error) { parts := strings.SplitN(line, " = ", 2) if len(parts) != 2 || !IsOid(parts[0]) { // TODO: This can be the case for wrapped Hex-STRING lines, we are ignoring it for now... - //err = fmt.Errorf("not a key = value line") return } diff --git a/snmp/table.go b/snmp/table.go index 5177809..3a48f2e 100644 --- a/snmp/table.go +++ b/snmp/table.go @@ -2,11 +2,12 @@ package snmp import ( "fmt" + "sort" + "strings" + "github.com/gosnmp/gosnmp" "github.com/mcuadros/go-version" log "github.com/sirupsen/logrus" - "sort" - "strings" ) type Table struct { @@ -141,7 +142,8 @@ func (t *Table) GetIntValue(id string, oid string) (int, error) { } func (t *Table) GetSortedOIDs() []string { - var ids []string + ids := make([]string, 0, len(t.Values)) + for k := range t.Values { ids = append(ids, k) } diff --git a/snmp/util.go b/snmp/util.go index b289ce1..457fc91 100644 --- a/snmp/util.go +++ b/snmp/util.go @@ -2,6 +2,7 @@ package snmp import ( "fmt" + "github.com/gosnmp/gosnmp" ) @@ -24,11 +25,7 @@ func IsOid(oid string) bool { lastChar = char } - if lastChar == '.' { - return false - } - - return true + return lastChar != '.' } // IsOidPartOf tests if an OID is equal of below another OID From 81fafa4f32faaf35a47652fb20cb2cbedb01be7b Mon Sep 17 00:00:00 2001 From: Markus Opolka Date: Mon, 2 Oct 2023 10:51:03 +0200 Subject: [PATCH 4/4] Bump go.mod to 1.21 --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 2f2e790..3da8565 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/NETWAYS/check_hp_firmware -go 1.19 +go 1.21 require ( github.com/NETWAYS/go-check v0.5.0