diff --git a/plugins/inputs/ipmi_sensor/README.md b/plugins/inputs/ipmi_sensor/README.md index 820af50a4..74cfe3bc5 100644 --- a/plugins/inputs/ipmi_sensor/README.md +++ b/plugins/inputs/ipmi_sensor/README.md @@ -22,7 +22,10 @@ ipmitool -I lan -H SERVER -U USERID -P PASSW0RD sdr [[inputs.ipmi_sensor]] ## optionally specify the path to the ipmitool executable # 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 ## [username[:password]@][protocol[(address)]] ## e.g. diff --git a/plugins/inputs/ipmi_sensor/connection.go b/plugins/inputs/ipmi_sensor/connection.go index b93cda7d4..87922b984 100644 --- a/plugins/inputs/ipmi_sensor/connection.go +++ b/plugins/inputs/ipmi_sensor/connection.go @@ -14,10 +14,12 @@ type Connection struct { Password string Port int Interface string + Privilege string } -func NewConnection(server string) *Connection { +func NewConnection(server string, privilege string) *Connection { conn := &Connection{} + conn.Privilege = privilege inx1 := strings.LastIndex(server, "@") inx2 := strings.Index(server, "(") inx3 := strings.Index(server, ")") @@ -59,7 +61,9 @@ func (t *Connection) options() []string { if t.Port != 0 { options = append(options, "-p", strconv.Itoa(t.Port)) } - + if t.Privilege != "" { + options = append(options, "-L", t.Privilege) + } return options } diff --git a/plugins/inputs/ipmi_sensor/connection_test.go b/plugins/inputs/ipmi_sensor/connection_test.go index 13a62061d..74944890f 100644 --- a/plugins/inputs/ipmi_sensor/connection_test.go +++ b/plugins/inputs/ipmi_sensor/connection_test.go @@ -23,6 +23,7 @@ func TestNewConnection(t *testing.T) { Username: "USERID", Password: "PASSW0RD", Interface: "lan", + Privilege: "USER", }, }, { @@ -32,11 +33,12 @@ func TestNewConnection(t *testing.T) { Username: "USERID", Password: "PASS:!@#$%^&*(234)_+W0RD", Interface: "lan", + Privilege: "USER", }, }, } for _, v := range testData { - assert.Equal(t, v.con, NewConnection(v.addr)) + assert.Equal(t, v.con, NewConnection(v.addr, "USER")) } } diff --git a/plugins/inputs/ipmi_sensor/ipmi.go b/plugins/inputs/ipmi_sensor/ipmi.go index 9448208bd..2d7bcaefc 100644 --- a/plugins/inputs/ipmi_sensor/ipmi.go +++ b/plugins/inputs/ipmi_sensor/ipmi.go @@ -17,15 +17,19 @@ var ( ) type Ipmi struct { - Path string - Servers []string - Timeout internal.Duration + Path string + Privilege string + Servers []string + Timeout internal.Duration } var sampleConfig = ` ## optionally specify the path to the ipmitool executable # 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 ## [username[:password]@][protocol[(address)]] ## e.g. @@ -77,13 +81,11 @@ func (m *Ipmi) Gather(acc telegraf.Accumulator) error { func (m *Ipmi) parse(acc telegraf.Accumulator, server string) error { opts := make([]string, 0) hostname := "" - if server != "" { - conn := NewConnection(server) + conn := NewConnection(server, m.Privilege) hostname = conn.Hostname opts = conn.options() } - opts = append(opts, "sdr") cmd := execCommand(m.Path, opts...) out, err := internal.CombinedOutputTimeout(cmd, m.Timeout.Duration) diff --git a/plugins/inputs/ipmi_sensor/ipmi_test.go b/plugins/inputs/ipmi_sensor/ipmi_test.go index a6f5148c1..3d45f2fa8 100644 --- a/plugins/inputs/ipmi_sensor/ipmi_test.go +++ b/plugins/inputs/ipmi_sensor/ipmi_test.go @@ -15,9 +15,10 @@ import ( func TestGather(t *testing.T) { i := &Ipmi{ - Servers: []string{"USERID:PASSW0RD@lan(192.168.1.1)"}, - Path: "ipmitool", - Timeout: internal.Duration{Duration: time.Second * 5}, + Servers: []string{"USERID:PASSW0RD@lan(192.168.1.1)"}, + Path: "ipmitool", + Privilege: "USER", + Timeout: internal.Duration{Duration: time.Second * 5}, } // overwriting exec commands with mock commands execCommand = fakeExecCommand @@ -29,7 +30,7 @@ func TestGather(t *testing.T) { 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, "lan", conn.Interface)