Error Converting Alert Template

I was going through converting my alert templates through the web UI. All but one converted. When I attempt to update the template after clicking the convert button, I receive the message “An error occurred updating this alert template.”

When I watch the librenms.log file as I update the template, I see the following:

[2018-10-19 16:34:07] production.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Parse error: syntax error, unexpected 'else' (T_ELSE) in /opt/librenms/storage/framework/views/a2be9d57b26e239a2622ac2b3dcc95d8:10
Stack trace:
#0 /opt/librenms/vendor/wpb/string-blade-compiler/src/Engines/CompilerEngine.php(45): Illuminate\View\Engines\PhpEngine->evaluatePath('/opt/librenms/s...', Array)
#1 /opt/librenms/vendor/wpb/string-blade-compiler/src/StringView.php(107): Wpb\String_Blade_Compiler\Engines\CompilerEngine->get(Object(stdClass), Array)
#2 /opt/librenms/vendor/laravel/framework/src/Illuminate/View/View.php(120): Wpb\String_Blade_Compiler\StringView->getContents()
#3 /opt/librenms/vendor/laravel/framework/src/Illuminate/View/View.php(85): Illuminate\View\View->renderContents()
#4 /opt/librenms/vendor/laravel/framework/src/Illuminate/View/View.php(412): Illuminate\View\View->render()
#5 /opt/librenms/html/includes/forms/alert-templates.inc.php(38): Illuminate\View\View->__toString()
#6 /opt/librenms/html/ajax_form.php(31): include_once('/opt/librenms/h...')
#7 {main}

Next ErrorException: Parse error: syntax error, unexpected 'else' (T_ELSE) (View: ) in /opt/librenms/storage/framework/views/a2be9d57b26e239a2622ac2b3dcc95d8:10
Stack trace:
#0 /opt/librenms/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(46): Illuminate\View\Engines\CompilerEngine->handleViewException(Object(Symfony\Component\Debug\Exception\FatalThrowableError), 1)
#1 /opt/librenms/vendor/wpb/string-blade-compiler/src/Engines/CompilerEngine.php(45): Illuminate\View\Engines\PhpEngine->evaluatePath('/opt/librenms/s...', Array)
#2 /opt/librenms/vendor/wpb/string-blade-compiler/src/StringView.php(107): Wpb\String_Blade_Compiler\Engines\CompilerEngine->get(Object(stdClass), Array)
#3 /opt/librenms/vendor/laravel/framework/src/Illuminate/View/View.php(120): Wpb\String_Blade_Compiler\StringView->getContents()
#4 /opt/librenms/vendor/laravel/framework/src/Illuminate/View/View.php(85): Illuminate\View\View->renderContents()
#5 /opt/librenms/vendor/laravel/framework/src/Illuminate/View/View.php(412): Illuminate\View\View->render()
#6 /opt/librenms/html/includes/forms/alert-templates.inc.php(38): Illuminate\View\View->__toString()
#7 /opt/librenms/html/ajax_form.php(31): include_once('/opt/librenms/h...')
#8 {main} 

Here’s the template code before the conversion:

{if %transport == slack}
%title
**NMS Status Page:** https://nms.bdg.link/device/device=%hostname
**Device Page:** https://%hostname/
{foreach %faults}
**Alerting Interface:** %value.ifDescr
**Current Speed:** %value.ifHighSpeed {if %value.ifHighSpeed == 1000}Gbps{else}Mbps{/if}
{/foreach}
{else}
%title
NMS Status Page: https://nms.bdg.link/device/device=%hostname
Device Page: https://%hostname/
{foreach %faults}
Alerting Interface: %value.ifDescr
Current Speed: %value.ifHighSpeed {if %value.ifHighSpeed == 1000}Gbps{else}Mbps{/if}
{/foreach}
{/if}

Here’s the same code after conversion:

 @if ($alert->transport == slack) 
{{ $alert->title }}
**NMS Status Page:** https://nms.bdg.link/device/device={{ $alert->hostname }}
**Device Page:** https://{{ $alert->hostname }}/
 @foreach ($alert->faults as $key => $value)
**Alerting Interface:** {{ $value['ifDescr'] }}
**Current Speed:** {{ $value['ifHighSpeed'] }} {if {{ $value['ifHighSpeed'] }} == 1000}Gbps @else Mbps @endif 
 @endforeach 
 @else 
{{ $alert->title }}
NMS Status Page: https://nms.bdg.link/device/device={{ $alert->hostname }}
Device Page: https://{{ $alert->hostname }}/
 @foreach ($alert->faults as $key => $value)
Alerting Interface: {{ $value['ifDescr'] }}
Current Speed: {{ $value['ifHighSpeed'] }} {if {{ $value['ifHighSpeed'] }} == 1000}Gbps @else Mbps @endif 
 @endforeach 
 @endif 

Validate output:

====================================
Component | Version
--------- | -------
LibreNMS  | 1.44-20-g7a2c9d9
DB Schema | 269
PHP       | 7.0.32-0ubuntu0.16.04.1
MySQL     | 10.0.36-MariaDB-0ubuntu0.16.04.1
RRDTool   | 1.5.5
SNMP      | NET-SNMP 5.7.3
====================================

[OK]    Composer Version: 1.7.2
[OK]    Dependencies up-to-date.
[OK]    Database connection successful
[OK]    Database schema correct
[WARN]  Your local git contains modified files, this could prevent automatic updates.
	[FIX]: 
	You can fix this with ./scripts/github-remove
	Modified Files:
	 bootstrap/cache/.gitignore
	 storage/app/.gitignore
	 storage/app/public/.gitignore
	 storage/debugbar/.gitignore
	 storage/framework/cache/.gitignore
	 storage/framework/sessions/.gitignore
	 storage/framework/testing/.gitignore
	 storage/framework/views/.gitignore
	 storage/logs/.gitignore

The git warnings showed up after applying the recommended permission changes.

Any ideas?

Looks like this line + another. Try:

 @if ($alert->transport == slack) 
{{ $alert->title }}
**NMS Status Page:** https://nms.bdg.link/device/device={{ $alert->hostname }}
**Device Page:** https://{{ $alert->hostname }}/
 @foreach ($alert->faults as $key => $value)
**Alerting Interface:** {{ $value['ifDescr'] }}
**Current Speed:** {{ $value['ifHighSpeed'] }} @if ( $value['ifHighSpeed'] == 1000 )Gbps @else Mbps @endif
 @endforeach 
 @else 
{{ $alert->title }}
NMS Status Page: https://nms.bdg.link/device/device={{ $alert->hostname }}
Device Page: https://{{ $alert->hostname }}/
 @foreach ($alert->faults as $key => $value)
Alerting Interface: {{ $value['ifDescr'] }}
Current Speed: {{ $value['ifHighSpeed'] }} @if ($value['ifHighSpeed'] == 1000 )Gbps @else Mbps @endif 
 @endforeach 
 @endif 

Ah it didn’t convert the imbeded {if to @if but it did get the endif!

Thanks, laf.

Edit: Oh, I see now that it missed the entire conversion of that section, including brackets.