diff --git a/LibreNMS/Alert/Transport/Alertmanager.php b/LibreNMS/Alert/Transport/Alertmanager.php
index 8e06a35430..4d84e19ac0 100644
--- a/LibreNMS/Alert/Transport/Alertmanager.php
+++ b/LibreNMS/Alert/Transport/Alertmanager.php
@@ -36,10 +36,13 @@ class Alertmanager extends Transport
$alertmanager_opts = $this->parseUserOptions($this->config['alertmanager-options']);
$alertmanager_opts['url'] = $this->config['alertmanager-url'];
- return $this->contactAlertmanager($obj, $alertmanager_opts);
+ $alertmanager_username = $this->config['alertmanager-username'];
+ $alertmanager_password = $this->config['alertmanager-password'];
+
+ return $this->contactAlertmanager($obj, $alertmanager_opts, $alertmanager_username, $alertmanager_password);
}
- public function contactAlertmanager($obj, $api)
+ public function contactAlertmanager($obj, $api, string $username, string $password)
{
if ($obj['state'] == AlertState::RECOVERED) {
$alertmanager_status = 'endsAt';
@@ -74,10 +77,10 @@ class Alertmanager extends Transport
}
}
- return $this->postAlerts($url, $data);
+ return $this->postAlerts($url, $data, $username, $password);
}
- public static function postAlerts($url, $data)
+ public static function postAlerts($url, $data, string $username, string $password)
{
$curl = curl_init();
Proxy::applyToCurl($curl);
@@ -89,6 +92,12 @@ class Alertmanager extends Transport
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, 5000);
curl_setopt($curl, CURLOPT_POST, true);
+ if ($username != '' && $password != '') {
+ curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
+ curl_setopt($curl, CURLOPT_USERNAME, $username);
+ curl_setopt($curl, CURLOPT_PASSWORD, $password);
+ }
+
$alert_message = json_encode($data);
curl_setopt($curl, CURLOPT_POSTFIELDS, $alert_message);
@@ -133,6 +142,18 @@ class Alertmanager extends Transport
'descr' => 'Alertmanager Webhook URL(s). Can contain comma-separated URLs',
'type' => 'text',
],
+ [
+ 'title' => 'Alertmanager Username',
+ 'name' => 'alertmanager-username',
+ 'descr' => 'Alertmanager Basic Username to authenticate to Alertmanager',
+ 'type' => 'text',
+ ],
+ [
+ 'title' => 'Alertmanager Password',
+ 'name' => 'alertmanager-password',
+ 'descr' => 'Alertmanager Basic Password to authenticate to Alertmanager',
+ 'type' => 'password',
+ ],
[
'title' => 'Alertmanager Options',
'name' => 'alertmanager-options',
diff --git a/doc/Alerting/Transports.md b/doc/Alerting/Transports.md
index d7ba461ef2..942a931505 100644
--- a/doc/Alerting/Transports.md
+++ b/doc/Alerting/Transports.md
@@ -75,6 +75,9 @@ label's value will be the string you provided just as it was a fixed string.
Multiple Alertmanager URLs (comma separated) are supported. Each
URL will be tried and the search will stop at the first success.
+Basic HTTP authentication with a username and a password is supported.
+If you let those value blank, no authentication will be used.
+
[Alertmanager Docs](https://prometheus.io/docs/alerting/alertmanager/)
**Example:**
@@ -82,6 +85,8 @@ URL will be tried and the search will stop at the first success.
| Config | Example |
| ------ | ------- |
| Alertmanager URL(s) | http://alertmanager1.example.com,http://alertmanager2.example.com |
+| Alertmanager Username | myUsername |
+| Alertmanager Password | myPassword |
| Alertmanager Options: | source=librenms
customlabel=value
extra_dynamic_value=variable_name |
## API