mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-11-10 12:37:25 +01:00
Use LookPath in IpmiCollector
This commit is contained in:
parent
b19ae7a4db
commit
d8ab3b0eb0
@ -9,11 +9,12 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
||||||
)
|
)
|
||||||
|
|
||||||
const IPMITOOL_PATH = `/usr/bin/ipmitool`
|
const IPMITOOL_PATH = `ipmitool`
|
||||||
const IPMISENSORS_PATH = `/usr/sbin/ipmi-sensors`
|
const IPMISENSORS_PATH = `ipmi-sensors`
|
||||||
|
|
||||||
type IpmiCollectorConfig struct {
|
type IpmiCollectorConfig struct {
|
||||||
ExcludeDevices []string `json:"exclude_devices"`
|
ExcludeDevices []string `json:"exclude_devices"`
|
||||||
@ -23,30 +24,36 @@ type IpmiCollectorConfig struct {
|
|||||||
|
|
||||||
type IpmiCollector struct {
|
type IpmiCollector struct {
|
||||||
metricCollector
|
metricCollector
|
||||||
tags map[string]string
|
//tags map[string]string
|
||||||
matches map[string]string
|
//matches map[string]string
|
||||||
config IpmiCollectorConfig
|
config IpmiCollectorConfig
|
||||||
|
ipmitool string
|
||||||
|
ipmisensors string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *IpmiCollector) Init(config json.RawMessage) error {
|
func (m *IpmiCollector) Init(config json.RawMessage) error {
|
||||||
m.name = "IpmiCollector"
|
m.name = "IpmiCollector"
|
||||||
m.setup()
|
m.setup()
|
||||||
m.meta = map[string]string{"source": m.name, "group": "IPMI"}
|
m.meta = map[string]string{"source": m.name, "group": "IPMI"}
|
||||||
|
m.config.IpmitoolPath = string(IPMITOOL_PATH)
|
||||||
|
m.config.IpmisensorsPath = string(IPMISENSORS_PATH)
|
||||||
|
m.ipmitool = ""
|
||||||
|
m.ipmisensors = ""
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
err := json.Unmarshal(config, &m.config)
|
err := json.Unmarshal(config, &m.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_, err1 := os.Stat(m.config.IpmitoolPath)
|
p, err := exec.LookPath(m.config.IpmitoolPath)
|
||||||
_, err2 := os.Stat(m.config.IpmisensorsPath)
|
if err == nil {
|
||||||
if err1 != nil {
|
m.ipmitool = p
|
||||||
m.config.IpmitoolPath = ""
|
|
||||||
}
|
}
|
||||||
if err2 != nil {
|
p, err = exec.LookPath(m.config.IpmisensorsPath)
|
||||||
m.config.IpmisensorsPath = ""
|
if err == nil {
|
||||||
|
m.ipmisensors = p
|
||||||
}
|
}
|
||||||
if err1 != nil && err2 != nil {
|
if len(m.ipmitool) == 0 && len(m.ipmisensors) == 0 {
|
||||||
return errors.New("No IPMI reader found")
|
return errors.New("No IPMI reader found")
|
||||||
}
|
}
|
||||||
m.init = true
|
m.init = true
|
||||||
|
Loading…
Reference in New Issue
Block a user