From e6f02ea7fffa63c177924c0261b8eeecb11ebee2 Mon Sep 17 00:00:00 2001 From: Joe Clarke Date: Sun, 21 Jul 2024 14:03:32 -0400 Subject: [PATCH] Add support for Prometheus pushgateway basic auth (#16230) Co-authored-by: Joe Clarke --- LibreNMS/Data/Store/Prometheus.php | 6 ++++++ doc/Extensions/metrics/Prometheus.md | 8 ++++++++ misc/config_definitions.json | 14 ++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/LibreNMS/Data/Store/Prometheus.php b/LibreNMS/Data/Store/Prometheus.php index 54676d9a4b..1fc0c03150 100644 --- a/LibreNMS/Data/Store/Prometheus.php +++ b/LibreNMS/Data/Store/Prometheus.php @@ -51,6 +51,12 @@ class Prometheus extends BaseDatastore $this->client = Http::client()->baseUrl($this->base_uri); + $user = Config::get('prometheus.user', ''); + $passwd = Config::get('prometheus.password', ''); + if ($user && $passwd) { + $this->client = $this->client->withBasicAuth($user, $passwd); + } + $this->prefix = Config::get('prometheus.prefix', ''); if ($this->prefix) { $this->prefix = "$this->prefix" . '_'; diff --git a/doc/Extensions/metrics/Prometheus.md b/doc/Extensions/metrics/Prometheus.md index c0f98b2d51..644d037c47 100644 --- a/doc/Extensions/metrics/Prometheus.md +++ b/doc/Extensions/metrics/Prometheus.md @@ -35,6 +35,14 @@ continue to function as normal. lnms config:set prometheus.prefix 'librenms' ``` +If your pushgateway uses basic authentication, configure the following: + +!!! setting "poller/prometheus" + ```bash + lnms config:set prometheus.user username + lnms config:set prometheus.password password + ``` + ## Prefix Setting the 'prefix' option will cause all metric names to begin with diff --git a/misc/config_definitions.json b/misc/config_definitions.json index e6d574814b..9016eeb393 100644 --- a/misc/config_definitions.json +++ b/misc/config_definitions.json @@ -5524,6 +5524,20 @@ "section": "prometheus", "order": 4 }, + "prometheus.user": { + "default": "", + "type": "text", + "group": "poller", + "section": "prometheus", + "order": 5 + }, + "prometheus.password": { + "default": "", + "type": "text", + "group": "poller", + "section": "prometheus", + "order": 6 + }, "public_status": { "default": false, "group": "auth",