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>

{{ $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%">
		<th>Host Name</th>
		<th><font color=orange>Storage Description</th>
		<th><font color=red>Percent Used</th>
         @foreach ($alert->faults as $key => $value) 
		<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>
         @endforeach  @endif 

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

 @if ($alert->faults) 
 @foreach ($alert->faults as $key => $value)
{{ $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>

Pre Update Alert Example:

Alerts now look like this:

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)

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)
($alert->severity == ‘warning’)

Change From:
($alert->transport == mail)
($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.