Alert Template not working anymore

My template is sending emails that contains :
Alert sent to: Warning! Fallback template used due to error in template CSSVT - Équipements up/down: Undefined constant “critical”

Only word critical in the template “template CSSVT - Équipements up/down” is this part :

@if ($alert->state == 1) @if ($alert->severity == critical){{ $alert->severity }}@endif @if ($alert->severity == warning){{ $alert->severity }}@endif @endif

I’m sending the ./validate.php. I’m reading the docs, but I don’t find the explanation for this error. Can you help ?

===========================================

Component Version
LibreNMS 23.11.0-8-g90927be97 (2023-11-27T21:38:41-05:00)
DB Schema 2023_11_21_172239_increase_vminfo.vmwvmguestos_column_length (274)
PHP 8.1.2-1ubuntu2.14
Python 3.10.12
Database MariaDB 10.6.12-MariaDB-0ubuntu0.22.04.1
RRDTool 1.7.2
SNMP 5.9.1
===========================================

[OK] Composer Version: 2.6.5
[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] Distributed Polling setting is enabled globally
[OK] Connected to rrdcached
[OK] Active pollers found
[OK] Dispatcher Service is enabled
[OK] Locks are functional
[OK] Python wrapper cron entry is not present
[OK] Redis is functional
[OK] rrdtool version ok
[OK] Connected to rrdcached

You’re template has a syntax issue, paste it in here for us to see.

I’m trying to post it but the html code is messing up the post.

You need by putting your template between 2 sets of ```

```
Like this
```

Sorry, but I don’t understand. You seem to have the same problem I had when trying to add HTML code to the post.
Could you write it in a Text editor and paste a print screen like I did ?

You need to paste your template between 2 sets of ``` like I showed above, it will format correctly then

I’m still getting the error on all our templates. Here’s another similar error :

Here’s what I tried as pair of ‘’’ (by color) :

When you say “paste your template between”, I thought you meant what I did in green or orange, am I correct ?

No I mean paste your template into here as a comment.

OK here’s my template

{{ $alert->title }} <BR>
Date : {{ $alert->timestamp }} <BR><BR>
<div style="font-family:Helvetica;">

<h2>
@if ($alert->state == 1)
  @if ($alert->severity == critical)<span style="color:red;">{{ $alert->severity }}</span>@endif
  @if ($alert->severity == warning)<span style="color:orange;">{{ $alert->severity }}</span>@endif
@endif
@if ($alert->state == 2) <span style="color:goldenrod;">acknowledged</span>@endif
@if ($alert->state == 3) <span style="color:green;">recovering</span>@endif
@if ($alert->state == 0) <span style="color:green;">recovered</span>@endif
</h2>

Équipement : {{ $alert->hostname }} <BR>
Description : {{ $alert->sysDescr }} <BR>
Type alerte : {{ $alert->type }} <BR>
Pourcentage de ping perdu : {{ $alert->ping_loss }} % <BR>
@if ($alert->state == 0)
  Durée de la panne : {{ $alert->elapsed }}
@endif

<BR><BR>
<img src="https://cssvt.gouv.qc.ca/wp-content/themes/cssvt/assets/images/cssvt.svg" width="186" height="64">

</div>

Sorry for the misunderstanding !

I didn’t notice in the earlier message, the actual error was in the message. You need to wrap critical and warning in quotes:

{{ $alert->title }} <BR>
Date : {{ $alert->timestamp }} <BR><BR>
<div style="font-family:Helvetica;">

<h2>
@if ($alert->state == 1)
  @if ($alert->severity == "critical")<span style="color:red;">{{ $alert->severity }}</span>@endif
  @if ($alert->severity == "warning")<span style="color:orange;">{{ $alert->severity }}</span>@endif
@endif
@if ($alert->state == 2) <span style="color:goldenrod;">acknowledged</span>@endif
@if ($alert->state == 3) <span style="color:green;">recovering</span>@endif
@if ($alert->state == 0) <span style="color:green;">recovered</span>@endif
</h2>

Équipement : {{ $alert->hostname }} <BR>
Description : {{ $alert->sysDescr }} <BR>
Type alerte : {{ $alert->type }} <BR>
Pourcentage de ping perdu : {{ $alert->ping_loss }} % <BR>
@if ($alert->state == 0)
  Durée de la panne : {{ $alert->elapsed }}
@endif

<BR><BR>
<img src="https://cssvt.gouv.qc.ca/wp-content/themes/cssvt/assets/images/cssvt.svg" width="186" height="64">

</div>

Thanks, problem solved. I changed all our templates and checked the alerts and they’re working now.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.