mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-12-26 15:29:04 +01:00
Test whether ipmitool or ipmi-sensors can be executed without errors
This commit is contained in:
parent
2efed7c631
commit
a36f8fe19d
@ -12,6 +12,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric"
|
lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric"
|
||||||
)
|
)
|
||||||
@ -54,15 +55,30 @@ func (m *IpmiCollector) Init(config json.RawMessage) error {
|
|||||||
// Check if executables ipmitool or ipmisensors are found
|
// Check if executables ipmitool or ipmisensors are found
|
||||||
p, err := exec.LookPath(m.config.IpmitoolPath)
|
p, err := exec.LookPath(m.config.IpmitoolPath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
command := exec.Command(p)
|
||||||
|
err := command.Run()
|
||||||
|
if err != nil {
|
||||||
|
cclog.ComponentError(m.name, fmt.Sprintf("Failed to execute %s: %v", p, err.Error()))
|
||||||
|
m.ipmitool = ""
|
||||||
|
} else {
|
||||||
m.ipmitool = p
|
m.ipmitool = p
|
||||||
}
|
}
|
||||||
|
}
|
||||||
p, err = exec.LookPath(m.config.IpmisensorsPath)
|
p, err = exec.LookPath(m.config.IpmisensorsPath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
command := exec.Command(p)
|
||||||
|
err := command.Run()
|
||||||
|
if err != nil {
|
||||||
|
cclog.ComponentError(m.name, fmt.Sprintf("Failed to execute %s: %v", p, err.Error()))
|
||||||
|
m.ipmisensors = ""
|
||||||
|
} else {
|
||||||
m.ipmisensors = p
|
m.ipmisensors = p
|
||||||
}
|
}
|
||||||
if len(m.ipmitool) == 0 && len(m.ipmisensors) == 0 {
|
|
||||||
return errors.New("no IPMI reader found")
|
|
||||||
}
|
}
|
||||||
|
if len(m.ipmitool) == 0 && len(m.ipmisensors) == 0 {
|
||||||
|
return errors.New("no usable IPMI reader found")
|
||||||
|
}
|
||||||
|
|
||||||
m.init = true
|
m.init = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -119,8 +135,8 @@ func (m *IpmiCollector) readIpmiTool(cmd string, output chan lp.CCMetric) {
|
|||||||
cclog.ComponentError(
|
cclog.ComponentError(
|
||||||
m.name,
|
m.name,
|
||||||
fmt.Sprintf("readIpmiTool(): Failed to wait for the end of command \"%s\": %v\n", command.String(), err),
|
fmt.Sprintf("readIpmiTool(): Failed to wait for the end of command \"%s\": %v\n", command.String(), err),
|
||||||
fmt.Sprintf("readIpmiTool(): command stderr: \"%s\"\n", string(errMsg)),
|
|
||||||
)
|
)
|
||||||
|
cclog.ComponentError(m.name, fmt.Sprintf("readIpmiTool(): command stderr: \"%s\"\n", strings.TrimSpace(string(errMsg))))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user