Skip to content

Commit

Permalink
Merge pull request #74 from NETWAYS/chore/bump-go
Browse files Browse the repository at this point in the history
Bump Go to 1.21
  • Loading branch information
martialblog authored Oct 2, 2023
2 parents 059c66a + 81fafa4 commit 0a4ca32
Show file tree
Hide file tree
Showing 20 changed files with 88 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
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@v3
with:
version: v1.51
version: v1.54
64 changes: 48 additions & 16 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 7 additions & 5 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions hp/cntlr/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion hp/cntlr/firmware_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
1 change: 1 addition & 0 deletions hp/ilo/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion hp/mib/cpq_da_cntrl.go
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
1 change: 0 additions & 1 deletion hp/mib/cpq_da_phy_drv.go
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
1 change: 0 additions & 1 deletion hp/mib/cpq_sm_cntrl.go
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
6 changes: 4 additions & 2 deletions hp/phy_drv/drive.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package phy_drv

import (
"fmt"

"github.com/NETWAYS/check_hp_firmware/hp/mib"
"github.com/NETWAYS/go-check"
)
Expand All @@ -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)
}

Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion hp/phy_drv/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions hp/phy_drv/firmware_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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},

Expand Down
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ 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"
"github.com/NETWAYS/check_hp_firmware/snmp"
"github.com/NETWAYS/go-check"
"github.com/NETWAYS/go-check/result"
"github.com/gosnmp/gosnmp"
"time"
)

const Readme = `
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -117,6 +119,7 @@ func main() {
}

// Initialize connection
// nolint: gocritic
if *ipv4 {
err = client.ConnectIPv4()
} else if *ipv6 {
Expand Down
6 changes: 4 additions & 2 deletions snmp/file_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions snmp/snmpwalk.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"bufio"
"encoding/hex"
"fmt"
"github.com/gosnmp/gosnmp"
"io"
"regexp"
"strconv"
"strings"

"github.com/gosnmp/gosnmp"
)

var (
Expand Down Expand Up @@ -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
}

Expand Down
8 changes: 5 additions & 3 deletions snmp/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
7 changes: 2 additions & 5 deletions snmp/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package snmp

import (
"fmt"

"github.com/gosnmp/gosnmp"
)

Expand All @@ -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
Expand Down

0 comments on commit 0a4ca32

Please sign in to comment.