Skip to content

Commit b31f0f7

Browse files
committed
Convert ipmi stats/tags to underscore and lowercase
closes #888
1 parent dbd7b9f commit b31f0f7

File tree

3 files changed

+112
-22
lines changed

3 files changed

+112
-22
lines changed

plugins/inputs/ipmi/README.md

+11-19
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ ipmitool -I lan -H 192.168.1.1 -U USERID -P PASSW0RD sdr
1212

1313
- ipmi_sensor:
1414

15-
* Tags: `server`,`host`
15+
* Tags: `name`,`server`
1616
* Fields:
1717
- status
1818
- value
19-
19+
2020
## Configuration
2121

2222
```toml
@@ -31,20 +31,12 @@ ipmitool -I lan -H 192.168.1.1 -U USERID -P PASSW0RD sdr
3131

3232
## Output
3333

34-
> ipmi_sensor,host=10.20.2.203,inst=Ambient\ Temp status=1i,value=20 1458488465012559455
35-
> ipmi_sensor,host=10.20.2.203,inst=Altitude status=1i,value=80 1458488465012688613
36-
> ipmi_sensor,host=10.20.2.203,inst=Avg\ Power status=1i,value=220 1458488465012776511
37-
> ipmi_sensor,host=10.20.2.203,inst=Planar\ 3.3V status=1i,value=3.28 1458488465012861875
38-
> ipmi_sensor,host=10.20.2.203,inst=Planar\ 5V status=1i,value=4.9 1458488465012944188
39-
> ipmi_sensor,host=10.20.2.203,inst=Planar\ 12V status=1i,value=12.04 1458488465013008485
40-
> ipmi_sensor,host=10.20.2.203,inst=Planar\ VBAT status=1i,value=3.04 1458488465013072508
41-
> ipmi_sensor,host=10.20.2.203,inst=Fan\ 1A\ Tach status=1i,value=2610 1458488465013137932
42-
> ipmi_sensor,host=10.20.2.203,inst=Fan\ 1B\ Tach status=1i,value=1775 1458488465013279896
43-
> ipmi_sensor,host=10.20.2.203,inst=Fan\ 2A\ Tach status=1i,value=1972 1458488465013358177
44-
> ipmi_sensor,host=10.20.2.203,inst=Fan\ 2B\ Tach status=1i,value=1275 1458488465013434023
45-
> ipmi_sensor,host=10.20.2.203,inst=Fan\ 3A\ Tach status=1i,value=2929 1458488465013514567
46-
> ipmi_sensor,host=10.20.2.203,inst=Fan\ 3B\ Tach status=1i,value=2125 1458488465013582616
47-
> ipmi_sensor,host=10.20.2.203,inst=Fan\ 1 status=1i,value=0 1458488465013643746
48-
> ipmi_sensor,host=10.20.2.203,inst=Fan\ 2 status=1i,value=0 1458488465013714887
49-
> ipmi_sensor,host=10.20.2.203,inst=Fan\ 3 status=1i,value=0 1458488465013861854
50-
34+
```
35+
> ipmi_sensor,server=10.20.2.203,unit=degrees_c,name=ambient_temp status=1i,value=20 1458488465012559455
36+
> ipmi_sensor,server=10.20.2.203,unit=feet,name=altitude status=1i,value=80 1458488465012688613
37+
> ipmi_sensor,server=10.20.2.203,unit=watts,name=avg_power status=1i,value=220 1458488465012776511
38+
> ipmi_sensor,server=10.20.2.203,unit=volts,name=planar_3.3v status=1i,value=3.28 1458488465012861875
39+
> ipmi_sensor,server=10.20.2.203,unit=volts,name=planar_vbat status=1i,value=3.04 1458488465013072508
40+
> ipmi_sensor,server=10.20.2.203,unit=rpm,name=fan_1a_tach status=1i,value=2610 1458488465013137932
41+
> ipmi_sensor,server=10.20.2.203,unit=rpm,name=fan_1b_tach status=1i,value=1775 1458488465013279896
42+
```

plugins/inputs/ipmi/ipmi.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ type Ipmi struct {
1515
runner Runner
1616
}
1717

18+
var replacer = strings.NewReplacer(" ", "_")
19+
1820
var sampleConfig = `
1921
## specify servers via a url matching:
2022
## [username[:password]@][protocol[(address)]]
@@ -65,7 +67,7 @@ func (m *Ipmi) gatherServer(serv string, acc telegraf.Accumulator) error {
6567
for i := 0; i < len(lines); i++ {
6668
vals := strings.Split(lines[i], "|")
6769
if len(vals) == 3 {
68-
tags := map[string]string{"server": conn.Hostname, "name": trim(vals[0])}
70+
tags := map[string]string{"server": conn.Hostname, "name": transform(vals[0])}
6971
fields := make(map[string]interface{})
7072
if strings.EqualFold("ok", trim(vals[2])) {
7173
fields["status"] = 1
@@ -76,8 +78,11 @@ func (m *Ipmi) gatherServer(serv string, acc telegraf.Accumulator) error {
7678
val1 := trim(vals[1])
7779

7880
if strings.Index(val1, " ") > 0 {
79-
val := strings.Split(val1, " ")[0]
80-
fields["value"] = Atofloat(val)
81+
valunit := strings.SplitN(val1, " ", 2)
82+
fields["value"] = Atofloat(valunit[0])
83+
if len(valunit) > 1 {
84+
tags["units"] = transform(valunit[1])
85+
}
8186
} else {
8287
fields["value"] = 0.0
8388
}
@@ -106,6 +111,12 @@ func trim(s string) string {
106111
return strings.TrimSpace(s)
107112
}
108113

114+
func transform(s string) string {
115+
s = trim(s)
116+
s = strings.ToLower(s)
117+
return replacer.Replace(s)
118+
}
119+
109120
func init() {
110121
inputs.Add("ipmi", func() telegraf.Input {
111122
return &Ipmi{}

plugins/inputs/ipmi/ipmi_test.go

+87
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,93 @@ func TestIpmi(t *testing.T) {
179179
require.NoError(t, err)
180180

181181
assert.Equal(t, acc.NFields(), 266, "non-numeric measurements should be ignored")
182+
183+
var tests = []struct {
184+
fields map[string]interface{}
185+
tags map[string]string
186+
}{
187+
{
188+
map[string]interface{}{
189+
"value": float64(20),
190+
"status": int(1),
191+
},
192+
map[string]string{
193+
"name": "ambient_temp",
194+
"server": "192.168.1.1",
195+
"units": "degrees_c",
196+
},
197+
},
198+
{
199+
map[string]interface{}{
200+
"value": float64(80),
201+
"status": int(1),
202+
},
203+
map[string]string{
204+
"name": "altitude",
205+
"server": "192.168.1.1",
206+
"units": "feet",
207+
},
208+
},
209+
{
210+
map[string]interface{}{
211+
"value": float64(210),
212+
"status": int(1),
213+
},
214+
map[string]string{
215+
"name": "avg_power",
216+
"server": "192.168.1.1",
217+
"units": "watts",
218+
},
219+
},
220+
{
221+
map[string]interface{}{
222+
"value": float64(4.9),
223+
"status": int(1),
224+
},
225+
map[string]string{
226+
"name": "planar_5v",
227+
"server": "192.168.1.1",
228+
"units": "volts",
229+
},
230+
},
231+
{
232+
map[string]interface{}{
233+
"value": float64(3.05),
234+
"status": int(1),
235+
},
236+
map[string]string{
237+
"name": "planar_vbat",
238+
"server": "192.168.1.1",
239+
"units": "volts",
240+
},
241+
},
242+
{
243+
map[string]interface{}{
244+
"value": float64(2610),
245+
"status": int(1),
246+
},
247+
map[string]string{
248+
"name": "fan_1a_tach",
249+
"server": "192.168.1.1",
250+
"units": "rpm",
251+
},
252+
},
253+
{
254+
map[string]interface{}{
255+
"value": float64(1775),
256+
"status": int(1),
257+
},
258+
map[string]string{
259+
"name": "fan_1b_tach",
260+
"server": "192.168.1.1",
261+
"units": "rpm",
262+
},
263+
},
264+
}
265+
266+
for _, test := range tests {
267+
acc.AssertContainsTaggedFields(t, "ipmi_sensor", test.fields, test.tags)
268+
}
182269
}
183270

184271
func TestIpmiConnection(t *testing.T) {

0 commit comments

Comments
 (0)