From ec967e7f9d0dbc41a0957d607cdaf1aa6068c689 Mon Sep 17 00:00:00 2001 From: Francesco Cogno Date: Sun, 10 May 2020 15:40:45 +0200 Subject: [PATCH] Parse case insensitive --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 7 ++++--- src/main.rs | 5 +++++ src/wireguard_config.rs | 6 ++++-- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8b44d30..899c350 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -685,7 +685,7 @@ dependencies = [ [[package]] name = "prometheus_wireguard_exporter" -version = "3.3.1" +version = "3.3.2" 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 a2daca8..06b9e71 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "prometheus_wireguard_exporter" -version = "3.3.1" +version = "3.3.2" authors = ["Francesco Cogno "] description = "Prometheus WireGuard Exporter" edition = "2018" diff --git a/README.md b/README.md index d4f5077..8a7c72b 100644 --- a/README.md +++ b/README.md @@ -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) -[![release](https://img.shields.io/github/release/MindFlavor/prometheus_wireguard_exporter.svg)](https://github.com/MindFlavor/prometheus_wireguard_exporter/tree/3.3.1) -[![tag](https://img.shields.io/github/tag/mindflavor/prometheus_wireguard_exporter.svg)](https://github.com/MindFlavor/prometheus_wireguard_exporter/tree/3.3.1) +[![release](https://img.shields.io/github/release/MindFlavor/prometheus_wireguard_exporter.svg)](https://github.com/MindFlavor/prometheus_wireguard_exporter/tree/3.3.2) +[![tag](https://img.shields.io/github/tag/mindflavor/prometheus_wireguard_exporter.svg)](https://github.com/MindFlavor/prometheus_wireguard_exporter/tree/3.3.2) [![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.3.1.svg)](https://img.shields.io/github/commits-since/mindflavor/prometheus_wireguard_exporter/3.3.1.svg) +[![commitssince](https://img.shields.io/github/commits-since/mindflavor/prometheus_wireguard_exporter/3.3.2.svg)](https://img.shields.io/github/commits-since/mindflavor/prometheus_wireguard_exporter/3.3.2.svg) ## Intro @@ -18,6 +18,7 @@ A Prometheus exporter for [WireGuard](https://www.wireguard.com), written in Rus ## Changelog +* From release [3.3.2](https://github.com/MindFlavor/prometheus_wireguard_exporter/releases/tag/3.3.2) the exporter parses the peer file in a case-insensitive manner. * From release [3.3.1](https://github.com/MindFlavor/prometheus_wireguard_exporter/releases/tag/3.3.1) the exporter accepts multiple interfaces in the command line options. Just pass the `-i` parameter multiple times. Note the not specifying the interface is equivalent to specifying every one of them (the exporter will pass the `all` parameter to `wg show` command). * **BREAKING** Starting from release [3.3.0](https://github.com/MindFlavor/prometheus_wireguard_exporter/releases/tag/3.3.0) the exporter allows you to specify a different interface from the file name. Previously if you specified the file name (the `-n` flag) the program would infer the interface name from the file name. Now the two items are decoupled: you need to specify the file name (with `-n`) and the interface name (with `-i`) separately. Thank you [Vincent Debergue](https://github.com/vdebergue) for helping with this (see issue [#22](https://github.com/MindFlavor/prometheus_wireguard_exporter/issues/22)). Upgrading from [3.2.4](https://github.com/MindFlavor/prometheus_wireguard_exporter/releases/tag/3.2.4): Please note that the `-n` flag no longer infer automatically the interface name from the file name. We now have the `-i` parameter for that. In order to keep the previous behaviour (if you use the `-n` flag) please add the `-i` flag to the command line arguments as well. For example, if you had `prometheus_wireguard_exporter -n /etc/wireguard/wg0.conf` you must specify `prometheus_wireguard_exporter -n /etc/wireguard/wg0.conf -i wg0` to keep the same behaviour. * From release [3.0.0](https://github.com/MindFlavor/prometheus_wireguard_exporter/releases/tag/3.0.0) the exporter allows two label modes: one is to dump every allowed ip in a single label (called `allowed_ips`) along with their subnets. The second one is to create a pair of labels for each allowed ip/subnet pair (called `allowed_ip_0`/`allowed_subnet_0`, `allowed_ip_1`/`allowed_subnet_1` and so on for every allowed ip). The default if the single label mode but you can enable the second mode by specifying the `-s` switch at startup. Thank you [Toon Schoenmakers](https://github.com/schoentoon) for this solution (see issue [#8](https://github.com/MindFlavor/prometheus_wireguard_exporter/issues/8)). diff --git a/src/main.rs b/src/main.rs index 8892caa..d43e482 100644 --- a/src/main.rs +++ b/src/main.rs @@ -168,6 +168,11 @@ async fn main() { } env_logger::init(); + info!( + "{} v{} starting...", + env!("CARGO_PKG_NAME"), + env!("CARGO_PKG_VERSION") + ); info!("using options: {:?}", options); let bind = matches.value_of("port").unwrap(); diff --git a/src/wireguard_config.rs b/src/wireguard_config.rs index 6c905fb..4ed63b1 100644 --- a/src/wireguard_config.rs +++ b/src/wireguard_config.rs @@ -34,9 +34,11 @@ impl<'a> TryFrom<&[&'a str]> for PeerEntry<'a> { let mut name = None; for line in lines { - if line.starts_with("PublicKey") { + let line_lowercase = line.to_lowercase(); + + if line_lowercase.starts_with("publickey") { public_key = after_char(line, '=').trim(); - } else if line.starts_with("AllowedIPs") { + } else if line_lowercase.starts_with("allowedips") { allowed_ips = after_char(line, '=').trim(); } else if line.starts_with('#') { // since the pound sign is 1 byte the below slice will work