Added extra dynamic values alerttransport alertmanager (#13828)

* Add extra dynamic values to Alert transport for Alertmanager

* Add description to explain how extra dynamic values for Alertmanager works in the WebUI

* Add _ in dynamic label name + fix continuous-itegration error

* Fix continuous-itegration error part 2

* Updating AlertManager docs with explanation of how dynamic variables works
This commit is contained in:
geg347
2022-03-14 22:39:00 +01:00
committed by GitHub
parent c28cb759aa
commit 9036fd53b4
2 changed files with 17 additions and 3 deletions
+7 -2
View File
@@ -66,7 +66,12 @@ class Alertmanager extends Transport
$url = $api['url'];
unset($api['url']);
foreach ($api as $label => $value) {
$data[0]['labels'][$label] = $value;
// To allow dynamic values
if ((preg_match('/^extra_[A-Za-z0-9_]+$/', $label)) && (! empty($obj['faults'][1][$value]))) {
$data[0]['labels'][$label] = $obj['faults'][1][$value];
} else {
$data[0]['labels'][$label] = $value;
}
}
return $this->postAlerts($url, $data);
@@ -131,7 +136,7 @@ class Alertmanager extends Transport
[
'title' => 'Alertmanager Options',
'name' => 'alertmanager-options',
'descr' => 'Alertmanager Options',
'descr' => 'Alertmanager Options. You can add any fixed string value or dynamic value from alert details (label name must start with extra_ and value must exists in alert details).',
'type' => 'textarea',
],
],
+10 -1
View File
@@ -63,6 +63,15 @@ It is possible to configure as many label values as required in
Alertmanager Options section. Every label and its value should be
entered as a new line.
Labels can be a fixed string or a dynamic variable from the alert.
To set a dynamic variable your label must start with extra_ then
complete with the name of your label (only characters, figures and
underscore are allowed here). The value must be the name of
the variable you want to get (you can see all the variables in
Alerts->Notifications by clicking on the Details icon of your alert when it is pending).
If the variable's name does not match with an existing value the
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.
@@ -73,7 +82,7 @@ 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 Options: | source=librenms <br/> customlabel=value |
| Alertmanager Options: | source=librenms <br/> customlabel=value <br/> extra_dynamic_value=variable_name |
## API