From 15aee153881018139bf4037925c5ee897c691884 Mon Sep 17 00:00:00 2001 From: angryp Date: Sat, 2 Mar 2019 07:09:25 +0200 Subject: [PATCH] Alertmanager fix 2 (#9860) * Improved Alertmanager transport * Typo fix * Fix according to Travis fail --- LibreNMS/Alert/Transport/Alertmanager.php | 8 ++++++-- doc/Alerting/Transports.md | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/LibreNMS/Alert/Transport/Alertmanager.php b/LibreNMS/Alert/Transport/Alertmanager.php index bfc1c11f92..5827469fac 100644 --- a/LibreNMS/Alert/Transport/Alertmanager.php +++ b/LibreNMS/Alert/Transport/Alertmanager.php @@ -46,7 +46,7 @@ class Alertmanager extends Transport $alertmanager_status = 'startsAt'; } $gen_url = (Config::get('base_url') . 'device/device=' . $obj['device_id']); - $host = ($api['url'] . '/api/v1/alerts'); + $host = ($api['url'] . '/api/v2/alerts'); $curl = curl_init(); $alertmanager_msg = strip_tags($obj['msg']); $data = [[ @@ -61,10 +61,14 @@ class Alertmanager extends Transport 'alertname' => $obj['name'], 'severity' => $obj['severity'], 'instance' => $obj['hostname'], - 'source' => $api['source'], ], ]]; + unset($api['url']); + foreach ($api as $label => $value) { + $data[0]['labels'][$label] = $value; + }; + $alert_message = json_encode($data); curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); set_curl_proxy($curl); diff --git a/doc/Alerting/Transports.md b/doc/Alerting/Transports.md index b53e143e46..8b74e19687 100644 --- a/doc/Alerting/Transports.md +++ b/doc/Alerting/Transports.md @@ -36,7 +36,7 @@ It has built-in functionality for deduplicating, grouping and routing alerts bas LibreNMS uses alert grouping by alert rule, which can produce an array of alerts of similar content for an array of hosts, whereas Alertmanager can group them by alert meta, ideally producing one single notice in case an issue occurs. -The one and only possible parameter to be passed is `source` - this is required to distinguish LibreNMS alerts from alerts coming from different sources. +It is possible to configure as much label values as required in Alertmanager Options section. Every label and it's value should be entered as a new line. [Alertmanager Docs](https://prometheus.io/docs/alerting/alertmanager/) @@ -46,6 +46,7 @@ The one and only possible parameter to be passed is `source` - this is required | ------ | ------- | | Alertmanager URL | http://alertmanager.example.com | | Alertmanager Options: | source=librenms | +| | customlabel=value | ## API API transports definitions are a bit more complex than the E-Mail configuration.