Skip to content

Commit d7a00d2

Browse files
domlebelectrocret
andauthored
Updates to Alerta transport (librenms#18202)
Add 'Origin' field to the Alerta Transport to be able to filter for LibreNMS alerts in Alerta. Also tidied up the alert data to reduce the volume of repeated info which makes the alert hard to read: - Remove duplicate 'title' values in the data to clean up - Remove duplicate 'type' values - Remove 'moreInfo' value that doesn't work Co-authored-by: Justin Lentz <[email protected]>
1 parent 5ae19d6 commit d7a00d2

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

LibreNMS/Alert/Transport/Alerta.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use LibreNMS\Enum\AlertState;
2222
use LibreNMS\Exceptions\AlertTransportDeliveryException;
2323
use LibreNMS\Util\Http;
24-
use LibreNMS\Util\Url;
2524

2625
class Alerta extends Transport
2726
{
@@ -30,25 +29,21 @@ public function deliverAlert(array $alert_data): bool
3029
$severity = ($alert_data['state'] == AlertState::RECOVERED ? $this->config['recoverstate'] : $this->config['alertstate']);
3130
$data = [
3231
'resource' => $alert_data['display'],
33-
'event' => $alert_data['name'],
32+
'event' => $alert_data['title'],
3433
'environment' => $this->config['environment'],
3534
'severity' => $severity,
36-
'service' => [$alert_data['title']],
35+
'service' => [$alert_data['type']],
3736
'group' => $alert_data['name'],
3837
'value' => $alert_data['state'],
39-
'text' => strip_tags($alert_data['msg']),
40-
'tags' => [$alert_data['title']],
38+
'text' => $alert_data['msg'],
4139
'attributes' => [
4240
'sysName' => $alert_data['sysName'],
4341
'sysDescr' => $alert_data['sysDescr'],
4442
'os' => $alert_data['os'],
45-
'type' => $alert_data['type'],
4643
'ip' => $alert_data['ip'],
4744
'uptime' => $alert_data['uptime_long'],
48-
'moreInfo' => '<a href=' . Url::deviceUrl($alert_data['device_id']) . '>' . $alert_data['display'] . '</a>',
4945
],
50-
'origin' => $alert_data['rule'],
51-
'type' => $alert_data['title'],
46+
'origin' => $this->config['origin'],
5247
];
5348

5449
$res = Http::client()
@@ -74,18 +69,24 @@ public static function configTemplate(): array
7469
'descr' => 'Alerta API URL',
7570
'type' => 'text',
7671
],
77-
[
78-
'title' => 'Environment',
79-
'name' => 'environment',
80-
'descr' => 'An allowed environment from your alertad.conf.',
81-
'type' => 'text',
82-
],
8372
[
8473
'title' => 'Api Key',
8574
'name' => 'apikey',
8675
'descr' => 'Your alerta api key with minimally write:alert permissions.',
8776
'type' => 'password',
8877
],
78+
[
79+
'title' => 'Origin',
80+
'name' => 'origin',
81+
'descr' => 'Name of this monitoring source e.g. LibreNMS.',
82+
'type' => 'text',
83+
],
84+
[
85+
'title' => 'Environment',
86+
'name' => 'environment',
87+
'descr' => 'An allowed environment from your alertad.conf.',
88+
'type' => 'text',
89+
],
8990
[
9091
'title' => 'Alert State',
9192
'name' => 'alertstate',

doc/Alerting/Transports/Alerta.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ alerts from many other monitoring tools on a single screen.
1010
| Config | Example |
1111
| ------ | ------- |
1212
| API Endpoint | http://alerta.example.com/api/alert |
13-
| Environment | Production |
1413
| Apy key | api key with write permission |
14+
| Origin | LibreNMS |
15+
| Environment | Production |
1516
| Alert state | critical |
1617
| Recover state | cleared |

0 commit comments

Comments
 (0)