From 8170a4c0f7c0eccc6f03023d8f287d008546aeb1 Mon Sep 17 00:00:00 2001 From: Galorhallen Date: Sat, 18 Dec 2021 00:25:23 +0100 Subject: [PATCH] Add readme --- README.md | 27 +++++++++++++++++++++++++++ config/configuration.go | 24 ++++++++++++++++++------ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3c35378..c5cc2a3 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,33 @@ $ docker run \ ekofr/pihole-exporter:latest ``` +A single instance of pihole-exporter can monitor multiple pi-holes instances. +To do so, you can specify a list of hostnames, protocols, passwords/API tokens and ports by separating them with commas in their respective environment variable: + +``` +$ docker run \ + -e 'PIHOLE_PROTOCOL="http,http,http" \ + -e 'PIHOLE_HOSTNAME="192.168.1.2,192.168.1.3,192.168.1.4"' \ + -e "PIHOLE_API_TOKEN="$API_TOKEN1,$API_TOKEN2,$API_TOKEN3" \ + -e "PIHOLE_PORT="8080,8081,8080" \ + -e 'INTERVAL=30s' \ + -e 'PORT=9617' \ + ekofr/pihole-exporter:latest +``` + +If port, protocol and API token/password is the same for all instances, you can specify them only once: + +``` +$ docker run \ + -e 'PIHOLE_PROTOCOL=",http" \ + -e 'PIHOLE_HOSTNAME="192.168.1.2,192.168.1.3,192.168.1.4"' \ + -e "PIHOLE_API_TOKEN="$API_TOKEN" \ + -e "PIHOLE_PORT="8080" \ + -e 'INTERVAL=30s' \ + -e 'PORT=9617' \ + ekofr/pihole-exporter:latest +``` + ### From sources Optionally, you can download and build it from the sources. You have to retrieve the project sources by using one of the following way: diff --git a/config/configuration.go b/config/configuration.go index 0e41d03..45d2383 100644 --- a/config/configuration.go +++ b/config/configuration.go @@ -97,15 +97,27 @@ func (c EnvConfig) Split() []Config { PIHolePort: c.PIHolePort[i], } - if c.PIHoleApiToken != nil && len(c.PIHoleApiToken) > 0 { - if c.PIHoleApiToken[i] != "" { - config.PIHoleApiToken = c.PIHoleApiToken[i] + if c.PIHoleApiToken != nil { + if len(c.PIHoleApiToken) == 1 { + if c.PIHoleApiToken[0] != "" { + config.PIHoleApiToken = c.PIHoleApiToken[0] + } + } else if len(c.PIHoleApiToken) > 1 { + if c.PIHoleApiToken[i] != "" { + config.PIHoleApiToken = c.PIHoleApiToken[i] + } } } - if c.PIHolePassword != nil && len(c.PIHolePassword) > 0 { - if c.PIHolePassword[i] != "" { - config.PIHolePassword = c.PIHolePassword[i] + if c.PIHolePassword != nil { + if len(c.PIHolePassword) == 1 { + if c.PIHolePassword[0] != "" { + config.PIHolePassword = c.PIHolePassword[0] + } + } else if len(c.PIHolePassword) > 1 { + if c.PIHolePassword[i] != "" { + config.PIHolePassword = c.PIHolePassword[i] + } } }