Add user privilege level setting to IPMI sensors (#3643)
This commit is contained in:
parent
35f1b9f500
commit
2938c2fa79
|
@ -22,7 +22,10 @@ ipmitool -I lan -H SERVER -U USERID -P PASSW0RD sdr
|
||||||
[[inputs.ipmi_sensor]]
|
[[inputs.ipmi_sensor]]
|
||||||
## optionally specify the path to the ipmitool executable
|
## optionally specify the path to the ipmitool executable
|
||||||
# path = "/usr/bin/ipmitool"
|
# path = "/usr/bin/ipmitool"
|
||||||
#
|
##
|
||||||
|
## optionally force session privilege level. Can be CALLBACK, USER, OPERATOR, ADMINISTRATOR
|
||||||
|
# privilege = "ADMINISTRATOR"
|
||||||
|
##
|
||||||
## optionally specify one or more servers via a url matching
|
## optionally specify one or more servers via a url matching
|
||||||
## [username[:password]@][protocol[(address)]]
|
## [username[:password]@][protocol[(address)]]
|
||||||
## e.g.
|
## e.g.
|
||||||
|
|
|
@ -14,10 +14,12 @@ type Connection struct {
|
||||||
Password string
|
Password string
|
||||||
Port int
|
Port int
|
||||||
Interface string
|
Interface string
|
||||||
|
Privilege string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConnection(server string) *Connection {
|
func NewConnection(server string, privilege string) *Connection {
|
||||||
conn := &Connection{}
|
conn := &Connection{}
|
||||||
|
conn.Privilege = privilege
|
||||||
inx1 := strings.LastIndex(server, "@")
|
inx1 := strings.LastIndex(server, "@")
|
||||||
inx2 := strings.Index(server, "(")
|
inx2 := strings.Index(server, "(")
|
||||||
inx3 := strings.Index(server, ")")
|
inx3 := strings.Index(server, ")")
|
||||||
|
@ -59,7 +61,9 @@ func (t *Connection) options() []string {
|
||||||
if t.Port != 0 {
|
if t.Port != 0 {
|
||||||
options = append(options, "-p", strconv.Itoa(t.Port))
|
options = append(options, "-p", strconv.Itoa(t.Port))
|
||||||
}
|
}
|
||||||
|
if t.Privilege != "" {
|
||||||
|
options = append(options, "-L", t.Privilege)
|
||||||
|
}
|
||||||
return options
|
return options
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ func TestNewConnection(t *testing.T) {
|
||||||
Username: "USERID",
|
Username: "USERID",
|
||||||
Password: "PASSW0RD",
|
Password: "PASSW0RD",
|
||||||
Interface: "lan",
|
Interface: "lan",
|
||||||
|
Privilege: "USER",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -32,11 +33,12 @@ func TestNewConnection(t *testing.T) {
|
||||||
Username: "USERID",
|
Username: "USERID",
|
||||||
Password: "PASS:!@#$%^&*(234)_+W0RD",
|
Password: "PASS:!@#$%^&*(234)_+W0RD",
|
||||||
Interface: "lan",
|
Interface: "lan",
|
||||||
|
Privilege: "USER",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range testData {
|
for _, v := range testData {
|
||||||
assert.Equal(t, v.con, NewConnection(v.addr))
|
assert.Equal(t, v.con, NewConnection(v.addr, "USER"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ var (
|
||||||
|
|
||||||
type Ipmi struct {
|
type Ipmi struct {
|
||||||
Path string
|
Path string
|
||||||
|
Privilege string
|
||||||
Servers []string
|
Servers []string
|
||||||
Timeout internal.Duration
|
Timeout internal.Duration
|
||||||
}
|
}
|
||||||
|
@ -25,7 +26,10 @@ type Ipmi struct {
|
||||||
var sampleConfig = `
|
var sampleConfig = `
|
||||||
## optionally specify the path to the ipmitool executable
|
## optionally specify the path to the ipmitool executable
|
||||||
# path = "/usr/bin/ipmitool"
|
# path = "/usr/bin/ipmitool"
|
||||||
#
|
##
|
||||||
|
## optionally force session privilege level. Can be CALLBACK, USER, OPERATOR, ADMINISTRATOR
|
||||||
|
# privilege = "ADMINISTRATOR"
|
||||||
|
##
|
||||||
## optionally specify one or more servers via a url matching
|
## optionally specify one or more servers via a url matching
|
||||||
## [username[:password]@][protocol[(address)]]
|
## [username[:password]@][protocol[(address)]]
|
||||||
## e.g.
|
## e.g.
|
||||||
|
@ -77,13 +81,11 @@ func (m *Ipmi) Gather(acc telegraf.Accumulator) error {
|
||||||
func (m *Ipmi) parse(acc telegraf.Accumulator, server string) error {
|
func (m *Ipmi) parse(acc telegraf.Accumulator, server string) error {
|
||||||
opts := make([]string, 0)
|
opts := make([]string, 0)
|
||||||
hostname := ""
|
hostname := ""
|
||||||
|
|
||||||
if server != "" {
|
if server != "" {
|
||||||
conn := NewConnection(server)
|
conn := NewConnection(server, m.Privilege)
|
||||||
hostname = conn.Hostname
|
hostname = conn.Hostname
|
||||||
opts = conn.options()
|
opts = conn.options()
|
||||||
}
|
}
|
||||||
|
|
||||||
opts = append(opts, "sdr")
|
opts = append(opts, "sdr")
|
||||||
cmd := execCommand(m.Path, opts...)
|
cmd := execCommand(m.Path, opts...)
|
||||||
out, err := internal.CombinedOutputTimeout(cmd, m.Timeout.Duration)
|
out, err := internal.CombinedOutputTimeout(cmd, m.Timeout.Duration)
|
||||||
|
|
|
@ -17,6 +17,7 @@ func TestGather(t *testing.T) {
|
||||||
i := &Ipmi{
|
i := &Ipmi{
|
||||||
Servers: []string{"USERID:PASSW0RD@lan(192.168.1.1)"},
|
Servers: []string{"USERID:PASSW0RD@lan(192.168.1.1)"},
|
||||||
Path: "ipmitool",
|
Path: "ipmitool",
|
||||||
|
Privilege: "USER",
|
||||||
Timeout: internal.Duration{Duration: time.Second * 5},
|
Timeout: internal.Duration{Duration: time.Second * 5},
|
||||||
}
|
}
|
||||||
// overwriting exec commands with mock commands
|
// overwriting exec commands with mock commands
|
||||||
|
@ -29,7 +30,7 @@ func TestGather(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, acc.NFields(), 266, "non-numeric measurements should be ignored")
|
assert.Equal(t, acc.NFields(), 266, "non-numeric measurements should be ignored")
|
||||||
|
|
||||||
conn := NewConnection(i.Servers[0])
|
conn := NewConnection(i.Servers[0], i.Privilege)
|
||||||
assert.Equal(t, "USERID", conn.Username)
|
assert.Equal(t, "USERID", conn.Username)
|
||||||
assert.Equal(t, "lan", conn.Interface)
|
assert.Equal(t, "lan", conn.Interface)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue