After PHP 8.1 Upgrade my alert templates are not working

Before the PHP 8.1 update I got alerts with html formatting Now they seem to be plain text.

Alert Template Example:

<b>{{ $alert->title }}</b> <br>

Severity: <b> @if ($alert->severity == warning) <font color=orange>{{ $alert->severity }}</font> @else <font color=red>{{ $alert->severity }}</font> @endif <br></b>

 @if ($alert->state == 0) 
Time elapsed: {{ $alert->elapsed }}
 @endif Timestamp: {{ $alert->timestamp }}<br>

Unique-ID: {{ $alert->uid }}<br>

Rule:  @if ($alert->name) {{ $alert->name }} @else {{ $alert->rule }} @endif 
 @if ($alert->faults) <br>
Faults:<br>

<!--
{{ $value['string'] }}
{{ $value['storage_id'] }}
#{{ $key }}: 
{{ $value['storage_descr'] }}
{{ $alert->storage_descr }} 
{{ $value['storage_perc'] }}%
{{ $alert->storage_perc }}%
Alert sent to:  @foreach ($alert->contacts as $key => $value){{ $value }} <{{ $key }}>  @endforeach 
-->

<table border="1" width="60%">
        <col style="width:20%">
	<col style="width:30%">
	<col style="width:10%">
<thead>
	<tr>
		<th>Host Name</th>
		<th><font color=orange>Storage Description</th>
		<th><font color=red>Percent Used</th>
</tr>
	</thead>
	<tbody>
         @foreach ($alert->faults as $key => $value) 
	<tr>
		<td align="center">{{ $alert->hostname }}</td>
		<td align="center"><font color=orange>{{ $value['storage_descr'] }}</td>
		<td align="center"><font color=red>{{ $value['storage_perc'] }}%</td>
	</tr>
         @endforeach  @endif 
	</tbody>
</table>

<br>
 @if ($alert->transport == mail) <a href="https://LibreNMS/device/device={{ $alert->hostname }}/">{{ $alert->hostname }}</a> @else {{ $alert->hostname }} @endif 
<br>

 @if ($alert->faults) 
 @foreach ($alert->faults as $key => $value)
<br>
{{ $value['storage_descr'] }}<br>
<img src="https://LibreNMS/graph.php?id={{ $value['storage_id'] }}&type=storage_usage&t&height=213&width=459&lazy_w=552&from=end-24h&device&legend=yes"><br><br>
 @endforeach 
 @endif 

Pre Update Alert Example:

Alerts now look like this:
image

If I try to modify an existing template Im unable to save it, I get the error below (The file listed is the saved alert)
image

Anybody have any idea what happened? I set the system default PHP to 8.1 and set nginx and apache2. Everything else is working normally it just the alert templates being screwy.

If I remove the @if Statement below I can save the template, but not sure why this would all of a sudden be an issue.

Adding Quotes seems to resolve the issue

Change from:
($alert->severity == warning)
To:
($alert->severity == ‘warning’)

Change From:
($alert->transport == mail)
To:
($alert->transport == ‘mail’)

So, it was that the template was no longer valid in PHP8!

Seems to only be when defining the ‘Placeholder’ values with words.
This one didn’t need to be changed
($alert->state == 0)

Yes, strings require quotes around them, numbers do not.

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