@@ -2,11 +2,11 @@ package collector
2
2
3
3
import (
4
4
"bytes"
5
- "fmt"
6
5
"sync"
7
6
"time"
8
7
9
- "github.com/apex/log"
8
+ alog "github.com/apex/log"
9
+ "github.com/jenningsloy318/redfish_exporter/common"
10
10
"github.com/prometheus/client_golang/prometheus"
11
11
gofish "github.com/stmcginnis/gofish"
12
12
gofishcommon "github.com/stmcginnis/gofish/common"
@@ -40,22 +40,16 @@ type RedfishCollector struct {
40
40
}
41
41
42
42
// NewRedfishCollector return RedfishCollector
43
- func NewRedfishCollector (host string , username string , password string , collectLogs bool , logger * log .Entry ) * RedfishCollector {
43
+ func NewRedfishCollector (ctx * common. CollectionContext , logger * alog .Entry ) * RedfishCollector {
44
44
var collectors map [string ]prometheus.Collector
45
- collectorLogCtx := logger
46
- redfishClient , err := newRedfishClient (host , username , password )
47
- if err != nil {
48
- collectorLogCtx .WithError (err ).Error ("error creating redfish client" )
49
- } else {
50
- chassisCollector := NewChassisCollector (redfishClient , collectLogs , collectorLogCtx )
51
- systemCollector := NewSystemCollector (redfishClient , collectLogs , collectorLogCtx )
52
- managerCollector := NewManagerCollector (redfishClient , collectLogs , collectorLogCtx )
45
+ chassisCollector := NewChassisCollector (ctx , logger )
46
+ systemCollector := NewSystemCollector (ctx , logger )
47
+ managerCollector := NewManagerCollector (ctx , logger )
53
48
54
- collectors = map [string ]prometheus.Collector {"chassis" : chassisCollector , "system" : systemCollector , "manager" : managerCollector }
55
- }
49
+ collectors = map [string ]prometheus.Collector {"chassis" : chassisCollector , "system" : systemCollector , "manager" : managerCollector }
56
50
57
51
return & RedfishCollector {
58
- redfishClient : redfishClient ,
52
+ redfishClient : ctx . RedfishClient ,
59
53
collectors : collectors ,
60
54
redfishUp : prometheus .NewGauge (
61
55
prometheus.GaugeOpts {
@@ -101,23 +95,6 @@ func (r *RedfishCollector) Collect(ch chan<- prometheus.Metric) {
101
95
ch <- prometheus .MustNewConstMetric (totalScrapeDurationDesc , prometheus .GaugeValue , time .Since (scrapeTime ).Seconds ())
102
96
}
103
97
104
- func newRedfishClient (host string , username string , password string ) (* gofish.APIClient , error ) {
105
-
106
- url := fmt .Sprintf ("https://%s" , host )
107
-
108
- config := gofish.ClientConfig {
109
- Endpoint : url ,
110
- Username : username ,
111
- Password : password ,
112
- Insecure : true ,
113
- }
114
- redfishClient , err := gofish .Connect (config )
115
- if err != nil {
116
- return nil , err
117
- }
118
- return redfishClient , nil
119
- }
120
-
121
98
func parseCommonStatusHealth (status gofishcommon.Health ) (float64 , bool ) {
122
99
if bytes .Equal ([]byte (status ), []byte ("OK" )) {
123
100
return float64 (1 ), true
0 commit comments