-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathipmi.go
71 lines (62 loc) · 1.84 KB
/
ipmi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"net"
"strings"
"ww2prom/pkgs/warewulf"
"gopkg.in/yaml.v2"
)
// IPMIExporterConfig represents the ipmi_exporter configuration
type IPMIExporterConfig struct {
Modules map[string]IPMIModule `yaml:"modules"`
}
// IPMIModule is a individual module within the ipmi_exporter config
type IPMIModule struct {
User string `yaml:"user"`
Pass string `yaml:"pass"`
Driver string `yaml:"driver,omitempty"`
Privilege string `yaml:"privilege,omitempty"`
Collectors []string `yaml:"collectors,omitempty"`
ExcludeSensorIDs []int64 `yaml:"exclude_sensor_ids,omitempty"`
}
//Update fetches the latest data via wwsh and repopulates the given IPMIExporterConfig
func (ipmiCfg *IPMIExporterConfig) Update(nodns bool) error {
nodes, err := warewulf.Nodes()
if err != nil {
return err
}
for _, v := range nodes {
if v.IpmiIpaddr != "" || v.IpmiUsername != "" || v.IpmiPassword != "" {
mod := IPMIModule{User: v.IpmiUsername, Pass: v.IpmiPassword}
if names, err := net.LookupAddr(v.IpmiIpaddr); nodns || err != nil {
ipmiCfg.Modules[v.IpmiIpaddr] = mod
} else {
name := strings.TrimSuffix(names[0], ".")
ipmiCfg.Modules[name] = mod
}
}
}
return nil
}
// ToYaml Marshalls IPMIExporterConfig to YAML
func (ipmiCfg *IPMIExporterConfig) ToYaml() ([]byte, error) {
d, err := yaml.Marshal(&ipmiCfg)
if err != nil {
return nil, err
}
return d, nil
}
// FromYAML unmarshals a IPMIExporterConfig from YAML
func FromYAML(b []byte) (*IPMIExporterConfig, error) {
var ipmiCfg IPMIExporterConfig
if err := yaml.Unmarshal(b, &ipmiCfg); err != nil {
return nil, err
}
return &ipmiCfg, nil
}
// IPMITargetsConfig represents a Prometheus File dy
type IPMITargetsConfig []struct {
Targets []string `yaml:"targets"`
Labels struct {
Job string `yaml:"job"`
} `yaml:"labels"`
}