mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Discord Transprot user configurable embed fields (#15068)
This commit is contained in:
@@ -35,12 +35,9 @@ use LibreNMS\Util\Http;
|
||||
|
||||
class Discord extends Transport
|
||||
{
|
||||
public const ALERT_FIELDS_TO_DISCORD_FIELDS = [
|
||||
'timestamp' => 'Timestamp',
|
||||
'severity' => 'Severity',
|
||||
'hostname' => 'Hostname',
|
||||
public const DEFAULT_EMBEDS = 'hostname,name,timestamp,severity';
|
||||
private array $embedFieldTranslations = [
|
||||
'name' => 'Rule Name',
|
||||
'rule' => 'Rule',
|
||||
];
|
||||
|
||||
public function deliverAlert(array $alert_data): bool
|
||||
@@ -105,15 +102,12 @@ class Discord extends Transport
|
||||
{
|
||||
$result = [];
|
||||
|
||||
foreach (self::ALERT_FIELDS_TO_DISCORD_FIELDS as $objKey => $discordKey) {
|
||||
// Skip over keys that do not exist so Discord does not give us a 400.
|
||||
if (! $alert_data[$objKey]) {
|
||||
continue;
|
||||
}
|
||||
$fields = explode(',', $this->config['discord-embed-fields'] ?? self::DEFAULT_EMBEDS);
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$result[] = [
|
||||
'name' => $discordKey,
|
||||
'value' => $alert_data[$objKey],
|
||||
'name' => $this->embedFieldTranslations[$field] ?? ucfirst($field),
|
||||
'value' => $alert_data[$field] ?? 'Error: Invalid Field',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -136,6 +130,13 @@ class Discord extends Transport
|
||||
'descr' => 'Enter the config options (format: option=value separated by new lines)',
|
||||
'type' => 'textarea',
|
||||
],
|
||||
[
|
||||
'title' => 'Fields to embed in the alert',
|
||||
'name' => 'discord-embed-fields',
|
||||
'descr' => 'Comma seperated list of fields from the alert to attach to the Discord message',
|
||||
'type' => 'text',
|
||||
'default' => self::DEFAULT_EMBEDS,
|
||||
],
|
||||
],
|
||||
'validation' => [
|
||||
'url' => 'required|url',
|
||||
|
Reference in New Issue
Block a user