This commit is contained in:
Sean E. Russell 2020-05-30 05:35:27 -05:00
parent dcfa280166
commit 30f59c43da

View File

@ -3,6 +3,7 @@
package devices
import (
"log"
"os/exec"
"strconv"
"strings"
@ -11,6 +12,10 @@ import (
)
func init() {
if len(devs()) == 0 {
log.Println("temp: no thermal sensors found")
return
}
RegisterTemp(update)
RegisterDeviceList(Temperatures, devs, devs)
}
@ -50,8 +55,19 @@ func update(temps map[string]int) map[string]error {
func devs() []string {
rv := make([]string, 0, len(sensorOIDS))
// Check that thermal sensors are really available; they aren't in VMs
bs, err := exec.Command("sysctl", "-a").Output()
if err != nil {
log.Printf("temp: failure to get system information %s", err.Error())
return []string{}
}
for k, _ := range sensorOIDS {
rv = append(rv, k)
idx := strings.Index(string(bs), k)
if idx < 0 {
log.Println("temp: no device %s found", k)
} else {
rv = append(rv, k)
}
}
return rv
}