From 4612afe68442254630bb78a949ad8a5805d59727 Mon Sep 17 00:00:00 2001 From: Francesco Cogno Date: Fri, 8 Nov 2019 09:34:17 +0100 Subject: [PATCH] release v3.2.1 --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 8 ++++---- src/wireguard.rs | 15 ++++++++++++--- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6a684ab..46261e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -514,7 +514,7 @@ dependencies = [ [[package]] name = "prometheus_wireguard_exporter" -version = "3.2.0" +version = "3.2.1" dependencies = [ "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 8287caa..856b5a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "prometheus_wireguard_exporter" -version = "3.2.0" +version = "3.2.1" authors = ["Francesco Cogno "] description = "Prometheus WireGuard Exporter" edition = "2018" diff --git a/README.md b/README.md index 695ccf7..a79727d 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ # Prometheus WireGuard Exporter -[![legal](https://img.shields.io/github/license/mindflavor/prometheus_wireguard_exporter.svg)](LICENSE) +[![legal](https://img.shields.io/github/license/mindflavor/prometheus_wireguard_exporter.svg)](LICENSE) ![stability-stable](https://img.shields.io/badge/stability-stable-green.svg) [![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.0) -[![tag](https://img.shields.io/github/tag/mindflavor/prometheus_wireguard_exporter.svg)](https://github.com/MindFlavor/prometheus_wireguard_exporter/tree/3.2.0) +[![release](https://img.shields.io/github/release/MindFlavor/prometheus_wireguard_exporter.svg)](https://github.com/MindFlavor/prometheus_wireguard_exporter/tree/3.2.1) +[![tag](https://img.shields.io/github/tag/mindflavor/prometheus_wireguard_exporter.svg)](https://github.com/MindFlavor/prometheus_wireguard_exporter/tree/3.2.1) [![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.0.svg)](https://img.shields.io/github/commits-since/mindflavor/prometheus_wireguard_exporter/3.2.0.svg) +[![commitssince](https://img.shields.io/github/commits-since/mindflavor/prometheus_wireguard_exporter/3.2.1.svg)](https://img.shields.io/github/commits-since/mindflavor/prometheus_wireguard_exporter/3.2.1.svg) ## Intro diff --git a/src/wireguard.rs b/src/wireguard.rs index 700686d..40a8bc9 100644 --- a/src/wireguard.rs +++ b/src/wireguard.rs @@ -2,10 +2,10 @@ use crate::exporter_error::ExporterError; use crate::wireguard_config::PeerEntryHashMap; use log::{debug, trace}; use prometheus_exporter_base::PrometheusCounter; +use regex::Regex; use std::collections::HashMap; use std::convert::TryFrom; use std::net::SocketAddr; -use regex::Regex; const EMPTY: &str = "(none)"; @@ -78,8 +78,17 @@ impl TryFrom<&str> for WireGuard { let public_key = v[1].to_owned(); let (remote_ip, remote_port) = if let Some(ip_and_port) = to_option_string(v[3]) { - let re = Regex::new(r"^\[(?P[A-Fa-f0-9:]+)%(.*)\]:(?P[0-9]+)$").unwrap(); - let addr: SocketAddr = re.replace_all(&ip_and_port, "[$ip]:$port").parse::().unwrap(); + // this workaround fixes issue #10 (see + // https://github.com/MindFlavor/prometheus_wireguard_exporter/issues/10). + // Whenever it will be fixed upstream this code will be replaced with a + // simple + // let addr: SocketAddr = ip_and_port.parse::().unwrap(); + let re = + Regex::new(r"^\[(?P[A-Fa-f0-9:]+)%(.*)\]:(?P[0-9]+)$").unwrap(); + let addr: SocketAddr = re + .replace_all(&ip_and_port, "[$ip]:$port") + .parse::() + .unwrap(); (Some(addr.ip().to_string()), Some(addr.port())) } else {