@@ -114,7 +114,7 @@ type Plugin interface {
114
114
115
115
// NewExporter returns an initialized Exporter for a redfish API capable device.
116
116
func NewExporter (ctx context.Context , target , uri , profile , model string , excludes Excludes , plugins ... Plugin ) (* Exporter , error ) {
117
- var fqdn * url.URL
117
+ var u * url.URL
118
118
var tasks []* pool.Task
119
119
var exp = Exporter {
120
120
ctx : ctx ,
@@ -158,15 +158,17 @@ func NewExporter(ctx context.Context, target, uri, profile, model string, exclud
158
158
exp .client = retryClient
159
159
160
160
// Check that the target passed in has http:// or https:// prefixed
161
- fqdn , err := url .ParseRequestURI (target )
162
- if err != nil {
163
- fqdn = & url.URL {
164
- Scheme : config .GetConfig ().BMCScheme ,
165
- Host : target ,
161
+ u , err := url .ParseRequestURI (target )
162
+ if err != nil || u .Host == "" {
163
+ u , err = url .ParseRequestURI (config .GetConfig ().BMCScheme + "://" + target )
164
+ if err != nil {
165
+ log .Error ("error parsing target param" , zap .Error (err ), zap .Any ("trace_id" , ctx .Value ("traceID" )))
166
+ return & exp , err
166
167
}
167
168
}
168
- exp .host = fqdn .Hostname ()
169
- exp .url = fqdn .String ()
169
+
170
+ exp .host = u .Hostname ()
171
+ exp .url = u .String ()
170
172
171
173
// check if host is on the ignored list, if so we immediately return
172
174
if _ , ok := common .IgnoredDevices [exp .host ]; ok {
@@ -177,7 +179,7 @@ func NewExporter(ctx context.Context, target, uri, profile, model string, exclud
177
179
178
180
chassisEndpoints , err := getMemberUrls (exp .url + uri + "/Chassis/" , target , retryClient )
179
181
if err != nil {
180
- log .Error ("error when getting chassis url from " + model , zap .Error (err ), zap .Any ("trace_id" , ctx .Value ("traceID" )))
182
+ log .Error ("error when getting chassis url" , zap .Error (err ), zap .Any ("trace_id" , ctx .Value ("traceID" )))
181
183
if errors .Is (err , common .ErrInvalidCredential ) {
182
184
common .IgnoredDevices [exp .host ] = common.IgnoredDevice {
183
185
Name : exp .host ,
@@ -198,7 +200,7 @@ func NewExporter(ctx context.Context, target, uri, profile, model string, exclud
198
200
199
201
mgrEndpoints , err := getMemberUrls (exp .url + uri + "/Managers/" , target , retryClient )
200
202
if err != nil {
201
- log .Error ("error when getting manager endpoint from " + model , zap .Error (err ), zap .Any ("trace_id" , ctx .Value ("traceID" )))
203
+ log .Error ("error when getting manager endpoint" , zap .Error (err ), zap .Any ("trace_id" , ctx .Value ("traceID" )))
202
204
return nil , err
203
205
}
204
206
@@ -232,7 +234,7 @@ func NewExporter(ctx context.Context, target, uri, profile, model string, exclud
232
234
// point for the systems and manager endpoints
233
235
sysEndpoints , err := getSystemEndpoints (chasUrlsFinal , target , retryClient , excludes )
234
236
if err != nil {
235
- log .Error ("error when getting chassis endpoints from " + model , zap .Error (err ), zap .Any ("trace_id" , ctx .Value ("traceID" )))
237
+ log .Error ("error when getting chassis endpoints" , zap .Error (err ), zap .Any ("trace_id" , ctx .Value ("traceID" )))
236
238
return nil , err
237
239
}
238
240
@@ -250,7 +252,7 @@ func NewExporter(ctx context.Context, target, uri, profile, model string, exclud
250
252
// call /redfish/v1/Systems/XXXXX/ for BIOS, Serial number
251
253
sysResp , err = getSystemsMetadata (exp .url + sysEndpoints .systems [0 ], target , retryClient )
252
254
if err != nil {
253
- log .Error ("error when getting BIOS version from " + model , zap .Error (err ), zap .Any ("trace_id" , ctx .Value ("traceID" )))
255
+ log .Error ("error when getting BIOS version" , zap .Error (err ), zap .Any ("trace_id" , ctx .Value ("traceID" )))
254
256
return nil , err
255
257
}
256
258
exp .biosVersion = sysResp .BiosVersion
@@ -267,14 +269,14 @@ func NewExporter(ctx context.Context, target, uri, profile, model string, exclud
267
269
// DIMM endpoints array
268
270
dimms , err = getDIMMEndpoints (exp .url + sysEndpoints .systems [0 ]+ "Memory/" , target , retryClient )
269
271
if err != nil {
270
- log .Error ("error when getting DIMM endpoints from " + model , zap .Error (err ), zap .Any ("trace_id" , ctx .Value ("traceID" )))
272
+ log .Error ("error when getting DIMM endpoints" , zap .Error (err ), zap .Any ("trace_id" , ctx .Value ("traceID" )))
271
273
return nil , err
272
274
}
273
275
274
276
// CPU processor metrics
275
277
processors , err = getProcessorEndpoints (exp .url + sysEndpoints .systems [0 ]+ "Processors/" , target , retryClient )
276
278
if err != nil {
277
- log .Error ("error when getting Processors endpoints from " + model , zap .Error (err ), zap .Any ("trace_id" , ctx .Value ("traceID" )))
279
+ log .Error ("error when getting Processors endpoints" , zap .Error (err ), zap .Any ("trace_id" , ctx .Value ("traceID" )))
278
280
return nil , err
279
281
}
280
282
} else {
@@ -298,7 +300,7 @@ func NewExporter(ctx context.Context, target, uri, profile, model string, exclud
298
300
if ss != "" {
299
301
driveEndpointsResp , err = getAllDriveEndpoints (ctx , exp .url , exp .url + ss , target , retryClient )
300
302
if err != nil {
301
- log .Error ("error when getting drive endpoints from " + model , zap .Error (err ), zap .Any ("trace_id" , ctx .Value ("traceID" )))
303
+ log .Error ("error when getting drive endpoints" , zap .Error (err ), zap .Any ("trace_id" , ctx .Value ("traceID" )))
302
304
return nil , err
303
305
}
304
306
}
@@ -441,7 +443,7 @@ func (e *Exporter) scrape() {
441
443
}
442
444
var upMetric = (* e .DeviceMetrics )["up" ]
443
445
(* upMetric )["up" ].WithLabelValues ().Set (float64 (deviceState ))
444
- log .Error ("error calling redfish api from " + e . Model , zap .Error (task .Err ), zap .String ("url" , task .URL ), zap .Any ("trace_id" , e .ctx .Value ("traceID" )))
446
+ log .Error ("error calling redfish api" , zap .Error (task .Err ), zap .String ("url" , task .URL ), zap .Any ("trace_id" , e .ctx .Value ("traceID" )))
445
447
return
446
448
}
447
449
@@ -450,7 +452,7 @@ func (e *Exporter) scrape() {
450
452
}
451
453
452
454
if err != nil {
453
- log .Error ("error exporting metrics - from " + e . Model , zap .Error (err ), zap .String ("url" , task .URL ), zap .Any ("trace_id" , e .ctx .Value ("traceID" )))
455
+ log .Error ("error exporting metrics" , zap .Error (err ), zap .String ("url" , task .URL ), zap .Any ("trace_id" , e .ctx .Value ("traceID" )))
454
456
continue
455
457
}
456
458
scrapeChan <- 1
0 commit comments