Add hex_key parameter for IPMI input plugin connection (#8524)
This commit is contained in:
parent
c47fcf6626
commit
dd09f46863
|
|
@ -19,6 +19,11 @@ When one or more servers are specified, the plugin will use the following comman
|
|||
ipmitool -I lan -H SERVER -U USERID -P PASSW0RD sdr
|
||||
```
|
||||
|
||||
Any of the following parameters will be added to the aformentioned query if they're configured:
|
||||
```
|
||||
-y hex_key -L privilege
|
||||
```
|
||||
|
||||
### Configuration
|
||||
|
||||
```toml
|
||||
|
|
@ -53,6 +58,9 @@ ipmitool -I lan -H SERVER -U USERID -P PASSW0RD sdr
|
|||
|
||||
## Schema Version: (Optional, defaults to version 1)
|
||||
metric_version = 2
|
||||
|
||||
## Optionally provide the hex key for the IMPI connection.
|
||||
# hex_key = ""
|
||||
```
|
||||
|
||||
### Measurements
|
||||
|
|
|
|||
|
|
@ -15,11 +15,14 @@ type Connection struct {
|
|||
Port int
|
||||
Interface string
|
||||
Privilege string
|
||||
HexKey string
|
||||
}
|
||||
|
||||
func NewConnection(server string, privilege string) *Connection {
|
||||
conn := &Connection{}
|
||||
conn.Privilege = privilege
|
||||
func NewConnection(server, privilege, hexKey string) *Connection {
|
||||
conn := &Connection{
|
||||
Privilege: privilege,
|
||||
HexKey: hexKey,
|
||||
}
|
||||
inx1 := strings.LastIndex(server, "@")
|
||||
inx2 := strings.Index(server, "(")
|
||||
|
||||
|
|
@ -57,6 +60,9 @@ func (t *Connection) options() []string {
|
|||
"-I", intf,
|
||||
}
|
||||
|
||||
if t.HexKey != "" {
|
||||
options = append(options, "-y", t.HexKey)
|
||||
}
|
||||
if t.Port != 0 {
|
||||
options = append(options, "-p", strconv.Itoa(t.Port))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package ipmi_sensor
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type conTest struct {
|
||||
|
|
@ -24,6 +24,7 @@ func TestNewConnection(t *testing.T) {
|
|||
Password: "PASSW0RD",
|
||||
Interface: "lan",
|
||||
Privilege: "USER",
|
||||
HexKey: "0001",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -34,11 +35,46 @@ func TestNewConnection(t *testing.T) {
|
|||
Password: "PASS:!@#$%^&*(234)_+W0RD",
|
||||
Interface: "lan",
|
||||
Privilege: "USER",
|
||||
HexKey: "0001",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, v := range testData {
|
||||
assert.Equal(t, v.con, NewConnection(v.addr, "USER"))
|
||||
require.EqualValues(t, v.con, NewConnection(v.addr, "USER", "0001"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCommandOptions(t *testing.T) {
|
||||
testData := []struct {
|
||||
connection *Connection
|
||||
options []string
|
||||
}{
|
||||
{
|
||||
&Connection{
|
||||
Hostname: "192.168.1.1",
|
||||
Username: "user",
|
||||
Password: "password",
|
||||
Interface: "lan",
|
||||
Privilege: "USER",
|
||||
HexKey: "0001",
|
||||
},
|
||||
[]string{"-H", "192.168.1.1", "-U", "user", "-P", "password", "-I", "lan", "-y", "0001", "-L", "USER"},
|
||||
},
|
||||
{
|
||||
&Connection{
|
||||
Hostname: "192.168.1.1",
|
||||
Username: "user",
|
||||
Password: "password",
|
||||
Interface: "lan",
|
||||
Privilege: "USER",
|
||||
HexKey: "",
|
||||
},
|
||||
[]string{"-H", "192.168.1.1", "-U", "user", "-P", "password", "-I", "lan", "-L", "USER"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, data := range testData {
|
||||
require.EqualValues(t, data.options, data.connection.options())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ var (
|
|||
type Ipmi struct {
|
||||
Path string
|
||||
Privilege string
|
||||
HexKey string `toml:"hex_key"`
|
||||
Servers []string
|
||||
Timeout internal.Duration
|
||||
MetricVersion int
|
||||
|
|
@ -65,6 +66,9 @@ var sampleConfig = `
|
|||
|
||||
## Schema Version: (Optional, defaults to version 1)
|
||||
metric_version = 2
|
||||
|
||||
## Optionally provide the hex key for the IMPI connection.
|
||||
# hex_key = ""
|
||||
`
|
||||
|
||||
// SampleConfig returns the documentation about the sample configuration
|
||||
|
|
@ -110,7 +114,7 @@ func (m *Ipmi) parse(acc telegraf.Accumulator, server string) error {
|
|||
opts := make([]string, 0)
|
||||
hostname := ""
|
||||
if server != "" {
|
||||
conn := NewConnection(server, m.Privilege)
|
||||
conn := NewConnection(server, m.Privilege, m.HexKey)
|
||||
hostname = conn.Hostname
|
||||
opts = conn.options()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import (
|
|||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/internal"
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
|
@ -20,7 +19,9 @@ func TestGather(t *testing.T) {
|
|||
Path: "ipmitool",
|
||||
Privilege: "USER",
|
||||
Timeout: internal.Duration{Duration: time.Second * 5},
|
||||
HexKey: "1234567F",
|
||||
}
|
||||
|
||||
// overwriting exec commands with mock commands
|
||||
execCommand = fakeExecCommand
|
||||
var acc testutil.Accumulator
|
||||
|
|
@ -29,11 +30,12 @@ func TestGather(t *testing.T) {
|
|||
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, acc.NFields(), 262, "non-numeric measurements should be ignored")
|
||||
require.EqualValues(t, acc.NFields(), 262, "non-numeric measurements should be ignored")
|
||||
|
||||
conn := NewConnection(i.Servers[0], i.Privilege)
|
||||
assert.Equal(t, "USERID", conn.Username)
|
||||
assert.Equal(t, "lan", conn.Interface)
|
||||
conn := NewConnection(i.Servers[0], i.Privilege, i.HexKey)
|
||||
require.EqualValues(t, "USERID", conn.Username)
|
||||
require.EqualValues(t, "lan", conn.Interface)
|
||||
require.EqualValues(t, "1234567F", conn.HexKey)
|
||||
|
||||
var testsWithServer = []struct {
|
||||
fields map[string]interface{}
|
||||
|
|
@ -388,6 +390,7 @@ func TestGatherV2(t *testing.T) {
|
|||
Privilege: "USER",
|
||||
Timeout: internal.Duration{Duration: time.Second * 5},
|
||||
MetricVersion: 2,
|
||||
HexKey: "0000000F",
|
||||
}
|
||||
// overwriting exec commands with mock commands
|
||||
execCommand = fakeExecCommandV2
|
||||
|
|
@ -397,9 +400,10 @@ func TestGatherV2(t *testing.T) {
|
|||
|
||||
require.NoError(t, err)
|
||||
|
||||
conn := NewConnection(i.Servers[0], i.Privilege)
|
||||
assert.Equal(t, "USERID", conn.Username)
|
||||
assert.Equal(t, "lan", conn.Interface)
|
||||
conn := NewConnection(i.Servers[0], i.Privilege, i.HexKey)
|
||||
require.EqualValues(t, "USERID", conn.Username)
|
||||
require.EqualValues(t, "lan", conn.Interface)
|
||||
require.EqualValues(t, "0000000F", conn.HexKey)
|
||||
|
||||
var testsWithServer = []struct {
|
||||
fields map[string]interface{}
|
||||
|
|
|
|||
Loading…
Reference in New Issue