Skip to content

Commit 66ed2d9

Browse files
gescheitidohalevi
authored and
idohalevi
committed
Add use_sudo option to ipmi_sensor input (influxdata#6798)
1 parent bc5a1b5 commit 66ed2d9

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

plugins/inputs/ipmi_sensor/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ ipmitool -I lan -H SERVER -U USERID -P PASSW0RD sdr
2727
## optionally specify the path to the ipmitool executable
2828
# path = "/usr/bin/ipmitool"
2929
##
30+
## Setting 'use_sudo' to true will make use of sudo to run ipmitool.
31+
## Sudo must be configured to allow the telegraf user to run ipmitool
32+
## without a password.
33+
# use_sudo = false
34+
##
3035
## optionally force session privilege level. Can be CALLBACK, USER, OPERATOR, ADMINISTRATOR
3136
# privilege = "ADMINISTRATOR"
3237
##
@@ -86,6 +91,21 @@ ipmi device node. When using udev you can create the device node giving
8691
```
8792
KERNEL=="ipmi*", MODE="660", GROUP="telegraf"
8893
```
94+
Alternatively, it is possible to use sudo. You will need the following in your telegraf config:
95+
```toml
96+
[[inputs.ipmi_sensor]]
97+
use_sudo = true
98+
```
99+
100+
You will also need to update your sudoers file:
101+
102+
```bash
103+
$ visudo
104+
# Add the following line:
105+
Cmnd_Alias IPMITOOL = /usr/bin/ipmitool *
106+
telegraf ALL=(root) NOPASSWD: IPMITOOL
107+
Defaults!IPMITOOL !logfile, !syslog, !pam_session
108+
```
89109

90110
### Example Output
91111

plugins/inputs/ipmi_sensor/ipmi.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,18 @@ type Ipmi struct {
3232
Servers []string
3333
Timeout internal.Duration
3434
MetricVersion int
35+
UseSudo bool
3536
}
3637

3738
var sampleConfig = `
3839
## optionally specify the path to the ipmitool executable
3940
# path = "/usr/bin/ipmitool"
4041
##
42+
## Setting 'use_sudo' to true will make use of sudo to run ipmitool.
43+
## Sudo must be configured to allow the telegraf user to run ipmitool
44+
## without a password.
45+
# use_sudo = false
46+
##
4147
## optionally force session privilege level. Can be CALLBACK, USER, OPERATOR, ADMINISTRATOR
4248
# privilege = "ADMINISTRATOR"
4349
##
@@ -112,7 +118,13 @@ func (m *Ipmi) parse(acc telegraf.Accumulator, server string) error {
112118
if m.MetricVersion == 2 {
113119
opts = append(opts, "elist")
114120
}
115-
cmd := execCommand(m.Path, opts...)
121+
name := m.Path
122+
if m.UseSudo {
123+
// -n - avoid prompting the user for input of any kind
124+
opts = append([]string{"-n", name}, opts...)
125+
name = "sudo"
126+
}
127+
cmd := execCommand(name, opts...)
116128
out, err := internal.CombinedOutputTimeout(cmd, m.Timeout.Duration)
117129
timestamp := time.Now()
118130
if err != nil {

0 commit comments

Comments
 (0)