Skip to content

Commit 8670afd

Browse files
authored
Merge pull request #59 from snetsystems/release-1.23-snet-jinhyeong
At #57 Fix Unable to Collect Data When customTags is Missing
2 parents 79dd441 + ce11da9 commit 8670afd

File tree

2 files changed

+111
-7
lines changed

2 files changed

+111
-7
lines changed

plugins/inputs/ipmi_sensor/ipmi_sensor.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,22 @@ func (m *Ipmi) parse(acc telegraf.Accumulator, server string) error {
113113

114114
if server != "" {
115115
server := trimAll(server)
116-
startIndex := strings.LastIndex(server, "),{")
117116
connInfo := regexp.MustCompile(`(.*\)),(\{.*\})`).FindStringSubmatch(server)
117+
serverConn := server
118118

119-
if startIndex >= 0 && len(connInfo) > 2 {
119+
if len(connInfo) > 2 {
120+
serverConn = connInfo[1]
120121
jsonBytes := []byte(strings.ReplaceAll(connInfo[2], "'", "\""))
121-
122122
err := json.Unmarshal(jsonBytes, &customTags)
123123
if err != nil {
124124
fmt.Println(err)
125125
return fmt.Errorf("Error unmarshaling %s ", err)
126126
}
127-
128-
conn := NewConnection(connInfo[1], m.Privilege, m.HexKey)
129-
ipmiIP = conn.IpmiIP
130-
opts = conn.options()
131127
}
128+
129+
conn := NewConnection(serverConn, m.Privilege, m.HexKey)
130+
ipmiIP = conn.IpmiIP
131+
opts = conn.options()
132132
}
133133
opts = append(opts, "sdr")
134134
if m.UseCache {

plugins/inputs/ipmi_sensor/ipmi_sensor_test.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,110 @@ func TestGather(t *testing.T) {
226226
for _, test := range testsWithoutServer {
227227
acc.AssertContainsTaggedFields(t, "ipmi_sensor", test.fields, test.tags)
228228
}
229+
230+
i = &Ipmi{
231+
Servers: []string{"USERID:PASSW0,RD@lan(192.168.1.1) "},
232+
Path: "ipmitool",
233+
Privilege: "USER",
234+
Timeout: config.Duration(time.Second * 5),
235+
HexKey: "1234567F",
236+
Log: testutil.Logger{},
237+
}
238+
239+
require.NoError(t, i.Init())
240+
require.NoError(t, acc.GatherError(i.Gather))
241+
242+
conn = NewConnection(i.Servers[0], i.Privilege, i.HexKey)
243+
require.EqualValues(t, "USERID", conn.Username)
244+
require.EqualValues(t, "lan", conn.Interface)
245+
require.EqualValues(t, "1234567F", conn.HexKey)
246+
247+
var testsWithoutCutsomTagServer = []struct {
248+
fields map[string]interface{}
249+
tags map[string]string
250+
}{
251+
{
252+
map[string]interface{}{
253+
"value": float64(20),
254+
"status": 1,
255+
},
256+
map[string]string{
257+
"name": "ambient_temp",
258+
"server": "192.168.1.1",
259+
"unit": "degrees_c",
260+
},
261+
},
262+
{
263+
map[string]interface{}{
264+
"value": float64(80),
265+
"status": 1,
266+
},
267+
map[string]string{
268+
"name": "altitude",
269+
"server": "192.168.1.1",
270+
"unit": "feet",
271+
},
272+
},
273+
{
274+
map[string]interface{}{
275+
"value": float64(210),
276+
"status": 1,
277+
},
278+
map[string]string{
279+
"name": "avg_power",
280+
"server": "192.168.1.1",
281+
"unit": "watts",
282+
},
283+
},
284+
{
285+
map[string]interface{}{
286+
"value": float64(4.9),
287+
"status": 1,
288+
},
289+
map[string]string{
290+
"name": "planar_5v",
291+
"server": "192.168.1.1",
292+
"unit": "volts",
293+
},
294+
},
295+
{
296+
map[string]interface{}{
297+
"value": float64(3.05),
298+
"status": 1,
299+
},
300+
map[string]string{
301+
"name": "planar_vbat",
302+
"server": "192.168.1.1",
303+
"unit": "volts",
304+
},
305+
},
306+
{
307+
map[string]interface{}{
308+
"value": float64(2610),
309+
"status": 1,
310+
},
311+
map[string]string{
312+
"name": "fan_1a_tach",
313+
"server": "192.168.1.1",
314+
"unit": "rpm",
315+
},
316+
},
317+
{
318+
map[string]interface{}{
319+
"value": float64(1775),
320+
"status": 1,
321+
},
322+
map[string]string{
323+
"name": "fan_1b_tach",
324+
"server": "192.168.1.1",
325+
"unit": "rpm",
326+
},
327+
},
328+
}
329+
330+
for _, test := range testsWithoutCutsomTagServer {
331+
acc.AssertContainsTaggedFields(t, "ipmi_sensor", test.fields, test.tags)
332+
}
229333
}
230334

231335
// fackeExecCommand is a helper function that mock

0 commit comments

Comments
 (0)