Skip to content

Commit c136613

Browse files
committed
examples/sensors: add example for power draw, temperature, fan speeds and chassis health
1 parent 443515c commit c136613

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

examples/v1/sensors/main.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"log"
7+
"time"
8+
9+
"github.com/bmc-toolbox/bmclib"
10+
"github.com/bombsimon/logrusr"
11+
"github.com/sirupsen/logrus"
12+
)
13+
14+
func main() {
15+
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
16+
defer cancel()
17+
host := ""
18+
port := ""
19+
user := ""
20+
pass := ""
21+
22+
l := logrus.New()
23+
l.Level = logrus.DebugLevel
24+
logger := logrusr.NewLogger(l)
25+
26+
var err error
27+
28+
cl := bmclib.NewClient(host, port, user, pass, bmclib.WithLogger(logger))
29+
cl.Registry.Drivers = cl.Registry.Using("redfish")
30+
err = cl.Open(ctx)
31+
if err != nil {
32+
log.Fatal(err, "bmc login failed")
33+
}
34+
35+
p, err := cl.GetPowerSensors(ctx)
36+
if err != nil {
37+
fmt.Println(err, "unable to retrieve power sensor data")
38+
}
39+
40+
fmt.Printf("%+v\n", p)
41+
42+
t, err := cl.GetTemperatureSensors(ctx)
43+
if err != nil {
44+
fmt.Println(err, "unable to retrieve temperature sensor data")
45+
}
46+
47+
fmt.Printf("%+v\n", t)
48+
49+
f, err := cl.GetFanSensors(ctx)
50+
if err != nil {
51+
fmt.Println(err, "unable to retrieve fan sensor data")
52+
}
53+
54+
fmt.Printf("%+v\n", f)
55+
56+
c, err := cl.GetChassisHealth(ctx)
57+
if err != nil {
58+
fmt.Println(err, "unable to retrieve chassis health data")
59+
}
60+
61+
fmt.Printf("%+v\n", c)
62+
63+
}

0 commit comments

Comments
 (0)