Added optional sudo
This commit is contained in:
parent
e77a3e26ee
commit
fa739c423c
1032
Cargo.lock
generated
1032
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "prometheus_wireguard_exporter"
|
||||
version = "3.4.0"
|
||||
version = "3.4.1"
|
||||
authors = ["Francesco Cogno <francesco.cogno@outlook.com>"]
|
||||
description = "Prometheus WireGuard Exporter"
|
||||
edition = "2018"
|
||||
|
14
src/main.rs
14
src/main.rs
@ -47,11 +47,21 @@ async fn perform_request(
|
||||
let mut wg_accumulator: Option<WireGuard> = None;
|
||||
|
||||
for interface_to_handle in interfaces_to_handle {
|
||||
let output = Command::new("wg")
|
||||
let output = if options.prepend_sudo {
|
||||
Command::new("sudo")
|
||||
.arg("wg")
|
||||
.arg("show")
|
||||
.arg(&interface_to_handle)
|
||||
.arg("dump")
|
||||
.output()?;
|
||||
.output()?
|
||||
} else {
|
||||
Command::new("wg")
|
||||
.arg("show")
|
||||
.arg(&interface_to_handle)
|
||||
.arg("dump")
|
||||
.output()?
|
||||
};
|
||||
|
||||
let output_stdout_str = String::from_utf8(output.stdout)?;
|
||||
trace!(
|
||||
"wg show {} dump stdout == {}",
|
||||
|
@ -1,6 +1,7 @@
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct Options {
|
||||
pub verbose: bool,
|
||||
pub prepend_sudo: bool,
|
||||
pub separate_allowed_ips: bool,
|
||||
pub extract_names_config_file: Option<String>,
|
||||
pub interfaces: Option<Vec<String>>,
|
||||
@ -11,6 +12,7 @@ impl Options {
|
||||
pub fn from_claps(matches: &clap::ArgMatches<'_>) -> Options {
|
||||
let options = Options {
|
||||
verbose: matches.is_present("verbose"),
|
||||
prepend_sudo: matches.is_present("prepend_sudo"),
|
||||
separate_allowed_ips: matches.is_present("separate_allowed_ips"),
|
||||
extract_names_config_file: matches
|
||||
.value_of("extract_names_config_files")
|
||||
@ -29,8 +31,3 @@ impl Options {
|
||||
options
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user