Skip to content

Commit

Permalink
Report powersupply status (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 authored Oct 2, 2024
1 parent 4c90d33 commit c55345d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 18 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.23
require (
github.com/gliderlabs/ssh v0.3.7
github.com/kelseyhightower/envconfig v1.4.0
github.com/metal-stack/go-hal v0.5.4
github.com/metal-stack/metal-go v0.35.2
github.com/metal-stack/go-hal v0.5.5
github.com/metal-stack/metal-go v0.37.1
github.com/metal-stack/v v1.0.3
github.com/nsqio/go-nsq v1.1.0
github.com/stretchr/testify v1.9.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ github.com/lestrrat-go/option v1.0.1 h1:oAzP2fvZGQKWkvHa1/SAcFolBEca1oN+mQ7eooNB
github.com/lestrrat-go/option v1.0.1/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/metal-stack/go-hal v0.5.4 h1:lovOdnYtcQnO81xEhmrrFuRonpZEauePTttA3ki0lSw=
github.com/metal-stack/go-hal v0.5.4/go.mod h1:2yeab7N8ApBd44z7mEwWCb+CL7o3ioZu41kSsra50Dw=
github.com/metal-stack/metal-go v0.35.2 h1:brTbmPUiYSH9IdbnCkrcRWFRlIfc0H/53f2phsB+5kY=
github.com/metal-stack/metal-go v0.35.2/go.mod h1:3MJTYCS4YJz8D8oteTKhjpaAKNMMjMKYDrIy9awHGtQ=
github.com/metal-stack/go-hal v0.5.5 h1:f+St8fZQEsUIwspy9fW5gkziKMIvFrGXP5kM9wJpLIw=
github.com/metal-stack/go-hal v0.5.5/go.mod h1:2yeab7N8ApBd44z7mEwWCb+CL7o3ioZu41kSsra50Dw=
github.com/metal-stack/metal-go v0.37.1 h1:vlvg/MY9Ep61h86GF54DER1VYADcqyHbFPZH3DqEbdM=
github.com/metal-stack/metal-go v0.37.1/go.mod h1:3MJTYCS4YJz8D8oteTKhjpaAKNMMjMKYDrIy9awHGtQ=
github.com/metal-stack/metal-lib v0.18.3 h1:bovFiJPB9SMvuGLqcXVWz6jFB8HrdzwnCX7TFlen4r0=
github.com/metal-stack/metal-lib v0.18.3/go.mod h1:Ctyi6zaXFr2NVrQZLFsDLnFCzupKnYErTtgRFKAsnbw=
github.com/metal-stack/security v0.8.1 h1:4zmVUxZvDWShVvVIxM3XhIv7pTmPe9DvACRIHW6YTsk=
Expand Down
17 changes: 15 additions & 2 deletions internal/leases/bmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"github.com/metal-stack/metal-go/api/models"
)

func (i *ReportItem) EnrichWithBMCDetails(ipmiPort int, ipmiUser, ipmiPassword string) {
func (i *ReportItem) EnrichWithBMCDetails(ipmiPort int, ipmiUser, ipmiPassword string) error {
ob, err := connect.OutBand(i.Ip, ipmiPort, ipmiUser, ipmiPassword, halslog.New(i.Log))
if err != nil {
i.Log.Error("could not establish outband connection to device bmc", "mac", i.Mac, "ip", i.Ip, "err", err)
return
return err
}

bmcDetails, err := ob.BMCConnection().BMC()
Expand All @@ -29,6 +29,7 @@ func (i *ReportItem) EnrichWithBMCDetails(ipmiPort int, ipmiUser, ipmiPassword s
}
} else {
i.Log.Warn("could not retrieve bmc details of device", "mac", i.Mac, "ip", i.Ip, "err", err)
return err
}

powerState, err := ob.PowerState()
Expand All @@ -50,6 +51,16 @@ func (i *ReportItem) EnrichWithBMCDetails(ipmiPort int, ipmiUser, ipmiPassword s
Minconsumedwatts: &board.PowerMetric.MinConsumedWatts,
}
}
var powerSupplies []*models.V1PowerSupply
for _, ps := range board.PowerSupplies {
powerSupplies = append(powerSupplies, &models.V1PowerSupply{
Status: &models.V1PowerSupplyStatus{
Health: &ps.Status.Health,
State: &ps.Status.State,
},
})
}
i.PowerSupplies = powerSupplies
}

u, err := ob.UUID()
Expand All @@ -58,5 +69,7 @@ func (i *ReportItem) EnrichWithBMCDetails(ipmiPort int, ipmiUser, ipmiPassword s
i.UUID = &str
} else {
i.Log.Warn("could not determine uuid of device", "mac", i.Mac, "ip", i.Ip, "err", err)
return err
}
return nil
}
17 changes: 9 additions & 8 deletions internal/leases/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ type Leases []Lease

type ReportItem struct {
Lease
Log *slog.Logger
UUID *string
BmcVersion *string
BiosVersion *string
FRU *models.V1MachineFru
Powerstate *string
IndicatorLED *string
PowerMetric *models.V1PowerMetric
Log *slog.Logger
UUID *string
BmcVersion *string
BiosVersion *string
FRU *models.V1MachineFru
Powerstate *string
IndicatorLED *string
PowerMetric *models.V1PowerMetric
PowerSupplies []*models.V1PowerSupply
}
4 changes: 2 additions & 2 deletions internal/reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ func (r reporter) collectAndReport() error {
for _, item := range items {
item := item
g.Go(func() error {
item.EnrichWithBMCDetails(r.cfg.IpmiPort, r.cfg.IpmiUser, r.cfg.IpmiPassword)
return nil
return item.EnrichWithBMCDetails(r.cfg.IpmiPort, r.cfg.IpmiUser, r.cfg.IpmiPassword)
})
}
err = g.Wait()
Expand Down Expand Up @@ -155,6 +154,7 @@ func (r reporter) report(items []*leases.ReportItem) error {
PowerState: item.Powerstate,
IndicatorLEDState: item.IndicatorLED,
PowerMetric: item.PowerMetric,
PowerSupplies: item.PowerSupplies,
}
reports[*item.UUID] = report
}
Expand Down

0 comments on commit c55345d

Please sign in to comment.