Alert template syntax help

I’m attempting to create an alert template utilizing the new wireless sensors - specifically to alert on link capacity dropping below a certain rate. I have the alert rule created and functioning properly, however I’m running in to an issue with the template.

Here’s my initial rule:

%title
**NMS Status Page:** https://10.2.1.131/device/device=%hostname
{foreach %faults}
{if %value.sensor_type == airos-tx}
**Current Link TX Rate:** {calc (%value.sensor_current/1000000)} Mbps
{/if}
{if %value.sensor_type == airos-rx}
**Current Link RX Rate:** {calc (%value.sensor_current/1000000)} Mbps
{/if}
{/foreach}
**Duration:** %elapsed

When this template is used, both of the “if %value.sensor_type ==” statements seem to evaluate as true. The output I receive ends up like this showing both TX and RX, which has the same sensor value since only one of them is alerting at the time:

ALERT: lit-up-blk2 link capacity below threshold
**NMS Status Page:** https://10.2.1.131/device/device=10.2.8.10


**Current Link TX Rate:** 817277000


**Current Link RX Rate:** 817277000

I suspect it may be related to the hyphen in “airos-tx” - I tried enclosing the line in single and double quotes, but then I do not get a notification via transport at all (the alert still shows in the web UI).

I’ve attempted to use a different value as well: “{if %value.sensor_descr == Tx Capacity}” both without quotes and with single/double quotes, however I still do not receive any transport notifications at that point. Unfortunately these are the only two columns in the database that I could use to distinguish TX or RX. Any help would be appreciated in clearing up this template.

Validate output:

==========================================================
Component | Version
--------- | -------
LibreNMS  | b6e18db766bf15bf576d95d569d260c106efbdf6
DB Schema | 190
PHP       | 7.0.15-0ubuntu0.16.04.4
MySQL     | 10.0.29-MariaDB-0ubuntu0.16.04.1
RRDTool   | 1.5.5
SNMP      | NET-SNMP 5.7.3
==========================================================

[OK]    Database connection successful
[OK]    Database schema correct

This is because we addslashes() so when you put in ' or " we add \'

I’ll see if we can just do str_replace on " as that is what we care about I think.

It should be noted, I simplified this down and just used %value.sensor_descr in the foreach loop without the IF condition to achieve what I wanted:

%title
**NMS Status Page:** https://10.2.1.131/device/device=%hostname
{foreach %faults}
**Current Link %value.sensor_descr:** {calc (%value.sensor_current/1000000)} Mbps
{/foreach}
**Duration:** %elapsed

This yields the following:

ALERT: lit-up-rock link capacity below threshold
**NMS Status Page:** https://nms.bdg.link/device/device=10.2.8.34

**Current Link Tx Capacity:** 771.565 Mbps

**Duration:** 22h 38m 17s

Definitely a better way :slight_smile:

I’ve submitted a pull request to both fix your original issue (you’ll be able to wrap things in ' and to also test templates: