@@ -490,36 +490,50 @@ func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, err
490490 }
491491
492492 // Add discovered temperature sensor to the list
493+ optional := optionalProperties (filepath .Join (directory , basename ))
493494 temperatures = append (temperatures , TemperatureStat {
494495 SensorKey : name ,
495496 Temperature : temperature / hostTemperatureScale ,
496- High : optionalValueReadFromFile (basepath + "_max" ) / hostTemperatureScale ,
497- Critical : optionalValueReadFromFile (basepath + "_crit" ) / hostTemperatureScale ,
497+ High : optional ["max" ],
498+ Critical : optional ["crit" ],
499+ Optional : optional ,
498500 })
499501 }
500502
501503 return temperatures , warns .Reference ()
502504}
503505
504- func optionalValueReadFromFile (filename string ) float64 {
505- var raw []byte
506-
507- var err error
508-
509- var value float64
510-
511- // Check if file exists
512- if _ , err := os .Stat (filename ); os .IsNotExist (err ) {
513- return 0
506+ func optionalProperties (basename string ) map [string ]float64 {
507+ // Determine all files with the base-prefix
508+ matches , err := filepath .Glob (basename + "_*" )
509+ if err != nil {
510+ return map [string ]float64 {}
514511 }
515512
516- if raw , err = os .ReadFile (filename ); err != nil {
517- return 0
518- }
513+ // Collect the information from all files that are not already handled
514+ // with the exception of "max" and "crit" to keep an indicator if those
515+ // actually exist
516+ values := make (map [string ]float64 )
517+ for _ , fn := range matches {
518+ // Skip already handles files
519+ suffix := strings .Split (fn , "_" )
520+ property := suffix [len (suffix )- 1 ]
521+ switch property {
522+ case "label" , "input" :
523+ continue
524+ }
519525
520- if value , err = strconv .ParseFloat (strings .TrimSpace (string (raw )), 64 ); err != nil {
521- return 0
526+ // Read and parse the file and keep the property on success
527+ raw , err := os .ReadFile (fn )
528+ if err != nil {
529+ continue
530+ }
531+ value , err := strconv .ParseFloat (strings .TrimSpace (string (raw )), 64 )
532+ if err != nil {
533+ continue
534+ }
535+ values [property ] = value / hostTemperatureScale
522536 }
523537
524- return value
538+ return values
525539}
0 commit comments