Support for stderr output in TRACE log level (#25)

* exported stderr

* version bump
This commit is contained in:
Francesco Cogno 2020-03-24 11:57:54 +01:00 committed by GitHub
parent 8b3b015492
commit ceeea75b3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 14 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "prometheus_wireguard_exporter" name = "prometheus_wireguard_exporter"
version = "3.2.3" version = "3.2.4"
authors = ["Francesco Cogno <francesco.cogno@outlook.com>"] authors = ["Francesco Cogno <francesco.cogno@outlook.com>"]
description = "Prometheus WireGuard Exporter" description = "Prometheus WireGuard Exporter"
edition = "2018" edition = "2018"
@ -25,5 +25,5 @@ failure = "0.1.5"
hyper = { version = "0.13.0-alpha.4" , features = ["unstable-stream"] } hyper = { version = "0.13.0-alpha.4" , features = ["unstable-stream"] }
http = "0.1.17" http = "0.1.17"
tokio = "0.2.0-alpha.6" tokio = "0.2.0-alpha.6"
prometheus_exporter_base = { version = "0.30.1" } prometheus_exporter_base = { version = "0.30.2" }
regex = "1.3.1" regex = "1.3.1"

View File

@ -4,11 +4,11 @@
[![Crate](https://img.shields.io/crates/v/prometheus_wireguard_exporter.svg)](https://crates.io/crates/prometheus_wireguard_exporter) [![cratedown](https://img.shields.io/crates/d/prometheus_wireguard_exporter.svg)](https://crates.io/crates/prometheus_wireguard_exporter) [![cratelastdown](https://img.shields.io/crates/dv/prometheus_wireguard_exporter.svg)](https://crates.io/crates/prometheus_wireguard_exporter) [![Crate](https://img.shields.io/crates/v/prometheus_wireguard_exporter.svg)](https://crates.io/crates/prometheus_wireguard_exporter) [![cratedown](https://img.shields.io/crates/d/prometheus_wireguard_exporter.svg)](https://crates.io/crates/prometheus_wireguard_exporter) [![cratelastdown](https://img.shields.io/crates/dv/prometheus_wireguard_exporter.svg)](https://crates.io/crates/prometheus_wireguard_exporter)
[![release](https://img.shields.io/github/release/MindFlavor/prometheus_wireguard_exporter.svg)](https://github.com/MindFlavor/prometheus_wireguard_exporter/tree/3.2.3) [![release](https://img.shields.io/github/release/MindFlavor/prometheus_wireguard_exporter.svg)](https://github.com/MindFlavor/prometheus_wireguard_exporter/tree/3.2.4)
[![tag](https://img.shields.io/github/tag/mindflavor/prometheus_wireguard_exporter.svg)](https://github.com/MindFlavor/prometheus_wireguard_exporter/tree/3.2.3) [![tag](https://img.shields.io/github/tag/mindflavor/prometheus_wireguard_exporter.svg)](https://github.com/MindFlavor/prometheus_wireguard_exporter/tree/3.2.4)
[![Build Status](https://travis-ci.org/MindFlavor/prometheus_wireguard_exporter.svg?branch=master)](https://travis-ci.org/MindFlavor/prometheus_wireguard_exporter) [![Build Status](https://travis-ci.org/MindFlavor/prometheus_wireguard_exporter.svg?branch=master)](https://travis-ci.org/MindFlavor/prometheus_wireguard_exporter)
[![commitssince](https://img.shields.io/github/commits-since/mindflavor/prometheus_wireguard_exporter/3.2.3.svg)](https://img.shields.io/github/commits-since/mindflavor/prometheus_wireguard_exporter/3.2.3.svg) [![commitssince](https://img.shields.io/github/commits-since/mindflavor/prometheus_wireguard_exporter/3.2.4.svg)](https://img.shields.io/github/commits-since/mindflavor/prometheus_wireguard_exporter/3.2.4.svg)
## Intro ## Intro

View File

@ -23,13 +23,13 @@ use std::sync::Arc;
fn wg_with_text( fn wg_with_text(
wg_config_str: &str, wg_config_str: &str,
wg_output_str: &str, wg_output_stdout_str: &str,
options: Arc<Options>, options: Arc<Options>,
) -> Result<String, failure::Error> { ) -> Result<String, failure::Error> {
let pehm = peer_entry_hashmap_try_from(wg_config_str)?; let pehm = peer_entry_hashmap_try_from(wg_config_str)?;
trace!("pehm == {:?}", pehm); trace!("pehm == {:?}", pehm);
let wg = WireGuard::try_from(wg_output_str)?; let wg = WireGuard::try_from(wg_output_stdout_str)?;
Ok(wg.render_with_names( Ok(wg.render_with_names(
Some(&pehm), Some(&pehm),
options.separate_allowed_ips, options.separate_allowed_ips,
@ -61,30 +61,40 @@ async fn perform_request(
.arg(&interface_str) .arg(&interface_str)
.arg("dump") .arg("dump")
.output()?; .output()?;
let output_str = String::from_utf8(output.stdout)?; let output_stdout_str = String::from_utf8(output.stdout)?;
trace!("wg show output == {}", output_str); trace!(
"wg show {} dump stdout == {}",
interface_str,
output_stdout_str
);
let output_stderr_str = String::from_utf8(output.stderr)?;
trace!(
"wg show {} dump stderr == {}",
interface_str,
output_stderr_str
);
// the output of wg show is different if we use all or we specify an interface. // the output of wg show is different if we use all or we specify an interface.
// In the first case the first column will be the interface name. In the second case // In the first case the first column will be the interface name. In the second case
// the interface name will be omitted. We need to compensate for the skew somehow (one // the interface name will be omitted. We need to compensate for the skew somehow (one
// column less in the second case). We solve this prepending the interface name in every // column less in the second case). We solve this prepending the interface name in every
// line so the output of the second case will be equal to the first case. // line so the output of the second case will be equal to the first case.
let output_str = if interface_str != "all" { let output_stdout_str = if interface_str != "all" {
debug!("injecting {} to the wg show output", interface_str); debug!("injecting {} to the wg show output", interface_str);
let mut result = String::new(); let mut result = String::new();
for s in output_str.lines() { for s in output_stdout_str.lines() {
result.push_str(&format!("{}\t{}\n", interface_str, s)); result.push_str(&format!("{}\t{}\n", interface_str, s));
} }
result result
} else { } else {
output_str output_stdout_str
}; };
if let Some(extract_names_config_file) = &options.extract_names_config_file { if let Some(extract_names_config_file) = &options.extract_names_config_file {
let wg_config_string = ::std::fs::read_to_string(extract_names_config_file)?; let wg_config_string = ::std::fs::read_to_string(extract_names_config_file)?;
wg_with_text(&wg_config_string as &str, &output_str, options) wg_with_text(&wg_config_string as &str, &output_stdout_str, options)
} else { } else {
let wg = WireGuard::try_from(&output_str as &str)?; let wg = WireGuard::try_from(&output_stdout_str as &str)?;
Ok(wg.render_with_names( Ok(wg.render_with_names(
None, None,
options.separate_allowed_ips, options.separate_allowed_ips,