@@ -29,6 +29,14 @@ type Device struct {
29
29
Sensors []Sensor
30
30
}
31
31
32
+ const (
33
+ inputFileSuffix string = "_input"
34
+ critThresholdFileSuffix string = "_crit"
35
+ lowestValueFileSuffix string = "_lowest"
36
+ highestValueFileSuffix string = "_highest"
37
+ maxValueFileSuffix string = "_max"
38
+ )
39
+
32
40
func (d * Device ) String () string {
33
41
result := d .Name
34
42
result += ": "
@@ -263,7 +271,7 @@ func readHumiditySensor(devicePath string, index int) (Sensor, error) {
263
271
sensor .Perfdata .Label = label
264
272
265
273
// Look for input (the actual value)
266
- value , err := readIntFromFile (basePath + "_input" )
274
+ value , err := readIntFromFile (basePath + inputFileSuffix )
267
275
268
276
if err != nil {
269
277
return sensor , err
@@ -285,7 +293,7 @@ func readEnergySensor(devicePath string, index int) (Sensor, error) {
285
293
sensor .Perfdata .Label = label
286
294
287
295
// Look for input (the actual value)
288
- value , err := readIntFromFile (basePath + "_input" )
296
+ value , err := readIntFromFile (basePath + inputFileSuffix )
289
297
if err != nil {
290
298
return sensor , err
291
299
}
@@ -307,7 +315,7 @@ func readCurrSensor(devicePath string, index int) (Sensor, error) {
307
315
sensor .Perfdata .Label = label
308
316
309
317
// Look for input (the actual value)
310
- value , err := readIntFromFile (basePath + "_input" )
318
+ value , err := readIntFromFile (basePath + inputFileSuffix )
311
319
if err != nil {
312
320
return sensor , err
313
321
}
@@ -317,14 +325,14 @@ func readCurrSensor(devicePath string, index int) (Sensor, error) {
317
325
318
326
// == Min
319
327
// Is there a currN_lowest file? Use it for max value
320
- value , err = readIntFromFile (basePath + "_lowest" )
328
+ value , err = readIntFromFile (basePath + lowestValueFileSuffix )
321
329
if err == nil {
322
330
sensor .Perfdata .Min = float64 (value ) / 1000
323
331
}
324
332
325
333
// == Max
326
334
// Is there a currN_highest file? Use it for max value
327
- value , err = readIntFromFile (basePath + "_highest" )
335
+ value , err = readIntFromFile (basePath + highestValueFileSuffix )
328
336
if err == nil {
329
337
sensor .Perfdata .Max = float64 (value ) / 1000
330
338
}
@@ -343,7 +351,7 @@ func readCurrSensor(devicePath string, index int) (Sensor, error) {
343
351
critPresent = true
344
352
}
345
353
// Is there a currN_crit file? If yes, use that as upper critical
346
- value , err = readIntFromFile (basePath + "_crit" )
354
+ value , err = readIntFromFile (basePath + critThresholdFileSuffix )
347
355
if err == nil {
348
356
tmp .Upper = float64 (value ) / 1000
349
357
critPresent = true
@@ -391,7 +399,7 @@ func readFanSensor(devicePath string, index int) (Sensor, error) {
391
399
sensor .Perfdata .Label = label
392
400
393
401
// Look for input (the actual value)
394
- value , err := readIntFromFile (basePath + "_input" )
402
+ value , err := readIntFromFile (basePath + inputFileSuffix )
395
403
if err != nil {
396
404
return sensor , err
397
405
}
@@ -403,7 +411,7 @@ func readFanSensor(devicePath string, index int) (Sensor, error) {
403
411
404
412
// == Max
405
413
// Is there a tempN_highest file? Use it for max value
406
- value , err = readIntFromFile (basePath + "_max" )
414
+ value , err = readIntFromFile (basePath + maxValueFileSuffix )
407
415
if err == nil {
408
416
sensor .Perfdata .Max = float64 (value )
409
417
}
@@ -424,7 +432,7 @@ func readVoltageSensor(_, devicePath string, index int) (Sensor, error) {
424
432
sensor .Perfdata .Label = label
425
433
426
434
// Look for input (the actual value)
427
- value , err := readIntFromFile (basePath + "_input" )
435
+ value , err := readIntFromFile (basePath + inputFileSuffix )
428
436
if err != nil {
429
437
return sensor , err
430
438
}
@@ -440,7 +448,7 @@ func readVoltageSensor(_, devicePath string, index int) (Sensor, error) {
440
448
}
441
449
warnPresent := false
442
450
// Is there a inN_max file? If yes, use that as warning
443
- value , err = readIntFromFile (basePath + "_max" )
451
+ value , err = readIntFromFile (basePath + maxValueFileSuffix )
444
452
if err == nil {
445
453
tmpWarn .Upper = float64 (value ) / 1000
446
454
warnPresent = true
@@ -458,7 +466,7 @@ func readVoltageSensor(_, devicePath string, index int) (Sensor, error) {
458
466
}
459
467
critPresent := false
460
468
// Is there a inN_crit file? If yes, use that as critical
461
- value , err = readIntFromFile (basePath + "_crit" )
469
+ value , err = readIntFromFile (basePath + critThresholdFileSuffix )
462
470
if err == nil {
463
471
tmpCrit .Upper = float64 (value ) / 1000
464
472
critPresent = true
@@ -476,14 +484,14 @@ func readVoltageSensor(_, devicePath string, index int) (Sensor, error) {
476
484
}
477
485
478
486
// == Min
479
- value , err = readIntFromFile (basePath + "_lowest" )
487
+ value , err = readIntFromFile (basePath + lowestValueFileSuffix )
480
488
if err == nil {
481
489
sensor .Perfdata .Min = float64 (value ) / 1000
482
490
}
483
491
484
492
// == Max
485
493
// Is there a tempN_highest file? Use it for max value
486
- value , err = readIntFromFile (basePath + "_highest" )
494
+ value , err = readIntFromFile (basePath + highestValueFileSuffix )
487
495
if err == nil {
488
496
sensor .Perfdata .Max = float64 (value ) / 1000
489
497
}
@@ -503,7 +511,7 @@ func readPowerSensor(_, devicePath string, index int) (Sensor, error) {
503
511
sensor .Perfdata .Label = label
504
512
505
513
// Look for input (the actual value)
506
- value , err := readIntFromFile (basePath + "_input" )
514
+ value , err := readIntFromFile (basePath + inputFileSuffix )
507
515
508
516
if err != nil {
509
517
return sensor , err
@@ -551,7 +559,7 @@ func readPowerSensor(_, devicePath string, index int) (Sensor, error) {
551
559
}
552
560
critPresent := false
553
561
// Is there a powerN_crit file? If yes, use that as critical
554
- value , err = readIntFromFile (basePath + "_crit" )
562
+ value , err = readIntFromFile (basePath + critThresholdFileSuffix )
555
563
if err == nil {
556
564
tmpCrit .Upper = float64 (value )
557
565
critPresent = true
@@ -574,7 +582,7 @@ func readTempSensor(_, devicePath string, index int) (Sensor, error) {
574
582
sensor .Perfdata .Label = label
575
583
576
584
// Look for input (the actual value)
577
- value , err := readIntFromFile (basePath + "_input" )
585
+ value , err := readIntFromFile (basePath + inputFileSuffix )
578
586
579
587
if err != nil {
580
588
return sensor , err
@@ -591,7 +599,7 @@ func readTempSensor(_, devicePath string, index int) (Sensor, error) {
591
599
}
592
600
warnPresent := false
593
601
// Is there a tempN_max file? If yes, use that as warning
594
- value , err = readIntFromFile (basePath + "_max" )
602
+ value , err = readIntFromFile (basePath + maxValueFileSuffix )
595
603
596
604
if err == nil {
597
605
tmpWarn .Upper = float64 (value / 1000 )
@@ -611,7 +619,7 @@ func readTempSensor(_, devicePath string, index int) (Sensor, error) {
611
619
612
620
critPresent := false
613
621
// Is there a tempN_crit file? If yes, use that as critical
614
- value , err = readIntFromFile (basePath + "_crit" )
622
+ value , err = readIntFromFile (basePath + critThresholdFileSuffix )
615
623
616
624
if err == nil {
617
625
tmpCrit .Upper = float64 (value / 1000 )
@@ -640,15 +648,15 @@ func readTempSensor(_, devicePath string, index int) (Sensor, error) {
640
648
641
649
// == Min
642
650
// Is there a tempN_lowest file? Use it for min value
643
- value , err = readIntFromFile (basePath + "_lowest" )
651
+ value , err = readIntFromFile (basePath + lowestValueFileSuffix )
644
652
645
653
if err == nil {
646
654
sensor .Perfdata .Min = value
647
655
}
648
656
649
657
// == Max
650
658
// Is there a tempN_highest file? Use it for max value
651
- value , err = readIntFromFile (basePath + "_highest" )
659
+ value , err = readIntFromFile (basePath + highestValueFileSuffix )
652
660
653
661
if err == nil {
654
662
sensor .Perfdata .Max = value
0 commit comments