Skip to content

Commit 498aab6

Browse files
authored
Add sudo config parameter (#172)
1 parent e75a7ad commit 498aab6

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ discovery:
9595
scripts:
9696
- name: <string>
9797
command: <string>
98+
sudo: <boolean>
9899
args:
99100
- <string>
100101
# by default the env cannot be overwritten by query parameters.
@@ -123,7 +124,9 @@ scripts_configs:
123124
- <string>
124125
```
125126
126-
The `name` of the script must be a valid Prometheus label value. The `command` string is the script which is executed with all arguments specified in `args`. To add dynamic arguments you can pass the `params` query parameter with a list of query parameters which values should be added as argument. The program will be executed directly, without a shell being invoked, and it is recommended that it be specified by path instead of relying on ``$PATH``.
127+
The `name` of the script must be a valid Prometheus label value. The `command` string is the script which is executed with all arguments specified in `args`. To add dynamic arguments you can pass the `params` query parameter with a list of query parameters which values should be added as argument. The program will be executed directly, without a shell being invoked, and it is recommended that it be specified by path instead of relying on ``$PATH``.
128+
129+
If `sudo` is defined and set to `true`, the command will be executed with privileged (root) permissions by executing the `command` with a pre-fixed `sudo`. Note that you still need to create the relevant sudoers entries, script_exporter will not do this for you.
127130

128131
The optional `env` key allows to run the script with custom environment variables.
129132

pkg/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type ScriptConfig struct {
7171
UseExpiredCacheOnError bool `yaml:"useExpiredCacheOnError"`
7272
CacheDuration string `yaml:"cacheDuration"`
7373
Discovery scriptDiscovery `yaml:"discovery"`
74+
Sudo bool `yaml:"sudo"`
7475
}
7576

7677
// LoadConfig reads the configuration file and umarshal the data into the config struct
@@ -159,6 +160,9 @@ func (c *Config) GetRunArgs(scriptName string) ([]string, error) {
159160
return strings.Split(script.Script, " "), nil
160161
}
161162
var runArgs []string
163+
if script.Sudo {
164+
runArgs = append(runArgs, "sudo")
165+
}
162166
runArgs = append(runArgs, script.Command)
163167
runArgs = append(runArgs, script.Args...)
164168
return runArgs, nil

0 commit comments

Comments
 (0)