librenms / librenms

Community-based GPL-licensed network monitoring system
https://www.librenms.org
Other
3.91k stars 2.3k forks source link

Discord alert transport shows "Error: Invalid Field" #15943

Closed sarabveer closed 6 months ago

sarabveer commented 6 months ago

The problem

image

This is showing up in the fields section of the Discord message. This behavior is happening by default on a new install when using the Discord alert transport with a webhook.

I have tried setting discord-embed-fields to hostname,sysName,timestamp,severity by running the following command:

lnms config:set "discord-embed-fields" "hostname,name,timestamp,severity" --ignore-checks

and setting the following line in config.php:

$config['discord-embed-fields'] = "hostname,sysName,timestamp,severity";

but both of these methods did not fix the issue.

The issue lies in Discord.php on Line 105. Offending line: https://github.com/librenms/librenms/blob/master/LibreNMS/Alert/Transport/Discord.php#L105C48-L105C67

The value of $this->config['discord-embed-fields'] is an empty string. So DEFAULT_EMBEDS never gets used.

Replacing Line 105 with: $fields = explode(',', self::DEFAULT_EMBEDS); yields correct behavior.

There should be a check added to see if the config is set to an empty string and use the default embeds. I do not know why after setting the config, the an empty string is still returned as the config value.

Output of ./validate.php

===========================================
Component | Version
--------- | -------
LibreNMS  | 24.3.0-13-ge19861c77 (2024-04-11T21:59:05-04:00)
DB Schema | 2024_02_07_151845_custom_map_additions (290)
PHP       | 8.2.7
Python    | 3.11.2
Database  | MariaDB 10.11.6-MariaDB-0+deb12u1
RRDTool   | 1.7.2
SNMP      | 5.9.3
===========================================

[OK]    Composer Version: 2.7.2
[OK]    Dependencies up-to-date.
[OK]    Database connection successful
[OK]    Database Schema is current
[OK]    SQL Server meets minimum requirements
[OK]    lower_case_table_names is enabled
[OK]    MySQL engine is optimal
[OK]    Database and column collations are correct
[OK]    Database schema correct
[OK]    MySQL and PHP time match
[OK]    Active pollers found
[OK]    Dispatcher Service not detected
[OK]    Locks are functional
[OK]    Python poller wrapper is polling
[OK]    Redis is unavailable
[OK]    rrd_dir is writable
[OK]    rrdtool version ok

What was the last working version of LibreNMS?

No response

Anything in the logs that might be useful for us?

No response

sarabveer commented 6 months ago

Also I did check if the config for discord-embed-fields was applied.

$ lnms config:get --dump | jq | grep discord
  "discord-embed-fields": "hostname,name,timestamp,severity",
sarabveer commented 6 months ago

The fix for this is to put hostname,name,timestamp,severity in the field in the alert transport settings. If it is left empty, it seems an empty string is passed which causes the error.

image

murrant commented 6 months ago

Why were you trying to set discord-embed-fields in the global config?

sarabveer commented 6 months ago

Why were you trying to set discord-embed-fields in the global config?

I was trying to debug the issue. I did not realize the $this->config variable being used in Discord.php was the alert transport config, not global config.