Skip to content

Commit

Permalink
Refactor to only use hashicorp/go-version
Browse files Browse the repository at this point in the history
 - Removes the github.com/mcuadros/go-version dependency
  • Loading branch information
martialblog committed Feb 12, 2024
1 parent 22b89c3 commit 542701c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/NETWAYS/go-check v0.6.1
github.com/gosnmp/gosnmp v1.37.0
github.com/hashicorp/go-version v1.6.0
github.com/mcuadros/go-version v0.0.0-20190830083331-035f6764e8d2
github.com/stretchr/testify v1.8.4
)

Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ github.com/gosnmp/gosnmp v1.37.0 h1:/Tf8D3b9wrnNuf/SfbvO+44mPrjVphBhRtcGg22V07Y=
github.com/gosnmp/gosnmp v1.37.0/go.mod h1:GDH9vNqpsD7f2HvZhKs5dlqSEcAS6s6Qp099oZRCR+M=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/mcuadros/go-version v0.0.0-20190830083331-035f6764e8d2 h1:YocNLcTBdEdvY3iDK6jfWXvEaM5OCKkjxPKoJRdB3Gg=
github.com/mcuadros/go-version v0.0.0-20190830083331-035f6764e8d2/go.mod h1:76rfSfYPWj01Z85hUf/ituArm797mNKcvINh1OlsZKo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
Expand Down
14 changes: 10 additions & 4 deletions hp/cntlr/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cntlr

import (
"github.com/NETWAYS/go-check"
"github.com/mcuadros/go-version"
"github.com/hashicorp/go-version"
)

type VersionInfo struct {
Expand All @@ -26,16 +26,22 @@ func init() {

// Note: we can't validate against existing logical drives at the moment
func IsAffected(firmware string) (int, string) {
if version.Compare(firmware, VersionFixed, ">=") {
firmwareVersion, _ := version.NewVersion(firmware)
fixedVersion, _ := version.NewVersion(VersionFixed)

if firmwareVersion.GreaterThanOrEqual(fixedVersion) {
return check.OK, "firmware has been updated"
}

if version.Compare(firmware, VersionAffectedRaid1, ">=") {
affectedRaid1, _ := version.NewVersion(VersionAffectedRaid1)

if firmwareVersion.GreaterThanOrEqual(affectedRaid1) {
return check.Critical, "if you have RAID 1/10/ADM - update immediately!"
}

for _, v := range VersionAffectedRaid5 {
if v == firmware {
affectedRaid5, _ := version.NewVersion(v)
if firmwareVersion.Equal(affectedRaid5) {
return check.Critical, "if you have RAID 5/6/50/60 - update immediately!"
}
}
Expand Down
6 changes: 4 additions & 2 deletions snmp/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"

"github.com/gosnmp/gosnmp"
"github.com/mcuadros/go-version"
"github.com/hashicorp/go-version"
)

type Table struct {
Expand Down Expand Up @@ -137,7 +137,9 @@ func (t *Table) GetSortedOIDs() []string {

func SortOIDs(list []string) []string {
sort.Slice(list, func(i, j int) bool {
return version.Compare(list[i], list[j], "<")
v1, _ := version.NewVersion(list[i])
v2, _ := version.NewVersion(list[j])
return v1.LessThan(v2)
})

return list
Expand Down

0 comments on commit 542701c

Please sign in to comment.