File tree 2 files changed +33
-1
lines changed
plugins/inputs/ipmi_sensor
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,11 @@ ipmitool -I lan -H SERVER -U USERID -P PASSW0RD sdr
27
27
# # optionally specify the path to the ipmitool executable
28
28
# path = "/usr/bin/ipmitool"
29
29
# #
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
+ # #
30
35
# # optionally force session privilege level. Can be CALLBACK, USER, OPERATOR, ADMINISTRATOR
31
36
# privilege = "ADMINISTRATOR"
32
37
# #
@@ -86,6 +91,21 @@ ipmi device node. When using udev you can create the device node giving
86
91
```
87
92
KERNEL=="ipmi*", MODE="660", GROUP="telegraf"
88
93
```
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
+ ```
89
109
90
110
### Example Output
91
111
Original file line number Diff line number Diff line change @@ -32,12 +32,18 @@ type Ipmi struct {
32
32
Servers []string
33
33
Timeout internal.Duration
34
34
MetricVersion int
35
+ UseSudo bool
35
36
}
36
37
37
38
var sampleConfig = `
38
39
## optionally specify the path to the ipmitool executable
39
40
# path = "/usr/bin/ipmitool"
40
41
##
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
+ ##
41
47
## optionally force session privilege level. Can be CALLBACK, USER, OPERATOR, ADMINISTRATOR
42
48
# privilege = "ADMINISTRATOR"
43
49
##
@@ -112,7 +118,13 @@ func (m *Ipmi) parse(acc telegraf.Accumulator, server string) error {
112
118
if m .MetricVersion == 2 {
113
119
opts = append (opts , "elist" )
114
120
}
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 ... )
116
128
out , err := internal .CombinedOutputTimeout (cmd , m .Timeout .Duration )
117
129
timestamp := time .Now ()
118
130
if err != nil {
You can’t perform that action at this time.
0 commit comments